Some small cleanups in add_symbol_overload_list_qualified
[binutils-gdb.git] / gas / config / tc-ia64.c
blobb50823270aa635f604de00cfacfb3e85d6be1f8c
1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2 Copyright (C) 1998-2025 Free Software Foundation, Inc.
3 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
20 Boston, MA 02110-1301, USA. */
23 TODO:
25 - optional operands
26 - directives:
27 .eb
28 .estate
29 .lb
30 .popsection
31 .previous
32 .psr
33 .pushsection
34 - labels are wrong if automatic alignment is introduced
35 (e.g., checkout the second real10 definition in test-data.s)
36 - DV-related stuff:
37 <reg>.safe_across_calls and any other DV-related directives I don't
38 have documentation for.
39 verify mod-sched-brs reads/writes are checked/marked (and other
40 notes)
44 #include "as.h"
45 #include "safe-ctype.h"
46 #include "dwarf2dbg.h"
47 #include "subsegs.h"
49 #include "opcode/ia64.h"
51 #include "elf/ia64.h"
52 #include "bfdver.h"
53 #include <time.h>
54 #include <limits.h>
56 #define NELEMS(a) ((int) (sizeof (a)/sizeof ((a)[0])))
58 /* Some systems define MIN in, e.g., param.h. */
59 #undef MIN
60 #define MIN(a,b) ((a) < (b) ? (a) : (b))
62 #define NUM_SLOTS 4
63 #define PREV_SLOT md.slot[(md.curr_slot + NUM_SLOTS - 1) % NUM_SLOTS]
64 #define CURR_SLOT md.slot[md.curr_slot]
66 #define O_pseudo_fixup (O_max + 1)
68 enum special_section
70 /* IA-64 ABI section pseudo-ops. */
71 SPECIAL_SECTION_SBSS = 0,
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,
101 #ifdef TE_VMS
102 FUNC_SLOTCOUNT_RELOC,
103 #endif
106 enum reg_symbol
108 REG_GR = 0,
109 REG_FR = (REG_GR + 128),
110 REG_AR = (REG_FR + 128),
111 REG_CR = (REG_AR + 128),
112 REG_DAHR = (REG_CR + 128),
113 REG_P = (REG_DAHR + 8),
114 REG_BR = (REG_P + 64),
115 REG_IP = (REG_BR + 8),
116 REG_CFM,
117 REG_PR,
118 REG_PR_ROT,
119 REG_PSR,
120 REG_PSR_L,
121 REG_PSR_UM,
122 /* The following are pseudo-registers for use by gas only. */
123 IND_CPUID,
124 IND_DBR,
125 IND_DTR,
126 IND_ITR,
127 IND_IBR,
128 IND_MSR,
129 IND_PKR,
130 IND_PMC,
131 IND_PMD,
132 IND_DAHR,
133 IND_RR,
134 /* The following pseudo-registers are used for unwind directives only: */
135 REG_PSP,
136 REG_PRIUNAT,
137 REG_NUM
140 enum dynreg_type
142 DYNREG_GR = 0, /* dynamic general purpose register */
143 DYNREG_FR, /* dynamic floating point register */
144 DYNREG_PR, /* dynamic predicate register */
145 DYNREG_NUM_TYPES
148 enum operand_match_result
150 OPERAND_MATCH,
151 OPERAND_OUT_OF_RANGE,
152 OPERAND_MISMATCH
155 /* On the ia64, we can't know the address of a text label until the
156 instructions are packed into a bundle. To handle this, we keep
157 track of the list of labels that appear in front of each
158 instruction. */
159 struct label_fix
161 struct label_fix *next;
162 struct symbol *sym;
163 bool dw2_mark_labels;
166 #ifdef TE_VMS
167 /* An internally used relocation. */
168 #define DUMMY_RELOC_IA64_SLOTCOUNT (BFD_RELOC_UNUSED + 1)
169 #endif
171 /* This is the endianness of the current section. */
172 extern int target_big_endian;
174 /* This is the default endianness. */
175 static int default_big_endian = TARGET_BYTES_BIG_ENDIAN;
177 void (*ia64_number_to_chars) (char *, valueT, int);
179 static void ia64_float_to_chars_bigendian (char *, LITTLENUM_TYPE *, int);
180 static void ia64_float_to_chars_littleendian (char *, LITTLENUM_TYPE *, int);
182 static void (*ia64_float_to_chars) (char *, LITTLENUM_TYPE *, int);
184 static htab_t alias_hash;
185 static htab_t alias_name_hash;
186 static htab_t secalias_hash;
187 static htab_t secalias_name_hash;
189 /* List of chars besides those in app.c:symbol_chars that can start an
190 operand. Used to prevent the scrubber eating vital white-space. */
191 const char ia64_symbol_chars[] = "@?";
193 /* Characters which always start a comment. */
194 const char comment_chars[] = "";
196 /* Characters which start a comment at the beginning of a line. */
197 const char line_comment_chars[] = "#";
199 /* Characters which may be used to separate multiple commands on a
200 single line. */
201 const char line_separator_chars[] = ";{}";
203 /* Characters which are used to indicate an exponent in a floating
204 point number. */
205 const char EXP_CHARS[] = "eE";
207 /* Characters which mean that a number is a floating point constant,
208 as in 0d1.0. */
209 const char FLT_CHARS[] = "rRsSfFdDxXpP";
211 /* ia64-specific option processing: */
213 const char md_shortopts[] = "m:N:x::";
215 const struct option md_longopts[] =
217 #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1)
218 {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP},
219 #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2)
220 {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC}
223 const size_t md_longopts_size = sizeof (md_longopts);
225 static struct
227 htab_t pseudo_hash; /* pseudo opcode hash table */
228 htab_t reg_hash; /* register name hash table */
229 htab_t dynreg_hash; /* dynamic register hash table */
230 htab_t const_hash; /* constant hash table */
231 htab_t entry_hash; /* code entry hint hash table */
233 /* If X_op is != O_absent, the register name for the instruction's
234 qualifying predicate. If NULL, p0 is assumed for instructions
235 that are predictable. */
236 expressionS qp;
238 /* Optimize for which CPU. */
239 enum
241 itanium1,
242 itanium2
243 } tune;
245 /* What to do when hint.b is used. */
246 enum
248 hint_b_error,
249 hint_b_warning,
250 hint_b_ok
251 } hint_b;
253 unsigned int
254 manual_bundling : 1,
255 debug_dv: 1,
256 detect_dv: 1,
257 explicit_mode : 1, /* which mode we're in */
258 default_explicit_mode : 1, /* which mode is the default */
259 mode_explicitly_set : 1, /* was the current mode explicitly set? */
260 auto_align : 1,
261 keep_pending_output : 1;
263 /* What to do when something is wrong with unwind directives. */
264 enum
266 unwind_check_warning,
267 unwind_check_error
268 } unwind_check;
270 /* Each bundle consists of up to three instructions. We keep
271 track of four most recent instructions so we can correctly set
272 the end_of_insn_group for the last instruction in a bundle. */
273 int curr_slot;
274 int num_slots_in_use;
275 struct slot
277 unsigned int
278 end_of_insn_group : 1,
279 manual_bundling_on : 1,
280 manual_bundling_off : 1,
281 loc_directive_seen : 1;
282 signed char user_template; /* user-selected template, if any */
283 unsigned char qp_regno; /* qualifying predicate */
284 /* This duplicates a good fraction of "struct fix" but we
285 can't use a "struct fix" instead since we can't call
286 fix_new_exp() until we know the address of the instruction. */
287 int num_fixups;
288 struct insn_fix
290 bfd_reloc_code_real_type code;
291 enum ia64_opnd opnd; /* type of operand in need of fix */
292 unsigned int is_pcrel : 1; /* is operand pc-relative? */
293 expressionS expr; /* the value to be inserted */
295 fixup[2]; /* at most two fixups per insn */
296 struct ia64_opcode *idesc;
297 struct label_fix *label_fixups;
298 struct label_fix *tag_fixups;
299 struct unw_rec_list *unwind_record; /* Unwind directive. */
300 expressionS opnd[6];
301 const char *src_file;
302 unsigned int src_line;
303 struct dwarf2_line_info debug_line;
305 slot[NUM_SLOTS];
307 segT last_text_seg;
308 subsegT last_text_subseg;
310 struct dynreg
312 struct dynreg *next; /* next dynamic register */
313 const char *name;
314 unsigned short base; /* the base register number */
315 unsigned short num_regs; /* # of registers in this set */
317 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
319 flagword flags; /* ELF-header flags */
321 struct mem_offset {
322 unsigned hint:1; /* is this hint currently valid? */
323 bfd_vma offset; /* mem.offset offset */
324 bfd_vma base; /* mem.offset base */
325 } mem_offset;
327 int path; /* number of alt. entry points seen */
328 const char **entry_labels; /* labels of all alternate paths in
329 the current DV-checking block. */
330 int maxpaths; /* size currently allocated for
331 entry_labels */
333 int pointer_size; /* size in bytes of a pointer */
334 int pointer_size_shift; /* shift size of a pointer for alignment */
336 symbolS *indregsym[IND_RR - IND_CPUID + 1];
340 /* These are not const, because they are modified to MMI for non-itanium1
341 targets below. */
342 /* MFI bundle of nops. */
343 static unsigned char le_nop[16] =
345 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
346 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00
348 /* MFI bundle of nops with stop-bit. */
349 static unsigned char le_nop_stop[16] =
351 0x0d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
352 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00
355 /* application registers: */
357 #define AR_K0 0
358 #define AR_K7 7
359 #define AR_RSC 16
360 #define AR_BSP 17
361 #define AR_BSPSTORE 18
362 #define AR_RNAT 19
363 #define AR_FCR 21
364 #define AR_EFLAG 24
365 #define AR_CSD 25
366 #define AR_SSD 26
367 #define AR_CFLG 27
368 #define AR_FSR 28
369 #define AR_FIR 29
370 #define AR_FDR 30
371 #define AR_CCV 32
372 #define AR_UNAT 36
373 #define AR_FPSR 40
374 #define AR_ITC 44
375 #define AR_RUC 45
376 #define AR_PFS 64
377 #define AR_LC 65
378 #define AR_EC 66
380 static const struct
382 const char *name;
383 unsigned int regnum;
385 ar[] =
387 {"ar.k0", AR_K0}, {"ar.k1", AR_K0 + 1},
388 {"ar.k2", AR_K0 + 2}, {"ar.k3", AR_K0 + 3},
389 {"ar.k4", AR_K0 + 4}, {"ar.k5", AR_K0 + 5},
390 {"ar.k6", AR_K0 + 6}, {"ar.k7", AR_K7},
391 {"ar.rsc", AR_RSC}, {"ar.bsp", AR_BSP},
392 {"ar.bspstore", AR_BSPSTORE}, {"ar.rnat", AR_RNAT},
393 {"ar.fcr", AR_FCR}, {"ar.eflag", AR_EFLAG},
394 {"ar.csd", AR_CSD}, {"ar.ssd", AR_SSD},
395 {"ar.cflg", AR_CFLG}, {"ar.fsr", AR_FSR},
396 {"ar.fir", AR_FIR}, {"ar.fdr", AR_FDR},
397 {"ar.ccv", AR_CCV}, {"ar.unat", AR_UNAT},
398 {"ar.fpsr", AR_FPSR}, {"ar.itc", AR_ITC},
399 {"ar.ruc", AR_RUC}, {"ar.pfs", AR_PFS},
400 {"ar.lc", AR_LC}, {"ar.ec", AR_EC},
403 /* control registers: */
405 #define CR_DCR 0
406 #define CR_ITM 1
407 #define CR_IVA 2
408 #define CR_PTA 8
409 #define CR_GPTA 9
410 #define CR_IPSR 16
411 #define CR_ISR 17
412 #define CR_IIP 19
413 #define CR_IFA 20
414 #define CR_ITIR 21
415 #define CR_IIPA 22
416 #define CR_IFS 23
417 #define CR_IIM 24
418 #define CR_IHA 25
419 #define CR_IIB0 26
420 #define CR_IIB1 27
421 #define CR_LID 64
422 #define CR_IVR 65
423 #define CR_TPR 66
424 #define CR_EOI 67
425 #define CR_IRR0 68
426 #define CR_IRR3 71
427 #define CR_ITV 72
428 #define CR_PMV 73
429 #define CR_CMCV 74
430 #define CR_LRR0 80
431 #define CR_LRR1 81
433 static const struct
435 const char *name;
436 unsigned int regnum;
438 cr[] =
440 {"cr.dcr", CR_DCR},
441 {"cr.itm", CR_ITM},
442 {"cr.iva", CR_IVA},
443 {"cr.pta", CR_PTA},
444 {"cr.gpta", CR_GPTA},
445 {"cr.ipsr", CR_IPSR},
446 {"cr.isr", CR_ISR},
447 {"cr.iip", CR_IIP},
448 {"cr.ifa", CR_IFA},
449 {"cr.itir", CR_ITIR},
450 {"cr.iipa", CR_IIPA},
451 {"cr.ifs", CR_IFS},
452 {"cr.iim", CR_IIM},
453 {"cr.iha", CR_IHA},
454 {"cr.iib0", CR_IIB0},
455 {"cr.iib1", CR_IIB1},
456 {"cr.lid", CR_LID},
457 {"cr.ivr", CR_IVR},
458 {"cr.tpr", CR_TPR},
459 {"cr.eoi", CR_EOI},
460 {"cr.irr0", CR_IRR0},
461 {"cr.irr1", CR_IRR0 + 1},
462 {"cr.irr2", CR_IRR0 + 2},
463 {"cr.irr3", CR_IRR3},
464 {"cr.itv", CR_ITV},
465 {"cr.pmv", CR_PMV},
466 {"cr.cmcv", CR_CMCV},
467 {"cr.lrr0", CR_LRR0},
468 {"cr.lrr1", CR_LRR1}
471 #define PSR_MFL 4
472 #define PSR_IC 13
473 #define PSR_DFL 18
474 #define PSR_CPL 32
476 static const struct const_desc
478 const char *name;
479 valueT value;
481 const_bits[] =
483 /* PSR constant masks: */
485 /* 0: reserved */
486 {"psr.be", ((valueT) 1) << 1},
487 {"psr.up", ((valueT) 1) << 2},
488 {"psr.ac", ((valueT) 1) << 3},
489 {"psr.mfl", ((valueT) 1) << 4},
490 {"psr.mfh", ((valueT) 1) << 5},
491 /* 6-12: reserved */
492 {"psr.ic", ((valueT) 1) << 13},
493 {"psr.i", ((valueT) 1) << 14},
494 {"psr.pk", ((valueT) 1) << 15},
495 /* 16: reserved */
496 {"psr.dt", ((valueT) 1) << 17},
497 {"psr.dfl", ((valueT) 1) << 18},
498 {"psr.dfh", ((valueT) 1) << 19},
499 {"psr.sp", ((valueT) 1) << 20},
500 {"psr.pp", ((valueT) 1) << 21},
501 {"psr.di", ((valueT) 1) << 22},
502 {"psr.si", ((valueT) 1) << 23},
503 {"psr.db", ((valueT) 1) << 24},
504 {"psr.lp", ((valueT) 1) << 25},
505 {"psr.tb", ((valueT) 1) << 26},
506 {"psr.rt", ((valueT) 1) << 27},
507 /* 28-31: reserved */
508 /* 32-33: cpl (current privilege level) */
509 {"psr.is", ((valueT) 1) << 34},
510 {"psr.mc", ((valueT) 1) << 35},
511 {"psr.it", ((valueT) 1) << 36},
512 {"psr.id", ((valueT) 1) << 37},
513 {"psr.da", ((valueT) 1) << 38},
514 {"psr.dd", ((valueT) 1) << 39},
515 {"psr.ss", ((valueT) 1) << 40},
516 /* 41-42: ri (restart instruction) */
517 {"psr.ed", ((valueT) 1) << 43},
518 {"psr.bn", ((valueT) 1) << 44},
521 /* indirect register-sets/memory: */
523 static const struct
525 const char *name;
526 unsigned int regnum;
528 indirect_reg[] =
530 { "CPUID", IND_CPUID },
531 { "cpuid", IND_CPUID },
532 { "dbr", IND_DBR },
533 { "dtr", IND_DTR },
534 { "itr", IND_ITR },
535 { "ibr", IND_IBR },
536 { "msr", IND_MSR },
537 { "pkr", IND_PKR },
538 { "pmc", IND_PMC },
539 { "pmd", IND_PMD },
540 { "dahr", IND_DAHR },
541 { "rr", IND_RR },
544 /* Pseudo functions used to indicate relocation types (these functions
545 start with an at sign (@). */
546 static struct
548 const char *name;
549 enum pseudo_type
551 PSEUDO_FUNC_NONE,
552 PSEUDO_FUNC_RELOC,
553 PSEUDO_FUNC_CONST,
554 PSEUDO_FUNC_REG,
555 PSEUDO_FUNC_FLOAT
557 type;
558 union
560 unsigned long ival;
561 symbolS *sym;
565 pseudo_func[] =
567 /* reloc pseudo functions (these must come first!): */
568 { "dtpmod", PSEUDO_FUNC_RELOC, { 0 } },
569 { "dtprel", PSEUDO_FUNC_RELOC, { 0 } },
570 { "fptr", PSEUDO_FUNC_RELOC, { 0 } },
571 { "gprel", PSEUDO_FUNC_RELOC, { 0 } },
572 { "ltoff", PSEUDO_FUNC_RELOC, { 0 } },
573 { "ltoffx", PSEUDO_FUNC_RELOC, { 0 } },
574 { "pcrel", PSEUDO_FUNC_RELOC, { 0 } },
575 { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
576 { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
577 { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
578 { "tprel", PSEUDO_FUNC_RELOC, { 0 } },
579 { "ltv", PSEUDO_FUNC_RELOC, { 0 } },
580 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
581 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_DTP_MODULE */
582 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_DTP_RELATIVE */
583 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_TP_RELATIVE */
584 { "iplt", PSEUDO_FUNC_RELOC, { 0 } },
585 #ifdef TE_VMS
586 { "slotcount", PSEUDO_FUNC_RELOC, { 0 } },
587 #endif
589 /* mbtype4 constants: */
590 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
591 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
592 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
593 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
594 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
596 /* fclass constants: */
597 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
598 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
599 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
600 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
601 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
602 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
603 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
604 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
605 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
607 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
609 /* hint constants: */
610 { "pause", PSEUDO_FUNC_CONST, { 0x0 } },
611 { "priority", PSEUDO_FUNC_CONST, { 0x1 } },
613 /* tf constants: */
614 { "clz", PSEUDO_FUNC_CONST, { 32 } },
615 { "mpy", PSEUDO_FUNC_CONST, { 33 } },
616 { "datahints", PSEUDO_FUNC_CONST, { 34 } },
618 /* unwind-related constants: */
619 { "svr4", PSEUDO_FUNC_CONST, { ELFOSABI_NONE } },
620 { "hpux", PSEUDO_FUNC_CONST, { ELFOSABI_HPUX } },
621 { "nt", PSEUDO_FUNC_CONST, { 2 } }, /* conflicts w/ELFOSABI_NETBSD */
622 { "linux", PSEUDO_FUNC_CONST, { ELFOSABI_GNU } },
623 { "freebsd", PSEUDO_FUNC_CONST, { ELFOSABI_FREEBSD } },
624 { "openvms", PSEUDO_FUNC_CONST, { ELFOSABI_OPENVMS } },
625 { "nsk", PSEUDO_FUNC_CONST, { ELFOSABI_NSK } },
627 /* unwind-related registers: */
628 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
631 /* 41-bit nop opcodes (one per unit): */
632 static const bfd_vma nop[IA64_NUM_UNITS] =
634 0x0000000000LL, /* NIL => break 0 */
635 0x0008000000LL, /* I-unit nop */
636 0x0008000000LL, /* M-unit nop */
637 0x4000000000LL, /* B-unit nop */
638 0x0008000000LL, /* F-unit nop */
639 0x0000000000LL, /* L-"unit" nop immediate */
640 0x0008000000LL, /* X-unit nop */
643 /* Can't be `const' as it's passed to input routines (which have the
644 habit of setting temporary sentinels. */
645 static char special_section_name[][20] =
647 {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
648 {".IA_64.unwind"}, {".IA_64.unwind_info"},
649 {".init_array"}, {".fini_array"}
652 /* The best template for a particular sequence of up to three
653 instructions: */
654 #define N IA64_NUM_TYPES
655 static unsigned char best_template[N][N][N];
656 #undef N
658 /* Resource dependencies currently in effect */
659 static struct rsrc {
660 int depind; /* dependency index */
661 const struct ia64_dependency *dependency; /* actual dependency */
662 unsigned specific:1, /* is this a specific bit/regno? */
663 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
664 int index; /* specific regno/bit within dependency */
665 int note; /* optional qualifying note (0 if none) */
666 #define STATE_NONE 0
667 #define STATE_STOP 1
668 #define STATE_SRLZ 2
669 int insn_srlz; /* current insn serialization state */
670 int data_srlz; /* current data serialization state */
671 int qp_regno; /* qualifying predicate for this usage */
672 const char *file; /* what file marked this dependency */
673 unsigned int line; /* what line marked this dependency */
674 struct mem_offset mem_offset; /* optional memory offset hint */
675 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
676 int path; /* corresponding code entry index */
677 } *regdeps = NULL;
678 static int regdepslen = 0;
679 static int regdepstotlen = 0;
680 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
681 static const char *dv_sem[] = { "none", "implied", "impliedf",
682 "data", "instr", "specific", "stop", "other" };
683 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
685 /* Current state of PR mutexation */
686 static struct qpmutex {
687 valueT prmask;
688 int path;
689 } *qp_mutexes = NULL; /* QP mutex bitmasks */
690 static int qp_mutexeslen = 0;
691 static int qp_mutexestotlen = 0;
692 static valueT qp_safe_across_calls = 0;
694 /* Current state of PR implications */
695 static struct qp_imply {
696 unsigned p1:6;
697 unsigned p2:6;
698 unsigned p2_branched:1;
699 int path;
700 } *qp_implies = NULL;
701 static int qp_implieslen = 0;
702 static int qp_impliestotlen = 0;
704 /* Keep track of static GR values so that indirect register usage can
705 sometimes be tracked. */
706 static struct gr {
707 unsigned known:1;
708 int path;
709 valueT value;
710 } gr_values[128] = {
713 #ifdef INT_MAX
714 INT_MAX,
715 #else
716 (((1 << (8 * sizeof(gr_values->path) - 2)) - 1) << 1) + 1,
717 #endif
722 /* Remember the alignment frag. */
723 static fragS *align_frag;
725 /* These are the routines required to output the various types of
726 unwind records. */
728 /* A slot_number is a frag address plus the slot index (0-2). We use the
729 frag address here so that if there is a section switch in the middle of
730 a function, then instructions emitted to a different section are not
731 counted. Since there may be more than one frag for a function, this
732 means we also need to keep track of which frag this address belongs to
733 so we can compute inter-frag distances. This also nicely solves the
734 problem with nops emitted for align directives, which can't easily be
735 counted, but can easily be derived from frag sizes. */
737 typedef struct unw_rec_list {
738 unwind_record r;
739 unsigned long slot_number;
740 fragS *slot_frag;
741 struct unw_rec_list *next;
742 } unw_rec_list;
744 #define SLOT_NUM_NOT_SET (unsigned)-1
746 /* Linked list of saved prologue counts. A very poor
747 implementation of a map from label numbers to prologue counts. */
748 typedef struct label_prologue_count
750 struct label_prologue_count *next;
751 unsigned long label_number;
752 unsigned int prologue_count;
753 } label_prologue_count;
755 typedef struct proc_pending
757 symbolS *sym;
758 struct proc_pending *next;
759 } proc_pending;
761 static struct
763 /* Maintain a list of unwind entries for the current function. */
764 unw_rec_list *list;
765 unw_rec_list *tail;
767 /* Any unwind entries that should be attached to the current slot
768 that an insn is being constructed for. */
769 unw_rec_list *current_entry;
771 /* These are used to create the unwind table entry for this function. */
772 proc_pending proc_pending;
773 symbolS *info; /* pointer to unwind info */
774 symbolS *personality_routine;
775 segT saved_text_seg;
776 subsegT saved_text_subseg;
777 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
779 /* TRUE if processing unwind directives in a prologue region. */
780 unsigned int prologue : 1;
781 unsigned int prologue_mask : 4;
782 unsigned int prologue_gr : 7;
783 unsigned int body : 1;
784 unsigned int insn : 1;
785 unsigned int prologue_count; /* number of .prologues seen so far */
786 /* Prologue counts at previous .label_state directives. */
787 struct label_prologue_count * saved_prologue_counts;
789 /* List of split up .save-s. */
790 unw_p_record *pending_saves;
791 } unwind;
793 /* The input value is a negated offset from psp, and specifies an address
794 psp - offset. The encoded value is psp + 16 - (4 * offset). Thus we
795 must add 16 and divide by 4 to get the encoded value. */
797 #define ENCODED_PSP_OFFSET(OFFSET) (((OFFSET) + 16) / 4)
799 typedef void (*vbyte_func) (int, char *, char *);
801 /* Forward declarations: */
802 static void dot_alias (int);
803 static int parse_operand_and_eval (expressionS *, int);
804 static void emit_one_bundle (void);
805 static bfd_reloc_code_real_type ia64_gen_real_reloc_type (struct symbol *,
806 bfd_reloc_code_real_type);
807 static void insn_group_break (int, int, int);
808 static void add_qp_mutex (valueT);
809 static void add_qp_imply (int, int);
810 static void clear_qp_mutex (valueT);
811 static void clear_qp_implies (valueT, valueT);
812 static void print_dependency (const char *, int);
813 static void instruction_serialization (void);
814 static void data_serialization (void);
815 static void output_R3_format (vbyte_func, unw_record_type, unsigned long);
816 static void output_B3_format (vbyte_func, unsigned long, unsigned long);
817 static void output_B4_format (vbyte_func, unw_record_type, unsigned long);
818 static void free_saved_prologue_counts (void);
820 /* Determine if application register REGNUM resides only in the integer
821 unit (as opposed to the memory unit). */
822 static int
823 ar_is_only_in_integer_unit (int reg)
825 reg -= REG_AR;
826 return reg >= 64 && reg <= 111;
829 /* Determine if application register REGNUM resides only in the memory
830 unit (as opposed to the integer unit). */
831 static int
832 ar_is_only_in_memory_unit (int reg)
834 reg -= REG_AR;
835 return reg >= 0 && reg <= 47;
838 /* Switch to section NAME and create section if necessary. It's
839 rather ugly that we have to manipulate input_line_pointer but I
840 don't see any other way to accomplish the same thing without
841 changing obj-elf.c (which may be the Right Thing, in the end). */
842 static void
843 set_section (char *name)
845 char *saved_input_line_pointer;
847 saved_input_line_pointer = input_line_pointer;
848 input_line_pointer = name;
849 obj_elf_section (0);
850 input_line_pointer = saved_input_line_pointer;
853 /* Map 's' to SHF_IA_64_SHORT. */
855 bfd_vma
856 ia64_elf_section_letter (int letter, const char **ptr_msg)
858 if (letter == 's')
859 return SHF_IA_64_SHORT;
860 else if (letter == 'o')
861 return SHF_LINK_ORDER;
862 #ifdef TE_VMS
863 else if (letter == 'O')
864 return SHF_IA_64_VMS_OVERLAID;
865 else if (letter == 'g')
866 return SHF_IA_64_VMS_GLOBAL;
867 #endif
869 *ptr_msg = _("bad .section directive: want a,o,s,w,x,M,S,G,T in string");
870 return -1;
873 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
875 flagword
876 ia64_elf_section_flags (flagword flags,
877 bfd_vma attr,
878 int type ATTRIBUTE_UNUSED)
880 if (attr & SHF_IA_64_SHORT)
881 flags |= SEC_SMALL_DATA;
882 return flags;
886 ia64_elf_section_type (const char *str, size_t len)
888 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
890 if (STREQ (ELF_STRING_ia64_unwind_info))
891 return SHT_PROGBITS;
893 if (STREQ (ELF_STRING_ia64_unwind_info_once))
894 return SHT_PROGBITS;
896 if (STREQ (ELF_STRING_ia64_unwind))
897 return SHT_IA_64_UNWIND;
899 if (STREQ (ELF_STRING_ia64_unwind_once))
900 return SHT_IA_64_UNWIND;
902 if (STREQ ("unwind"))
903 return SHT_IA_64_UNWIND;
905 return -1;
906 #undef STREQ
909 static unsigned int
910 set_regstack (unsigned int ins,
911 unsigned int locs,
912 unsigned int outs,
913 unsigned int rots)
915 /* Size of frame. */
916 unsigned int sof;
918 sof = ins + locs + outs;
919 if (sof > 96)
921 as_bad (_("Size of frame exceeds maximum of 96 registers"));
922 return 0;
924 if (rots > sof)
926 as_warn (_("Size of rotating registers exceeds frame size"));
927 return 0;
929 md.in.base = REG_GR + 32;
930 md.loc.base = md.in.base + ins;
931 md.out.base = md.loc.base + locs;
933 md.in.num_regs = ins;
934 md.loc.num_regs = locs;
935 md.out.num_regs = outs;
936 md.rot.num_regs = rots;
937 return sof;
940 void
941 ia64_flush_insns (void)
943 struct label_fix *lfix;
944 segT saved_seg;
945 subsegT saved_subseg;
946 unw_rec_list *ptr;
947 bool mark;
949 if (!md.last_text_seg)
950 return;
952 saved_seg = now_seg;
953 saved_subseg = now_subseg;
955 subseg_set (md.last_text_seg, md.last_text_subseg);
957 while (md.num_slots_in_use > 0)
958 emit_one_bundle (); /* force out queued instructions */
960 /* In case there are labels following the last instruction, resolve
961 those now. */
962 mark = false;
963 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
965 symbol_set_value_now (lfix->sym);
966 mark |= lfix->dw2_mark_labels;
968 if (mark)
970 dwarf2_where (&CURR_SLOT.debug_line);
971 CURR_SLOT.debug_line.flags |= DWARF2_FLAG_BASIC_BLOCK;
972 dwarf2_gen_line_info (frag_now_fix (), &CURR_SLOT.debug_line);
973 dwarf2_consume_line_info ();
975 CURR_SLOT.label_fixups = 0;
977 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
978 symbol_set_value_now (lfix->sym);
979 CURR_SLOT.tag_fixups = 0;
981 /* In case there are unwind directives following the last instruction,
982 resolve those now. We only handle prologue, body, and endp directives
983 here. Give an error for others. */
984 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
986 switch (ptr->r.type)
988 case prologue:
989 case prologue_gr:
990 case body:
991 case endp:
992 ptr->slot_number = (unsigned long) frag_more (0);
993 ptr->slot_frag = frag_now;
994 break;
996 /* Allow any record which doesn't have a "t" field (i.e.,
997 doesn't relate to a particular instruction). */
998 case unwabi:
999 case br_gr:
1000 case copy_state:
1001 case fr_mem:
1002 case frgr_mem:
1003 case gr_gr:
1004 case gr_mem:
1005 case label_state:
1006 case rp_br:
1007 case spill_base:
1008 case spill_mask:
1009 /* nothing */
1010 break;
1012 default:
1013 as_bad (_("Unwind directive not followed by an instruction."));
1014 break;
1017 unwind.current_entry = NULL;
1019 subseg_set (saved_seg, saved_subseg);
1021 if (md.qp.X_op == O_register)
1022 as_bad (_("qualifying predicate not followed by instruction"));
1025 void
1026 ia64_cons_align (int nbytes)
1028 if (md.auto_align)
1030 int log;
1031 for (log = 0; (nbytes & 1) != 1; nbytes >>= 1)
1032 log++;
1034 do_align (log, NULL, 0, 0);
1038 #ifdef TE_VMS
1040 /* .vms_common section, symbol, size, alignment */
1042 static void
1043 obj_elf_vms_common (int ignore ATTRIBUTE_UNUSED)
1045 const char *sec_name;
1046 char *sym_name;
1047 char c;
1048 offsetT size;
1049 offsetT cur_size;
1050 offsetT temp;
1051 symbolS *symbolP;
1052 segT current_seg = now_seg;
1053 subsegT current_subseg = now_subseg;
1054 offsetT log_align;
1056 /* Section name. */
1057 sec_name = obj_elf_section_name ();
1058 if (sec_name == NULL)
1059 return;
1061 /* Symbol name. */
1062 SKIP_WHITESPACE ();
1063 if (*input_line_pointer == ',')
1065 input_line_pointer++;
1066 SKIP_WHITESPACE ();
1068 else
1070 as_bad (_("expected ',' after section name"));
1071 ignore_rest_of_line ();
1072 return;
1075 c = get_symbol_name (&sym_name);
1077 if (input_line_pointer == sym_name)
1079 (void) restore_line_pointer (c);
1080 as_bad (_("expected symbol name"));
1081 ignore_rest_of_line ();
1082 return;
1085 symbolP = symbol_find_or_make (sym_name);
1086 (void) restore_line_pointer (c);
1088 if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP))
1089 && !S_IS_COMMON (symbolP))
1091 as_bad (_("Ignoring attempt to re-define symbol"));
1092 ignore_rest_of_line ();
1093 return;
1096 /* Symbol size. */
1097 SKIP_WHITESPACE ();
1098 if (*input_line_pointer == ',')
1100 input_line_pointer++;
1101 SKIP_WHITESPACE ();
1103 else
1105 as_bad (_("expected ',' after symbol name"));
1106 ignore_rest_of_line ();
1107 return;
1110 temp = get_absolute_expression ();
1111 size = temp;
1112 size &= ((offsetT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1;
1113 if (temp != size)
1115 as_warn (_("size (%ld) out of range, ignored"), (long) temp);
1116 ignore_rest_of_line ();
1117 return;
1120 /* Alignment. */
1121 SKIP_WHITESPACE ();
1122 if (*input_line_pointer == ',')
1124 input_line_pointer++;
1125 SKIP_WHITESPACE ();
1127 else
1129 as_bad (_("expected ',' after symbol size"));
1130 ignore_rest_of_line ();
1131 return;
1134 log_align = get_absolute_expression ();
1136 demand_empty_rest_of_line ();
1138 obj_elf_change_section
1139 (sec_name, SHT_NOBITS,
1140 SHF_ALLOC | SHF_WRITE | SHF_IA_64_VMS_OVERLAID | SHF_IA_64_VMS_GLOBAL,
1141 0, NULL, true);
1143 S_SET_VALUE (symbolP, 0);
1144 S_SET_SIZE (symbolP, size);
1145 S_SET_EXTERNAL (symbolP);
1146 S_SET_SEGMENT (symbolP, now_seg);
1148 symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;
1150 record_alignment (now_seg, log_align);
1152 cur_size = bfd_section_size (now_seg);
1153 if ((int) size > cur_size)
1155 char *pfrag
1156 = frag_var (rs_fill, 1, 1, (relax_substateT)0, NULL,
1157 (valueT)size - (valueT)cur_size, NULL);
1158 *pfrag = 0;
1159 bfd_set_section_size (now_seg, size);
1162 /* Switch back to current segment. */
1163 subseg_set (current_seg, current_subseg);
1165 #ifdef md_elf_section_change_hook
1166 md_elf_section_change_hook ();
1167 #endif
1170 #endif /* TE_VMS */
1172 /* Output COUNT bytes to a memory location. */
1173 static char *vbyte_mem_ptr = NULL;
1175 static void
1176 output_vbyte_mem (int count, char *ptr, char *comment ATTRIBUTE_UNUSED)
1178 int x;
1179 if (vbyte_mem_ptr == NULL)
1180 abort ();
1182 if (count == 0)
1183 return;
1184 for (x = 0; x < count; x++)
1185 *(vbyte_mem_ptr++) = ptr[x];
1188 /* Count the number of bytes required for records. */
1189 static int vbyte_count = 0;
1190 static void
1191 count_output (int count,
1192 char *ptr ATTRIBUTE_UNUSED,
1193 char *comment ATTRIBUTE_UNUSED)
1195 vbyte_count += count;
1198 static void
1199 output_R1_format (vbyte_func f, unw_record_type rtype, int rlen)
1201 int r = 0;
1202 char byte;
1203 if (rlen > 0x1f)
1205 output_R3_format (f, rtype, rlen);
1206 return;
1209 if (rtype == body)
1210 r = 1;
1211 else if (rtype != prologue)
1212 as_bad (_("record type is not valid"));
1214 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1215 (*f) (1, &byte, NULL);
1218 static void
1219 output_R2_format (vbyte_func f, int mask, int grsave, unsigned long rlen)
1221 char bytes[20];
1222 int count = 2;
1223 mask = (mask & 0x0f);
1224 grsave = (grsave & 0x7f);
1226 bytes[0] = (UNW_R2 | (mask >> 1));
1227 bytes[1] = (((mask & 0x01) << 7) | grsave);
1228 count += output_leb128 (bytes + 2, rlen, 0);
1229 (*f) (count, bytes, NULL);
1232 static void
1233 output_R3_format (vbyte_func f, unw_record_type rtype, unsigned long rlen)
1235 int r = 0, count;
1236 char bytes[20];
1237 if (rlen <= 0x1f)
1239 output_R1_format (f, rtype, rlen);
1240 return;
1243 if (rtype == body)
1244 r = 1;
1245 else if (rtype != prologue)
1246 as_bad (_("record type is not valid"));
1247 bytes[0] = (UNW_R3 | r);
1248 count = output_leb128 (bytes + 1, rlen, 0);
1249 (*f) (count + 1, bytes, NULL);
1252 static void
1253 output_P1_format (vbyte_func f, int brmask)
1255 char byte;
1256 byte = UNW_P1 | (brmask & 0x1f);
1257 (*f) (1, &byte, NULL);
1260 static void
1261 output_P2_format (vbyte_func f, int brmask, 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 (vbyte_func f, unw_record_type rtype, int reg)
1273 char bytes[2];
1274 int r = 0;
1275 reg = (reg & 0x7f);
1276 switch (rtype)
1278 case psp_gr:
1279 r = 0;
1280 break;
1281 case rp_gr:
1282 r = 1;
1283 break;
1284 case pfs_gr:
1285 r = 2;
1286 break;
1287 case preds_gr:
1288 r = 3;
1289 break;
1290 case unat_gr:
1291 r = 4;
1292 break;
1293 case lc_gr:
1294 r = 5;
1295 break;
1296 case rp_br:
1297 r = 6;
1298 break;
1299 case rnat_gr:
1300 r = 7;
1301 break;
1302 case bsp_gr:
1303 r = 8;
1304 break;
1305 case bspstore_gr:
1306 r = 9;
1307 break;
1308 case fpsr_gr:
1309 r = 10;
1310 break;
1311 case priunat_gr:
1312 r = 11;
1313 break;
1314 default:
1315 as_bad (_("Invalid record type for P3 format."));
1317 bytes[0] = (UNW_P3 | (r >> 1));
1318 bytes[1] = (((r & 1) << 7) | reg);
1319 (*f) (2, bytes, NULL);
1322 static void
1323 output_P4_format (vbyte_func f, unsigned char *imask, unsigned long imask_size)
1325 imask[0] = UNW_P4;
1326 (*f) (imask_size, (char *) imask, NULL);
1329 static void
1330 output_P5_format (vbyte_func f, int grmask, unsigned long frmask)
1332 char bytes[4];
1333 grmask = (grmask & 0x0f);
1335 bytes[0] = UNW_P5;
1336 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1337 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1338 bytes[3] = (frmask & 0x000000ff);
1339 (*f) (4, bytes, NULL);
1342 static void
1343 output_P6_format (vbyte_func f, unw_record_type rtype, int rmask)
1345 char byte;
1346 int r = 0;
1348 if (rtype == gr_mem)
1349 r = 1;
1350 else if (rtype != fr_mem)
1351 as_bad (_("Invalid record type for format P6"));
1352 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1353 (*f) (1, &byte, NULL);
1356 static void
1357 output_P7_format (vbyte_func f,
1358 unw_record_type rtype,
1359 unsigned long w1,
1360 unsigned long w2)
1362 char bytes[20];
1363 int count = 1;
1364 int r = 0;
1365 count += output_leb128 (bytes + 1, w1, 0);
1366 switch (rtype)
1368 case mem_stack_f:
1369 r = 0;
1370 count += output_leb128 (bytes + count, w2 >> 4, 0);
1371 break;
1372 case mem_stack_v:
1373 r = 1;
1374 break;
1375 case spill_base:
1376 r = 2;
1377 break;
1378 case psp_sprel:
1379 r = 3;
1380 break;
1381 case rp_when:
1382 r = 4;
1383 break;
1384 case rp_psprel:
1385 r = 5;
1386 break;
1387 case pfs_when:
1388 r = 6;
1389 break;
1390 case pfs_psprel:
1391 r = 7;
1392 break;
1393 case preds_when:
1394 r = 8;
1395 break;
1396 case preds_psprel:
1397 r = 9;
1398 break;
1399 case lc_when:
1400 r = 10;
1401 break;
1402 case lc_psprel:
1403 r = 11;
1404 break;
1405 case unat_when:
1406 r = 12;
1407 break;
1408 case unat_psprel:
1409 r = 13;
1410 break;
1411 case fpsr_when:
1412 r = 14;
1413 break;
1414 case fpsr_psprel:
1415 r = 15;
1416 break;
1417 default:
1418 break;
1420 bytes[0] = (UNW_P7 | r);
1421 (*f) (count, bytes, NULL);
1424 static void
1425 output_P8_format (vbyte_func f, unw_record_type rtype, unsigned long t)
1427 char bytes[20];
1428 int r = 0;
1429 int count = 2;
1430 bytes[0] = UNW_P8;
1431 switch (rtype)
1433 case rp_sprel:
1434 r = 1;
1435 break;
1436 case pfs_sprel:
1437 r = 2;
1438 break;
1439 case preds_sprel:
1440 r = 3;
1441 break;
1442 case lc_sprel:
1443 r = 4;
1444 break;
1445 case unat_sprel:
1446 r = 5;
1447 break;
1448 case fpsr_sprel:
1449 r = 6;
1450 break;
1451 case bsp_when:
1452 r = 7;
1453 break;
1454 case bsp_psprel:
1455 r = 8;
1456 break;
1457 case bsp_sprel:
1458 r = 9;
1459 break;
1460 case bspstore_when:
1461 r = 10;
1462 break;
1463 case bspstore_psprel:
1464 r = 11;
1465 break;
1466 case bspstore_sprel:
1467 r = 12;
1468 break;
1469 case rnat_when:
1470 r = 13;
1471 break;
1472 case rnat_psprel:
1473 r = 14;
1474 break;
1475 case rnat_sprel:
1476 r = 15;
1477 break;
1478 case priunat_when_gr:
1479 r = 16;
1480 break;
1481 case priunat_psprel:
1482 r = 17;
1483 break;
1484 case priunat_sprel:
1485 r = 18;
1486 break;
1487 case priunat_when_mem:
1488 r = 19;
1489 break;
1490 default:
1491 break;
1493 bytes[1] = r;
1494 count += output_leb128 (bytes + 2, t, 0);
1495 (*f) (count, bytes, NULL);
1498 static void
1499 output_P9_format (vbyte_func f, int grmask, int gr)
1501 char bytes[3];
1502 bytes[0] = UNW_P9;
1503 bytes[1] = (grmask & 0x0f);
1504 bytes[2] = (gr & 0x7f);
1505 (*f) (3, bytes, NULL);
1508 static void
1509 output_P10_format (vbyte_func f, int abi, int context)
1511 char bytes[3];
1512 bytes[0] = UNW_P10;
1513 bytes[1] = (abi & 0xff);
1514 bytes[2] = (context & 0xff);
1515 (*f) (3, bytes, NULL);
1518 static void
1519 output_B1_format (vbyte_func f, unw_record_type rtype, unsigned long label)
1521 char byte;
1522 int r = 0;
1523 if (label > 0x1f)
1525 output_B4_format (f, rtype, label);
1526 return;
1528 if (rtype == copy_state)
1529 r = 1;
1530 else if (rtype != label_state)
1531 as_bad (_("Invalid record type for format B1"));
1533 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1534 (*f) (1, &byte, NULL);
1537 static void
1538 output_B2_format (vbyte_func f, unsigned long ecount, unsigned long t)
1540 char bytes[20];
1541 int count = 1;
1542 if (ecount > 0x1f)
1544 output_B3_format (f, ecount, t);
1545 return;
1547 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1548 count += output_leb128 (bytes + 1, t, 0);
1549 (*f) (count, bytes, NULL);
1552 static void
1553 output_B3_format (vbyte_func f, unsigned long ecount, unsigned long t)
1555 char bytes[20];
1556 int count = 1;
1557 if (ecount <= 0x1f)
1559 output_B2_format (f, ecount, t);
1560 return;
1562 bytes[0] = UNW_B3;
1563 count += output_leb128 (bytes + 1, t, 0);
1564 count += output_leb128 (bytes + count, ecount, 0);
1565 (*f) (count, bytes, NULL);
1568 static void
1569 output_B4_format (vbyte_func f, unw_record_type rtype, unsigned long label)
1571 char bytes[20];
1572 int r = 0;
1573 int count = 1;
1574 if (label <= 0x1f)
1576 output_B1_format (f, rtype, label);
1577 return;
1580 if (rtype == copy_state)
1581 r = 1;
1582 else if (rtype != label_state)
1583 as_bad (_("Invalid record type for format B1"));
1585 bytes[0] = (UNW_B4 | (r << 3));
1586 count += output_leb128 (bytes + 1, label, 0);
1587 (*f) (count, bytes, NULL);
1590 static char
1591 format_ab_reg (int ab, int reg)
1593 int ret;
1594 ab = (ab & 3);
1595 reg = (reg & 0x1f);
1596 ret = (ab << 5) | reg;
1597 return ret;
1600 static void
1601 output_X1_format (vbyte_func f,
1602 unw_record_type rtype,
1603 int ab,
1604 int reg,
1605 unsigned long t,
1606 unsigned long w1)
1608 char bytes[20];
1609 int r = 0;
1610 int count = 2;
1611 bytes[0] = UNW_X1;
1613 if (rtype == spill_sprel)
1614 r = 1;
1615 else if (rtype != spill_psprel)
1616 as_bad (_("Invalid record type for format X1"));
1617 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1618 count += output_leb128 (bytes + 2, t, 0);
1619 count += output_leb128 (bytes + count, w1, 0);
1620 (*f) (count, bytes, NULL);
1623 static void
1624 output_X2_format (vbyte_func f,
1625 int ab,
1626 int reg,
1627 int x,
1628 int y,
1629 int treg,
1630 unsigned long t)
1632 char bytes[20];
1633 int count = 3;
1634 bytes[0] = UNW_X2;
1635 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1636 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1637 count += output_leb128 (bytes + 3, t, 0);
1638 (*f) (count, bytes, NULL);
1641 static void
1642 output_X3_format (vbyte_func f,
1643 unw_record_type rtype,
1644 int qp,
1645 int ab,
1646 int reg,
1647 unsigned long t,
1648 unsigned long w1)
1650 char bytes[20];
1651 int r = 0;
1652 int count = 3;
1653 bytes[0] = UNW_X3;
1655 if (rtype == spill_sprel_p)
1656 r = 1;
1657 else if (rtype != spill_psprel_p)
1658 as_bad (_("Invalid record type for format X3"));
1659 bytes[1] = ((r << 7) | (qp & 0x3f));
1660 bytes[2] = format_ab_reg (ab, reg);
1661 count += output_leb128 (bytes + 3, t, 0);
1662 count += output_leb128 (bytes + count, w1, 0);
1663 (*f) (count, bytes, NULL);
1666 static void
1667 output_X4_format (vbyte_func f,
1668 int qp,
1669 int ab,
1670 int reg,
1671 int x,
1672 int y,
1673 int treg,
1674 unsigned long t)
1676 char bytes[20];
1677 int count = 4;
1678 bytes[0] = UNW_X4;
1679 bytes[1] = (qp & 0x3f);
1680 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1681 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1682 count += output_leb128 (bytes + 4, t, 0);
1683 (*f) (count, bytes, NULL);
1686 /* This function checks whether there are any outstanding .save-s and
1687 discards them if so. */
1689 static void
1690 check_pending_save (void)
1692 if (unwind.pending_saves)
1694 unw_rec_list *cur, *prev;
1696 as_warn (_("Previous .save incomplete"));
1697 for (cur = unwind.list, prev = NULL; cur; )
1698 if (&cur->r.record.p == unwind.pending_saves)
1700 if (prev)
1701 prev->next = cur->next;
1702 else
1703 unwind.list = cur->next;
1704 if (cur == unwind.tail)
1705 unwind.tail = prev;
1706 if (cur == unwind.current_entry)
1707 unwind.current_entry = cur->next;
1708 /* Don't free the first discarded record, it's being used as
1709 terminator for (currently) br_gr and gr_gr processing, and
1710 also prevents leaving a dangling pointer to it in its
1711 predecessor. */
1712 cur->r.record.p.grmask = 0;
1713 cur->r.record.p.brmask = 0;
1714 cur->r.record.p.frmask = 0;
1715 prev = cur->r.record.p.next;
1716 cur->r.record.p.next = NULL;
1717 cur = prev;
1718 break;
1720 else
1722 prev = cur;
1723 cur = cur->next;
1725 while (cur)
1727 prev = cur;
1728 cur = cur->r.record.p.next;
1729 free (prev);
1731 unwind.pending_saves = NULL;
1735 /* This function allocates a record list structure, and initializes fields. */
1737 static unw_rec_list *
1738 alloc_record (unw_record_type t)
1740 unw_rec_list *ptr;
1741 ptr = XNEW (unw_rec_list);
1742 memset (ptr, 0, sizeof (*ptr));
1743 ptr->slot_number = SLOT_NUM_NOT_SET;
1744 ptr->r.type = t;
1745 return ptr;
1748 /* Dummy unwind record used for calculating the length of the last prologue or
1749 body region. */
1751 static unw_rec_list *
1752 output_endp (void)
1754 unw_rec_list *ptr = alloc_record (endp);
1755 return ptr;
1758 static unw_rec_list *
1759 output_prologue (void)
1761 unw_rec_list *ptr = alloc_record (prologue);
1762 return ptr;
1765 static unw_rec_list *
1766 output_prologue_gr (unsigned int saved_mask, unsigned int reg)
1768 unw_rec_list *ptr = alloc_record (prologue_gr);
1769 ptr->r.record.r.grmask = saved_mask;
1770 ptr->r.record.r.grsave = reg;
1771 return ptr;
1774 static unw_rec_list *
1775 output_body (void)
1777 unw_rec_list *ptr = alloc_record (body);
1778 return ptr;
1781 static unw_rec_list *
1782 output_mem_stack_f (unsigned int size)
1784 unw_rec_list *ptr = alloc_record (mem_stack_f);
1785 ptr->r.record.p.size = size;
1786 return ptr;
1789 static unw_rec_list *
1790 output_mem_stack_v (void)
1792 unw_rec_list *ptr = alloc_record (mem_stack_v);
1793 return ptr;
1796 static unw_rec_list *
1797 output_psp_gr (unsigned int gr)
1799 unw_rec_list *ptr = alloc_record (psp_gr);
1800 ptr->r.record.p.r.gr = gr;
1801 return ptr;
1804 static unw_rec_list *
1805 output_psp_sprel (unsigned int offset)
1807 unw_rec_list *ptr = alloc_record (psp_sprel);
1808 ptr->r.record.p.off.sp = offset / 4;
1809 return ptr;
1812 static unw_rec_list *
1813 output_rp_when (void)
1815 unw_rec_list *ptr = alloc_record (rp_when);
1816 return ptr;
1819 static unw_rec_list *
1820 output_rp_gr (unsigned int gr)
1822 unw_rec_list *ptr = alloc_record (rp_gr);
1823 ptr->r.record.p.r.gr = gr;
1824 return ptr;
1827 static unw_rec_list *
1828 output_rp_br (unsigned int br)
1830 unw_rec_list *ptr = alloc_record (rp_br);
1831 ptr->r.record.p.r.br = br;
1832 return ptr;
1835 static unw_rec_list *
1836 output_rp_psprel (unsigned int offset)
1838 unw_rec_list *ptr = alloc_record (rp_psprel);
1839 ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset);
1840 return ptr;
1843 static unw_rec_list *
1844 output_rp_sprel (unsigned int offset)
1846 unw_rec_list *ptr = alloc_record (rp_sprel);
1847 ptr->r.record.p.off.sp = offset / 4;
1848 return ptr;
1851 static unw_rec_list *
1852 output_pfs_when (void)
1854 unw_rec_list *ptr = alloc_record (pfs_when);
1855 return ptr;
1858 static unw_rec_list *
1859 output_pfs_gr (unsigned int gr)
1861 unw_rec_list *ptr = alloc_record (pfs_gr);
1862 ptr->r.record.p.r.gr = gr;
1863 return ptr;
1866 static unw_rec_list *
1867 output_pfs_psprel (unsigned int offset)
1869 unw_rec_list *ptr = alloc_record (pfs_psprel);
1870 ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset);
1871 return ptr;
1874 static unw_rec_list *
1875 output_pfs_sprel (unsigned int offset)
1877 unw_rec_list *ptr = alloc_record (pfs_sprel);
1878 ptr->r.record.p.off.sp = offset / 4;
1879 return ptr;
1882 static unw_rec_list *
1883 output_preds_when (void)
1885 unw_rec_list *ptr = alloc_record (preds_when);
1886 return ptr;
1889 static unw_rec_list *
1890 output_preds_gr (unsigned int gr)
1892 unw_rec_list *ptr = alloc_record (preds_gr);
1893 ptr->r.record.p.r.gr = gr;
1894 return ptr;
1897 static unw_rec_list *
1898 output_preds_psprel (unsigned int offset)
1900 unw_rec_list *ptr = alloc_record (preds_psprel);
1901 ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset);
1902 return ptr;
1905 static unw_rec_list *
1906 output_preds_sprel (unsigned int offset)
1908 unw_rec_list *ptr = alloc_record (preds_sprel);
1909 ptr->r.record.p.off.sp = offset / 4;
1910 return ptr;
1913 static unw_rec_list *
1914 output_fr_mem (unsigned int mask)
1916 unw_rec_list *ptr = alloc_record (fr_mem);
1917 unw_rec_list *cur = ptr;
1919 ptr->r.record.p.frmask = mask;
1920 unwind.pending_saves = &ptr->r.record.p;
1921 for (;;)
1923 unw_rec_list *prev = cur;
1925 /* Clear least significant set bit. */
1926 mask &= ~(mask & (~mask + 1));
1927 if (!mask)
1928 return ptr;
1929 cur = alloc_record (fr_mem);
1930 cur->r.record.p.frmask = mask;
1931 /* Retain only least significant bit. */
1932 prev->r.record.p.frmask ^= mask;
1933 prev->r.record.p.next = cur;
1937 static unw_rec_list *
1938 output_frgr_mem (unsigned int gr_mask, unsigned int fr_mask)
1940 unw_rec_list *ptr = alloc_record (frgr_mem);
1941 unw_rec_list *cur = ptr;
1943 unwind.pending_saves = &cur->r.record.p;
1944 cur->r.record.p.frmask = fr_mask;
1945 while (fr_mask)
1947 unw_rec_list *prev = cur;
1949 /* Clear least significant set bit. */
1950 fr_mask &= ~(fr_mask & (~fr_mask + 1));
1951 if (!gr_mask && !fr_mask)
1952 return ptr;
1953 cur = alloc_record (frgr_mem);
1954 cur->r.record.p.frmask = fr_mask;
1955 /* Retain only least significant bit. */
1956 prev->r.record.p.frmask ^= fr_mask;
1957 prev->r.record.p.next = cur;
1959 cur->r.record.p.grmask = gr_mask;
1960 for (;;)
1962 unw_rec_list *prev = cur;
1964 /* Clear least significant set bit. */
1965 gr_mask &= ~(gr_mask & (~gr_mask + 1));
1966 if (!gr_mask)
1967 return ptr;
1968 cur = alloc_record (frgr_mem);
1969 cur->r.record.p.grmask = gr_mask;
1970 /* Retain only least significant bit. */
1971 prev->r.record.p.grmask ^= gr_mask;
1972 prev->r.record.p.next = cur;
1976 static unw_rec_list *
1977 output_gr_gr (unsigned int mask, unsigned int reg)
1979 unw_rec_list *ptr = alloc_record (gr_gr);
1980 unw_rec_list *cur = ptr;
1982 ptr->r.record.p.grmask = mask;
1983 ptr->r.record.p.r.gr = reg;
1984 unwind.pending_saves = &ptr->r.record.p;
1985 for (;;)
1987 unw_rec_list *prev = cur;
1989 /* Clear least significant set bit. */
1990 mask &= ~(mask & (~mask + 1));
1991 if (!mask)
1992 return ptr;
1993 cur = alloc_record (gr_gr);
1994 cur->r.record.p.grmask = mask;
1995 /* Indicate this record shouldn't be output. */
1996 cur->r.record.p.r.gr = REG_NUM;
1997 /* Retain only least significant bit. */
1998 prev->r.record.p.grmask ^= mask;
1999 prev->r.record.p.next = cur;
2003 static unw_rec_list *
2004 output_gr_mem (unsigned int mask)
2006 unw_rec_list *ptr = alloc_record (gr_mem);
2007 unw_rec_list *cur = ptr;
2009 ptr->r.record.p.grmask = mask;
2010 unwind.pending_saves = &ptr->r.record.p;
2011 for (;;)
2013 unw_rec_list *prev = cur;
2015 /* Clear least significant set bit. */
2016 mask &= ~(mask & (~mask + 1));
2017 if (!mask)
2018 return ptr;
2019 cur = alloc_record (gr_mem);
2020 cur->r.record.p.grmask = mask;
2021 /* Retain only least significant bit. */
2022 prev->r.record.p.grmask ^= mask;
2023 prev->r.record.p.next = cur;
2027 static unw_rec_list *
2028 output_br_mem (unsigned int mask)
2030 unw_rec_list *ptr = alloc_record (br_mem);
2031 unw_rec_list *cur = ptr;
2033 ptr->r.record.p.brmask = mask;
2034 unwind.pending_saves = &ptr->r.record.p;
2035 for (;;)
2037 unw_rec_list *prev = cur;
2039 /* Clear least significant set bit. */
2040 mask &= ~(mask & (~mask + 1));
2041 if (!mask)
2042 return ptr;
2043 cur = alloc_record (br_mem);
2044 cur->r.record.p.brmask = mask;
2045 /* Retain only least significant bit. */
2046 prev->r.record.p.brmask ^= mask;
2047 prev->r.record.p.next = cur;
2051 static unw_rec_list *
2052 output_br_gr (unsigned int mask, unsigned int reg)
2054 unw_rec_list *ptr = alloc_record (br_gr);
2055 unw_rec_list *cur = ptr;
2057 ptr->r.record.p.brmask = mask;
2058 ptr->r.record.p.r.gr = reg;
2059 unwind.pending_saves = &ptr->r.record.p;
2060 for (;;)
2062 unw_rec_list *prev = cur;
2064 /* Clear least significant set bit. */
2065 mask &= ~(mask & (~mask + 1));
2066 if (!mask)
2067 return ptr;
2068 cur = alloc_record (br_gr);
2069 cur->r.record.p.brmask = mask;
2070 /* Indicate this record shouldn't be output. */
2071 cur->r.record.p.r.gr = REG_NUM;
2072 /* Retain only least significant bit. */
2073 prev->r.record.p.brmask ^= mask;
2074 prev->r.record.p.next = cur;
2078 static unw_rec_list *
2079 output_spill_base (unsigned int offset)
2081 unw_rec_list *ptr = alloc_record (spill_base);
2082 ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset);
2083 return ptr;
2086 static unw_rec_list *
2087 output_unat_when (void)
2089 unw_rec_list *ptr = alloc_record (unat_when);
2090 return ptr;
2093 static unw_rec_list *
2094 output_unat_gr (unsigned int gr)
2096 unw_rec_list *ptr = alloc_record (unat_gr);
2097 ptr->r.record.p.r.gr = gr;
2098 return ptr;
2101 static unw_rec_list *
2102 output_unat_psprel (unsigned int offset)
2104 unw_rec_list *ptr = alloc_record (unat_psprel);
2105 ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset);
2106 return ptr;
2109 static unw_rec_list *
2110 output_unat_sprel (unsigned int offset)
2112 unw_rec_list *ptr = alloc_record (unat_sprel);
2113 ptr->r.record.p.off.sp = offset / 4;
2114 return ptr;
2117 static unw_rec_list *
2118 output_lc_when (void)
2120 unw_rec_list *ptr = alloc_record (lc_when);
2121 return ptr;
2124 static unw_rec_list *
2125 output_lc_gr (unsigned int gr)
2127 unw_rec_list *ptr = alloc_record (lc_gr);
2128 ptr->r.record.p.r.gr = gr;
2129 return ptr;
2132 static unw_rec_list *
2133 output_lc_psprel (unsigned int offset)
2135 unw_rec_list *ptr = alloc_record (lc_psprel);
2136 ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset);
2137 return ptr;
2140 static unw_rec_list *
2141 output_lc_sprel (unsigned int offset)
2143 unw_rec_list *ptr = alloc_record (lc_sprel);
2144 ptr->r.record.p.off.sp = offset / 4;
2145 return ptr;
2148 static unw_rec_list *
2149 output_fpsr_when (void)
2151 unw_rec_list *ptr = alloc_record (fpsr_when);
2152 return ptr;
2155 static unw_rec_list *
2156 output_fpsr_gr (unsigned int gr)
2158 unw_rec_list *ptr = alloc_record (fpsr_gr);
2159 ptr->r.record.p.r.gr = gr;
2160 return ptr;
2163 static unw_rec_list *
2164 output_fpsr_psprel (unsigned int offset)
2166 unw_rec_list *ptr = alloc_record (fpsr_psprel);
2167 ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset);
2168 return ptr;
2171 static unw_rec_list *
2172 output_fpsr_sprel (unsigned int offset)
2174 unw_rec_list *ptr = alloc_record (fpsr_sprel);
2175 ptr->r.record.p.off.sp = offset / 4;
2176 return ptr;
2179 static unw_rec_list *
2180 output_priunat_when_gr (void)
2182 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2183 return ptr;
2186 static unw_rec_list *
2187 output_priunat_when_mem (void)
2189 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2190 return ptr;
2193 static unw_rec_list *
2194 output_priunat_gr (unsigned int gr)
2196 unw_rec_list *ptr = alloc_record (priunat_gr);
2197 ptr->r.record.p.r.gr = gr;
2198 return ptr;
2201 static unw_rec_list *
2202 output_priunat_psprel (unsigned int offset)
2204 unw_rec_list *ptr = alloc_record (priunat_psprel);
2205 ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset);
2206 return ptr;
2209 static unw_rec_list *
2210 output_priunat_sprel (unsigned int offset)
2212 unw_rec_list *ptr = alloc_record (priunat_sprel);
2213 ptr->r.record.p.off.sp = offset / 4;
2214 return ptr;
2217 static unw_rec_list *
2218 output_bsp_when (void)
2220 unw_rec_list *ptr = alloc_record (bsp_when);
2221 return ptr;
2224 static unw_rec_list *
2225 output_bsp_gr (unsigned int gr)
2227 unw_rec_list *ptr = alloc_record (bsp_gr);
2228 ptr->r.record.p.r.gr = gr;
2229 return ptr;
2232 static unw_rec_list *
2233 output_bsp_psprel (unsigned int offset)
2235 unw_rec_list *ptr = alloc_record (bsp_psprel);
2236 ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset);
2237 return ptr;
2240 static unw_rec_list *
2241 output_bsp_sprel (unsigned int offset)
2243 unw_rec_list *ptr = alloc_record (bsp_sprel);
2244 ptr->r.record.p.off.sp = offset / 4;
2245 return ptr;
2248 static unw_rec_list *
2249 output_bspstore_when (void)
2251 unw_rec_list *ptr = alloc_record (bspstore_when);
2252 return ptr;
2255 static unw_rec_list *
2256 output_bspstore_gr (unsigned int gr)
2258 unw_rec_list *ptr = alloc_record (bspstore_gr);
2259 ptr->r.record.p.r.gr = gr;
2260 return ptr;
2263 static unw_rec_list *
2264 output_bspstore_psprel (unsigned int offset)
2266 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2267 ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset);
2268 return ptr;
2271 static unw_rec_list *
2272 output_bspstore_sprel (unsigned int offset)
2274 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2275 ptr->r.record.p.off.sp = offset / 4;
2276 return ptr;
2279 static unw_rec_list *
2280 output_rnat_when (void)
2282 unw_rec_list *ptr = alloc_record (rnat_when);
2283 return ptr;
2286 static unw_rec_list *
2287 output_rnat_gr (unsigned int gr)
2289 unw_rec_list *ptr = alloc_record (rnat_gr);
2290 ptr->r.record.p.r.gr = gr;
2291 return ptr;
2294 static unw_rec_list *
2295 output_rnat_psprel (unsigned int offset)
2297 unw_rec_list *ptr = alloc_record (rnat_psprel);
2298 ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset);
2299 return ptr;
2302 static unw_rec_list *
2303 output_rnat_sprel (unsigned int offset)
2305 unw_rec_list *ptr = alloc_record (rnat_sprel);
2306 ptr->r.record.p.off.sp = offset / 4;
2307 return ptr;
2310 static unw_rec_list *
2311 output_unwabi (unsigned long abi, unsigned long context)
2313 unw_rec_list *ptr = alloc_record (unwabi);
2314 ptr->r.record.p.abi = abi;
2315 ptr->r.record.p.context = context;
2316 return ptr;
2319 static unw_rec_list *
2320 output_epilogue (unsigned long ecount)
2322 unw_rec_list *ptr = alloc_record (epilogue);
2323 ptr->r.record.b.ecount = ecount;
2324 return ptr;
2327 static unw_rec_list *
2328 output_label_state (unsigned long label)
2330 unw_rec_list *ptr = alloc_record (label_state);
2331 ptr->r.record.b.label = label;
2332 return ptr;
2335 static unw_rec_list *
2336 output_copy_state (unsigned long label)
2338 unw_rec_list *ptr = alloc_record (copy_state);
2339 ptr->r.record.b.label = label;
2340 return ptr;
2343 static unw_rec_list *
2344 output_spill_psprel (unsigned int ab,
2345 unsigned int reg,
2346 unsigned int offset,
2347 unsigned int predicate)
2349 unw_rec_list *ptr = alloc_record (predicate ? spill_psprel_p : spill_psprel);
2350 ptr->r.record.x.ab = ab;
2351 ptr->r.record.x.reg = reg;
2352 ptr->r.record.x.where.pspoff = ENCODED_PSP_OFFSET (offset);
2353 ptr->r.record.x.qp = predicate;
2354 return ptr;
2357 static unw_rec_list *
2358 output_spill_sprel (unsigned int ab,
2359 unsigned int reg,
2360 unsigned int offset,
2361 unsigned int predicate)
2363 unw_rec_list *ptr = alloc_record (predicate ? spill_sprel_p : spill_sprel);
2364 ptr->r.record.x.ab = ab;
2365 ptr->r.record.x.reg = reg;
2366 ptr->r.record.x.where.spoff = offset / 4;
2367 ptr->r.record.x.qp = predicate;
2368 return ptr;
2371 static unw_rec_list *
2372 output_spill_reg (unsigned int ab,
2373 unsigned int reg,
2374 unsigned int targ_reg,
2375 unsigned int xy,
2376 unsigned int predicate)
2378 unw_rec_list *ptr = alloc_record (predicate ? spill_reg_p : spill_reg);
2379 ptr->r.record.x.ab = ab;
2380 ptr->r.record.x.reg = reg;
2381 ptr->r.record.x.where.reg = targ_reg;
2382 ptr->r.record.x.xy = xy;
2383 ptr->r.record.x.qp = predicate;
2384 return ptr;
2387 /* Given a unw_rec_list process the correct format with the
2388 specified function. */
2390 static void
2391 process_one_record (unw_rec_list *ptr, vbyte_func f)
2393 unsigned int fr_mask, gr_mask;
2395 switch (ptr->r.type)
2397 /* This is a dummy record that takes up no space in the output. */
2398 case endp:
2399 break;
2401 case gr_mem:
2402 case fr_mem:
2403 case br_mem:
2404 case frgr_mem:
2405 /* These are taken care of by prologue/prologue_gr. */
2406 break;
2408 case prologue_gr:
2409 case prologue:
2410 if (ptr->r.type == prologue_gr)
2411 output_R2_format (f, ptr->r.record.r.grmask,
2412 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2413 else
2414 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2416 /* Output descriptor(s) for union of register spills (if any). */
2417 gr_mask = ptr->r.record.r.mask.gr_mem;
2418 fr_mask = ptr->r.record.r.mask.fr_mem;
2419 if (fr_mask)
2421 if ((fr_mask & ~0xfUL) == 0)
2422 output_P6_format (f, fr_mem, fr_mask);
2423 else
2425 output_P5_format (f, gr_mask, fr_mask);
2426 gr_mask = 0;
2429 if (gr_mask)
2430 output_P6_format (f, gr_mem, gr_mask);
2431 if (ptr->r.record.r.mask.br_mem)
2432 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2434 /* output imask descriptor if necessary: */
2435 if (ptr->r.record.r.mask.i)
2436 output_P4_format (f, ptr->r.record.r.mask.i,
2437 ptr->r.record.r.imask_size);
2438 break;
2440 case body:
2441 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2442 break;
2443 case mem_stack_f:
2444 case mem_stack_v:
2445 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2446 ptr->r.record.p.size);
2447 break;
2448 case psp_gr:
2449 case rp_gr:
2450 case pfs_gr:
2451 case preds_gr:
2452 case unat_gr:
2453 case lc_gr:
2454 case fpsr_gr:
2455 case priunat_gr:
2456 case bsp_gr:
2457 case bspstore_gr:
2458 case rnat_gr:
2459 output_P3_format (f, ptr->r.type, ptr->r.record.p.r.gr);
2460 break;
2461 case rp_br:
2462 output_P3_format (f, rp_br, ptr->r.record.p.r.br);
2463 break;
2464 case psp_sprel:
2465 output_P7_format (f, psp_sprel, ptr->r.record.p.off.sp, 0);
2466 break;
2467 case rp_when:
2468 case pfs_when:
2469 case preds_when:
2470 case unat_when:
2471 case lc_when:
2472 case fpsr_when:
2473 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2474 break;
2475 case rp_psprel:
2476 case pfs_psprel:
2477 case preds_psprel:
2478 case unat_psprel:
2479 case lc_psprel:
2480 case fpsr_psprel:
2481 case spill_base:
2482 output_P7_format (f, ptr->r.type, ptr->r.record.p.off.psp, 0);
2483 break;
2484 case rp_sprel:
2485 case pfs_sprel:
2486 case preds_sprel:
2487 case unat_sprel:
2488 case lc_sprel:
2489 case fpsr_sprel:
2490 case priunat_sprel:
2491 case bsp_sprel:
2492 case bspstore_sprel:
2493 case rnat_sprel:
2494 output_P8_format (f, ptr->r.type, ptr->r.record.p.off.sp);
2495 break;
2496 case gr_gr:
2497 if (ptr->r.record.p.r.gr < REG_NUM)
2499 const unw_rec_list *cur = ptr;
2501 gr_mask = cur->r.record.p.grmask;
2502 while ((cur = cur->r.record.p.next) != NULL)
2503 gr_mask |= cur->r.record.p.grmask;
2504 output_P9_format (f, gr_mask, ptr->r.record.p.r.gr);
2506 break;
2507 case br_gr:
2508 if (ptr->r.record.p.r.gr < REG_NUM)
2510 const unw_rec_list *cur = ptr;
2512 gr_mask = cur->r.record.p.brmask;
2513 while ((cur = cur->r.record.p.next) != NULL)
2514 gr_mask |= cur->r.record.p.brmask;
2515 output_P2_format (f, gr_mask, ptr->r.record.p.r.gr);
2517 break;
2518 case spill_mask:
2519 as_bad (_("spill_mask record unimplemented."));
2520 break;
2521 case priunat_when_gr:
2522 case priunat_when_mem:
2523 case bsp_when:
2524 case bspstore_when:
2525 case rnat_when:
2526 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2527 break;
2528 case priunat_psprel:
2529 case bsp_psprel:
2530 case bspstore_psprel:
2531 case rnat_psprel:
2532 output_P8_format (f, ptr->r.type, ptr->r.record.p.off.psp);
2533 break;
2534 case unwabi:
2535 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2536 break;
2537 case epilogue:
2538 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2539 break;
2540 case label_state:
2541 case copy_state:
2542 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2543 break;
2544 case spill_psprel:
2545 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2546 ptr->r.record.x.reg, ptr->r.record.x.t,
2547 ptr->r.record.x.where.pspoff);
2548 break;
2549 case spill_sprel:
2550 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2551 ptr->r.record.x.reg, ptr->r.record.x.t,
2552 ptr->r.record.x.where.spoff);
2553 break;
2554 case spill_reg:
2555 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2556 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2557 ptr->r.record.x.where.reg, ptr->r.record.x.t);
2558 break;
2559 case spill_psprel_p:
2560 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2561 ptr->r.record.x.ab, ptr->r.record.x.reg,
2562 ptr->r.record.x.t, ptr->r.record.x.where.pspoff);
2563 break;
2564 case spill_sprel_p:
2565 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2566 ptr->r.record.x.ab, ptr->r.record.x.reg,
2567 ptr->r.record.x.t, ptr->r.record.x.where.spoff);
2568 break;
2569 case spill_reg_p:
2570 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2571 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2572 ptr->r.record.x.xy, ptr->r.record.x.where.reg,
2573 ptr->r.record.x.t);
2574 break;
2575 default:
2576 as_bad (_("record_type_not_valid"));
2577 break;
2581 /* Given a unw_rec_list list, process all the records with
2582 the specified function. */
2583 static void
2584 process_unw_records (unw_rec_list *list, vbyte_func f)
2586 unw_rec_list *ptr;
2587 for (ptr = list; ptr; ptr = ptr->next)
2588 process_one_record (ptr, f);
2591 /* Determine the size of a record list in bytes. */
2592 static int
2593 calc_record_size (unw_rec_list *list)
2595 vbyte_count = 0;
2596 process_unw_records (list, count_output);
2597 return vbyte_count;
2600 /* Return the number of bits set in the input value.
2601 Perhaps this has a better place... */
2602 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
2603 # define popcount __builtin_popcount
2604 #else
2605 static int
2606 popcount (unsigned x)
2608 static const unsigned char popcnt[16] =
2610 0, 1, 1, 2,
2611 1, 2, 2, 3,
2612 1, 2, 2, 3,
2613 2, 3, 3, 4
2616 if (x < NELEMS (popcnt))
2617 return popcnt[x];
2618 return popcnt[x % NELEMS (popcnt)] + popcount (x / NELEMS (popcnt));
2620 #endif
2622 /* Update IMASK bitmask to reflect the fact that one or more registers
2623 of type TYPE are saved starting at instruction with index T. If N
2624 bits are set in REGMASK, it is assumed that instructions T through
2625 T+N-1 save these registers.
2627 TYPE values:
2628 0: no save
2629 1: instruction saves next fp reg
2630 2: instruction saves next general reg
2631 3: instruction saves next branch reg */
2632 static void
2633 set_imask (unw_rec_list *region,
2634 unsigned long regmask,
2635 unsigned long t,
2636 unsigned int type)
2638 unsigned char *imask;
2639 unsigned long imask_size;
2640 unsigned int i;
2641 int pos;
2643 imask = region->r.record.r.mask.i;
2644 imask_size = region->r.record.r.imask_size;
2645 if (!imask)
2647 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2648 imask = XCNEWVEC (unsigned char, imask_size);
2650 region->r.record.r.imask_size = imask_size;
2651 region->r.record.r.mask.i = imask;
2654 i = (t / 4) + 1;
2655 pos = 2 * (3 - t % 4);
2656 while (regmask)
2658 if (i >= imask_size)
2660 as_bad (_("Ignoring attempt to spill beyond end of region"));
2661 return;
2664 imask[i] |= (type & 0x3) << pos;
2666 regmask &= (regmask - 1);
2667 pos -= 2;
2668 if (pos < 0)
2670 pos = 0;
2671 ++i;
2676 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2677 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2678 containing FIRST_ADDR. If BEFORE_RELAX, then we use worst-case estimates
2679 for frag sizes. */
2681 static unsigned long
2682 slot_index (unsigned long slot_addr,
2683 fragS *slot_frag,
2684 unsigned long first_addr,
2685 fragS *first_frag,
2686 int before_relax)
2688 unsigned long s_index = 0;
2690 /* First time we are called, the initial address and frag are invalid. */
2691 if (first_addr == 0)
2692 return 0;
2694 /* If the two addresses are in different frags, then we need to add in
2695 the remaining size of this frag, and then the entire size of intermediate
2696 frags. */
2697 while (slot_frag != first_frag)
2699 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2701 if (! before_relax)
2703 /* We can get the final addresses only during and after
2704 relaxation. */
2705 if (first_frag->fr_next && first_frag->fr_next->fr_address)
2706 s_index += 3 * ((first_frag->fr_next->fr_address
2707 - first_frag->fr_address
2708 - first_frag->fr_fix) >> 4);
2710 else
2711 /* We don't know what the final addresses will be. We try our
2712 best to estimate. */
2713 switch (first_frag->fr_type)
2715 default:
2716 break;
2718 case rs_space:
2719 as_fatal (_("Only constant space allocation is supported"));
2720 break;
2722 case rs_align:
2723 case rs_align_code:
2724 case rs_align_test:
2725 /* Take alignment into account. Assume the worst case
2726 before relaxation. */
2727 s_index += 3 * ((1 << first_frag->fr_offset) >> 4);
2728 break;
2730 case rs_org:
2731 if (first_frag->fr_symbol)
2733 as_fatal (_("Only constant offsets are supported"));
2734 break;
2736 /* Fall through. */
2737 case rs_fill:
2738 s_index += 3 * (first_frag->fr_offset >> 4);
2739 break;
2742 /* Add in the full size of the frag converted to instruction slots. */
2743 s_index += 3 * (first_frag->fr_fix >> 4);
2744 /* Subtract away the initial part before first_addr. */
2745 s_index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2746 + ((first_addr & 0x3) - (start_addr & 0x3)));
2748 /* Move to the beginning of the next frag. */
2749 first_frag = first_frag->fr_next;
2750 first_addr = (unsigned long) &first_frag->fr_literal;
2752 /* This can happen if there is section switching in the middle of a
2753 function, causing the frag chain for the function to be broken.
2754 It is too difficult to recover safely from this problem, so we just
2755 exit with an error. */
2756 if (first_frag == NULL)
2757 as_fatal (_("Section switching in code is not supported."));
2760 /* Add in the used part of the last frag. */
2761 s_index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2762 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2763 return s_index;
2766 /* Optimize unwind record directives. */
2768 static unw_rec_list *
2769 optimize_unw_records (unw_rec_list *list)
2771 if (!list)
2772 return NULL;
2774 /* If the only unwind record is ".prologue" or ".prologue" followed
2775 by ".body", then we can optimize the unwind directives away. */
2776 if (list->r.type == prologue
2777 && (list->next->r.type == endp
2778 || (list->next->r.type == body && list->next->next->r.type == endp)))
2779 return NULL;
2781 return list;
2784 /* Given a complete record list, process any records which have
2785 unresolved fields, (ie length counts for a prologue). After
2786 this has been run, all necessary information should be available
2787 within each record to generate an image. */
2789 static void
2790 fixup_unw_records (unw_rec_list *list, int before_relax)
2792 unw_rec_list *ptr, *region = 0;
2793 unsigned long first_addr = 0, rlen = 0, t;
2794 fragS *first_frag = 0;
2796 for (ptr = list; ptr; ptr = ptr->next)
2798 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2799 as_bad (_("Insn slot not set in unwind record."));
2800 t = slot_index (ptr->slot_number, ptr->slot_frag,
2801 first_addr, first_frag, before_relax);
2802 switch (ptr->r.type)
2804 case prologue:
2805 case prologue_gr:
2806 case body:
2808 unw_rec_list *last;
2809 int size;
2810 unsigned long last_addr = 0;
2811 fragS *last_frag = NULL;
2813 first_addr = ptr->slot_number;
2814 first_frag = ptr->slot_frag;
2815 /* Find either the next body/prologue start, or the end of
2816 the function, and determine the size of the region. */
2817 for (last = ptr->next; last != NULL; last = last->next)
2818 if (last->r.type == prologue || last->r.type == prologue_gr
2819 || last->r.type == body || last->r.type == endp)
2821 last_addr = last->slot_number;
2822 last_frag = last->slot_frag;
2823 break;
2825 size = slot_index (last_addr, last_frag, first_addr, first_frag,
2826 before_relax);
2827 rlen = ptr->r.record.r.rlen = size;
2828 if (ptr->r.type == body)
2829 /* End of region. */
2830 region = 0;
2831 else
2832 region = ptr;
2833 break;
2835 case epilogue:
2836 if (t < rlen)
2837 ptr->r.record.b.t = rlen - 1 - t;
2838 else
2839 /* This happens when a memory-stack-less procedure uses a
2840 ".restore sp" directive at the end of a region to pop
2841 the frame state. */
2842 ptr->r.record.b.t = 0;
2843 break;
2845 case mem_stack_f:
2846 case mem_stack_v:
2847 case rp_when:
2848 case pfs_when:
2849 case preds_when:
2850 case unat_when:
2851 case lc_when:
2852 case fpsr_when:
2853 case priunat_when_gr:
2854 case priunat_when_mem:
2855 case bsp_when:
2856 case bspstore_when:
2857 case rnat_when:
2858 ptr->r.record.p.t = t;
2859 break;
2861 case spill_reg:
2862 case spill_sprel:
2863 case spill_psprel:
2864 case spill_reg_p:
2865 case spill_sprel_p:
2866 case spill_psprel_p:
2867 ptr->r.record.x.t = t;
2868 break;
2870 case frgr_mem:
2871 if (!region)
2873 as_bad (_("frgr_mem record before region record!"));
2874 return;
2876 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2877 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2878 set_imask (region, ptr->r.record.p.frmask, t, 1);
2879 set_imask (region, ptr->r.record.p.grmask, t, 2);
2880 break;
2881 case fr_mem:
2882 if (!region)
2884 as_bad (_("fr_mem record before region record!"));
2885 return;
2887 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2888 set_imask (region, ptr->r.record.p.frmask, t, 1);
2889 break;
2890 case gr_mem:
2891 if (!region)
2893 as_bad (_("gr_mem record before region record!"));
2894 return;
2896 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2897 set_imask (region, ptr->r.record.p.grmask, t, 2);
2898 break;
2899 case br_mem:
2900 if (!region)
2902 as_bad (_("br_mem record before region record!"));
2903 return;
2905 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2906 set_imask (region, ptr->r.record.p.brmask, t, 3);
2907 break;
2909 case gr_gr:
2910 if (!region)
2912 as_bad (_("gr_gr record before region record!"));
2913 return;
2915 set_imask (region, ptr->r.record.p.grmask, t, 2);
2916 break;
2917 case br_gr:
2918 if (!region)
2920 as_bad (_("br_gr record before region record!"));
2921 return;
2923 set_imask (region, ptr->r.record.p.brmask, t, 3);
2924 break;
2926 default:
2927 break;
2932 /* Estimate the size of a frag before relaxing. We only have one type of frag
2933 to handle here, which is the unwind info frag. */
2936 ia64_estimate_size_before_relax (fragS *frag,
2937 asection *segtype ATTRIBUTE_UNUSED)
2939 unw_rec_list *list;
2940 int len, size, pad;
2942 /* ??? This code is identical to the first part of ia64_convert_frag. */
2943 list = (unw_rec_list *) frag->fr_opcode;
2944 fixup_unw_records (list, 0);
2946 len = calc_record_size (list);
2947 /* pad to pointer-size boundary. */
2948 pad = len % md.pointer_size;
2949 if (pad != 0)
2950 len += md.pointer_size - pad;
2951 /* Add 8 for the header. */
2952 size = len + 8;
2953 /* Add a pointer for the personality offset. */
2954 if (frag->fr_offset)
2955 size += md.pointer_size;
2957 /* fr_var carries the max_chars that we created the fragment with.
2958 We must, of course, have allocated enough memory earlier. */
2959 gas_assert (frag->fr_var >= size);
2961 return frag->fr_fix + size;
2964 /* This function converts a rs_machine_dependent variant frag into a
2965 normal fill frag with the unwind image from the record list. */
2966 void
2967 ia64_convert_frag (fragS *frag)
2969 unw_rec_list *list;
2970 int len, size, pad;
2971 valueT flag_value;
2973 /* ??? This code is identical to ia64_estimate_size_before_relax. */
2974 list = (unw_rec_list *) frag->fr_opcode;
2975 fixup_unw_records (list, 0);
2977 len = calc_record_size (list);
2978 /* pad to pointer-size boundary. */
2979 pad = len % md.pointer_size;
2980 if (pad != 0)
2981 len += md.pointer_size - pad;
2982 /* Add 8 for the header. */
2983 size = len + 8;
2984 /* Add a pointer for the personality offset. */
2985 if (frag->fr_offset)
2986 size += md.pointer_size;
2988 /* fr_var carries the max_chars that we created the fragment with.
2989 We must, of course, have allocated enough memory earlier. */
2990 gas_assert (frag->fr_var >= size);
2992 /* Initialize the header area. fr_offset is initialized with
2993 unwind.personality_routine. */
2994 if (frag->fr_offset)
2996 if (md.flags & EF_IA_64_ABI64)
2997 flag_value = (bfd_vma) 3 << 32;
2998 else
2999 /* 32-bit unwind info block. */
3000 flag_value = (bfd_vma) 0x1003 << 32;
3002 else
3003 flag_value = 0;
3005 md_number_to_chars (frag->fr_literal,
3006 (((bfd_vma) 1 << 48) /* Version. */
3007 | flag_value /* U & E handler flags. */
3008 | (len / md.pointer_size)), /* Length. */
3011 /* Skip the header. */
3012 vbyte_mem_ptr = frag->fr_literal + 8;
3013 process_unw_records (list, output_vbyte_mem);
3015 /* Fill the padding bytes with zeros. */
3016 if (pad != 0)
3017 md_number_to_chars (frag->fr_literal + len + 8 - md.pointer_size + pad, 0,
3018 md.pointer_size - pad);
3019 /* Fill the unwind personality with zeros. */
3020 if (frag->fr_offset)
3021 md_number_to_chars (frag->fr_literal + size - md.pointer_size, 0,
3022 md.pointer_size);
3024 frag->fr_fix += size;
3025 frag->fr_type = rs_fill;
3026 frag->fr_var = 0;
3027 frag->fr_offset = 0;
3030 static int
3031 parse_predicate_and_operand (expressionS *e, unsigned *qp, const char *po)
3033 int sep = parse_operand_and_eval (e, ',');
3035 *qp = e->X_add_number - REG_P;
3036 if (e->X_op != O_register || *qp > 63)
3038 as_bad (_("First operand to .%s must be a predicate"), po);
3039 *qp = 0;
3041 else if (*qp == 0)
3042 as_warn (_("Pointless use of p0 as first operand to .%s"), po);
3043 if (sep == ',')
3044 sep = parse_operand_and_eval (e, ',');
3045 else
3046 e->X_op = O_absent;
3047 return sep;
3050 static void
3051 convert_expr_to_ab_reg (const expressionS *e,
3052 unsigned int *ab,
3053 unsigned int *regp,
3054 const char *po,
3055 int n)
3057 unsigned int reg = e->X_add_number;
3059 *ab = *regp = 0; /* Anything valid is good here. */
3061 if (e->X_op != O_register)
3062 reg = REG_GR; /* Anything invalid is good here. */
3064 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
3066 *ab = 0;
3067 *regp = reg - REG_GR;
3069 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
3070 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
3072 *ab = 1;
3073 *regp = reg - REG_FR;
3075 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
3077 *ab = 2;
3078 *regp = reg - REG_BR;
3080 else
3082 *ab = 3;
3083 switch (reg)
3085 case REG_PR: *regp = 0; break;
3086 case REG_PSP: *regp = 1; break;
3087 case REG_PRIUNAT: *regp = 2; break;
3088 case REG_BR + 0: *regp = 3; break;
3089 case REG_AR + AR_BSP: *regp = 4; break;
3090 case REG_AR + AR_BSPSTORE: *regp = 5; break;
3091 case REG_AR + AR_RNAT: *regp = 6; break;
3092 case REG_AR + AR_UNAT: *regp = 7; break;
3093 case REG_AR + AR_FPSR: *regp = 8; break;
3094 case REG_AR + AR_PFS: *regp = 9; break;
3095 case REG_AR + AR_LC: *regp = 10; break;
3097 default:
3098 as_bad (_("Operand %d to .%s must be a preserved register"), n, po);
3099 break;
3104 static void
3105 convert_expr_to_xy_reg (const expressionS *e,
3106 unsigned int *xy,
3107 unsigned int *regp,
3108 const char *po,
3109 int n)
3111 unsigned int reg = e->X_add_number;
3113 *xy = *regp = 0; /* Anything valid is good here. */
3115 if (e->X_op != O_register)
3116 reg = REG_GR; /* Anything invalid is good here. */
3118 if (reg >= (REG_GR + 1) && reg <= (REG_GR + 127))
3120 *xy = 0;
3121 *regp = reg - REG_GR;
3123 else if (reg >= (REG_FR + 2) && reg <= (REG_FR + 127))
3125 *xy = 1;
3126 *regp = reg - REG_FR;
3128 else if (reg >= REG_BR && reg <= (REG_BR + 7))
3130 *xy = 2;
3131 *regp = reg - REG_BR;
3133 else
3134 as_bad (_("Operand %d to .%s must be a writable register"), n, po);
3137 static void
3138 dot_align (int arg)
3140 /* The current frag is an alignment frag. */
3141 align_frag = frag_now;
3142 s_align_bytes (arg);
3145 static void
3146 dot_radix (int dummy ATTRIBUTE_UNUSED)
3148 char *radix;
3149 int ch;
3151 SKIP_WHITESPACE ();
3153 if (is_it_end_of_statement ())
3154 return;
3155 ch = get_symbol_name (&radix);
3156 ia64_canonicalize_symbol_name (radix);
3157 if (strcasecmp (radix, "C"))
3158 as_bad (_("Radix `%s' unsupported or invalid"), radix);
3159 (void) restore_line_pointer (ch);
3160 demand_empty_rest_of_line ();
3163 /* Helper function for .loc directives. If the assembler is not generating
3164 line number info, then we need to remember which instructions have a .loc
3165 directive, and only call dwarf2_gen_line_info for those instructions. */
3167 static void
3168 dot_loc (int x)
3170 CURR_SLOT.loc_directive_seen = 1;
3171 dwarf2_directive_loc (x);
3174 /* .sbss, .srodata etc. are macros that expand into ".section SECNAME". */
3175 static void
3176 dot_special_section (int which)
3178 set_section ((char *) special_section_name[which]);
3181 /* Return -1 for warning and 0 for error. */
3183 static int
3184 unwind_diagnostic (const char * region, const char *directive)
3186 if (md.unwind_check == unwind_check_warning)
3188 as_warn (_(".%s outside of %s"), directive, region);
3189 return -1;
3191 else
3193 as_bad (_(".%s outside of %s"), directive, region);
3194 ignore_rest_of_line ();
3195 return 0;
3199 /* Return 1 if a directive is in a procedure, -1 if a directive isn't in
3200 a procedure but the unwind directive check is set to warning, 0 if
3201 a directive isn't in a procedure and the unwind directive check is set
3202 to error. */
3204 static int
3205 in_procedure (const char *directive)
3207 if (unwind.proc_pending.sym
3208 && (!unwind.saved_text_seg || strcmp (directive, "endp") == 0))
3209 return 1;
3210 return unwind_diagnostic ("procedure", directive);
3213 /* Return 1 if a directive is in a prologue, -1 if a directive isn't in
3214 a prologue but the unwind directive check is set to warning, 0 if
3215 a directive isn't in a prologue and the unwind directive check is set
3216 to error. */
3218 static int
3219 in_prologue (const char *directive)
3221 int in = in_procedure (directive);
3223 if (in > 0 && !unwind.prologue)
3224 in = unwind_diagnostic ("prologue", directive);
3225 check_pending_save ();
3226 return in;
3229 /* Return 1 if a directive is in a body, -1 if a directive isn't in
3230 a body but the unwind directive check is set to warning, 0 if
3231 a directive isn't in a body and the unwind directive check is set
3232 to error. */
3234 static int
3235 in_body (const char *directive)
3237 int in = in_procedure (directive);
3239 if (in > 0 && !unwind.body)
3240 in = unwind_diagnostic ("body region", directive);
3241 return in;
3244 static void
3245 add_unwind_entry (unw_rec_list *ptr, int sep)
3247 if (ptr)
3249 if (unwind.tail)
3250 unwind.tail->next = ptr;
3251 else
3252 unwind.list = ptr;
3253 unwind.tail = ptr;
3255 /* The current entry can in fact be a chain of unwind entries. */
3256 if (unwind.current_entry == NULL)
3257 unwind.current_entry = ptr;
3260 /* The current entry can in fact be a chain of unwind entries. */
3261 if (unwind.current_entry == NULL)
3262 unwind.current_entry = ptr;
3264 if (sep == ',')
3266 char *name;
3267 /* Parse a tag permitted for the current directive. */
3268 int ch;
3270 SKIP_WHITESPACE ();
3271 ch = get_symbol_name (&name);
3272 /* FIXME: For now, just issue a warning that this isn't implemented. */
3274 static int warned;
3276 if (!warned)
3278 warned = 1;
3279 as_warn (_("Tags on unwind pseudo-ops aren't supported, yet"));
3282 (void) restore_line_pointer (ch);
3284 if (sep != NOT_A_CHAR)
3285 demand_empty_rest_of_line ();
3288 static void
3289 dot_fframe (int dummy ATTRIBUTE_UNUSED)
3291 expressionS e;
3292 int sep;
3294 if (!in_prologue ("fframe"))
3295 return;
3297 sep = parse_operand_and_eval (&e, ',');
3299 if (e.X_op != O_constant)
3301 as_bad (_("First operand to .fframe must be a constant"));
3302 e.X_add_number = 0;
3304 add_unwind_entry (output_mem_stack_f (e.X_add_number), sep);
3307 static void
3308 dot_vframe (int dummy ATTRIBUTE_UNUSED)
3310 expressionS e;
3311 unsigned reg;
3312 int sep;
3314 if (!in_prologue ("vframe"))
3315 return;
3317 sep = parse_operand_and_eval (&e, ',');
3318 reg = e.X_add_number - REG_GR;
3319 if (e.X_op != O_register || reg > 127)
3321 as_bad (_("First operand to .vframe must be a general register"));
3322 reg = 0;
3324 add_unwind_entry (output_mem_stack_v (), sep);
3325 if (! (unwind.prologue_mask & 2))
3326 add_unwind_entry (output_psp_gr (reg), NOT_A_CHAR);
3327 else if (reg != unwind.prologue_gr
3328 + (unsigned) popcount (unwind.prologue_mask & -(2 << 1)))
3329 as_warn (_("Operand of .vframe contradicts .prologue"));
3332 static void
3333 dot_vframesp (int psp)
3335 expressionS e;
3336 int sep;
3338 if (psp)
3339 as_warn (_(".vframepsp is meaningless, assuming .vframesp was meant"));
3341 if (!in_prologue ("vframesp"))
3342 return;
3344 sep = parse_operand_and_eval (&e, ',');
3345 if (e.X_op != O_constant)
3347 as_bad (_("Operand to .vframesp must be a constant (sp-relative offset)"));
3348 e.X_add_number = 0;
3350 add_unwind_entry (output_mem_stack_v (), sep);
3351 add_unwind_entry (output_psp_sprel (e.X_add_number), NOT_A_CHAR);
3354 static void
3355 dot_save (int dummy ATTRIBUTE_UNUSED)
3357 expressionS e1, e2;
3358 unsigned reg1, reg2;
3359 int sep;
3361 if (!in_prologue ("save"))
3362 return;
3364 sep = parse_operand_and_eval (&e1, ',');
3365 if (sep == ',')
3366 sep = parse_operand_and_eval (&e2, ',');
3367 else
3368 e2.X_op = O_absent;
3370 reg1 = e1.X_add_number;
3371 /* Make sure it's a valid ar.xxx reg, OR its br0, aka 'rp'. */
3372 if (e1.X_op != O_register)
3374 as_bad (_("First operand to .save not a register"));
3375 reg1 = REG_PR; /* Anything valid is good here. */
3377 reg2 = e2.X_add_number - REG_GR;
3378 if (e2.X_op != O_register || reg2 > 127)
3380 as_bad (_("Second operand to .save not a valid register"));
3381 reg2 = 0;
3383 switch (reg1)
3385 case REG_AR + AR_BSP:
3386 add_unwind_entry (output_bsp_when (), sep);
3387 add_unwind_entry (output_bsp_gr (reg2), NOT_A_CHAR);
3388 break;
3389 case REG_AR + AR_BSPSTORE:
3390 add_unwind_entry (output_bspstore_when (), sep);
3391 add_unwind_entry (output_bspstore_gr (reg2), NOT_A_CHAR);
3392 break;
3393 case REG_AR + AR_RNAT:
3394 add_unwind_entry (output_rnat_when (), sep);
3395 add_unwind_entry (output_rnat_gr (reg2), NOT_A_CHAR);
3396 break;
3397 case REG_AR + AR_UNAT:
3398 add_unwind_entry (output_unat_when (), sep);
3399 add_unwind_entry (output_unat_gr (reg2), NOT_A_CHAR);
3400 break;
3401 case REG_AR + AR_FPSR:
3402 add_unwind_entry (output_fpsr_when (), sep);
3403 add_unwind_entry (output_fpsr_gr (reg2), NOT_A_CHAR);
3404 break;
3405 case REG_AR + AR_PFS:
3406 add_unwind_entry (output_pfs_when (), sep);
3407 if (! (unwind.prologue_mask & 4))
3408 add_unwind_entry (output_pfs_gr (reg2), NOT_A_CHAR);
3409 else if (reg2 != unwind.prologue_gr
3410 + (unsigned) popcount (unwind.prologue_mask & -(4 << 1)))
3411 as_warn (_("Second operand of .save contradicts .prologue"));
3412 break;
3413 case REG_AR + AR_LC:
3414 add_unwind_entry (output_lc_when (), sep);
3415 add_unwind_entry (output_lc_gr (reg2), NOT_A_CHAR);
3416 break;
3417 case REG_BR:
3418 add_unwind_entry (output_rp_when (), sep);
3419 if (! (unwind.prologue_mask & 8))
3420 add_unwind_entry (output_rp_gr (reg2), NOT_A_CHAR);
3421 else if (reg2 != unwind.prologue_gr)
3422 as_warn (_("Second operand of .save contradicts .prologue"));
3423 break;
3424 case REG_PR:
3425 add_unwind_entry (output_preds_when (), sep);
3426 if (! (unwind.prologue_mask & 1))
3427 add_unwind_entry (output_preds_gr (reg2), NOT_A_CHAR);
3428 else if (reg2 != unwind.prologue_gr
3429 + (unsigned) popcount (unwind.prologue_mask & -(1 << 1)))
3430 as_warn (_("Second operand of .save contradicts .prologue"));
3431 break;
3432 case REG_PRIUNAT:
3433 add_unwind_entry (output_priunat_when_gr (), sep);
3434 add_unwind_entry (output_priunat_gr (reg2), NOT_A_CHAR);
3435 break;
3436 default:
3437 as_bad (_("First operand to .save not a valid register"));
3438 add_unwind_entry (NULL, sep);
3439 break;
3443 static void
3444 dot_restore (int dummy ATTRIBUTE_UNUSED)
3446 expressionS e1;
3447 unsigned long ecount; /* # of _additional_ regions to pop */
3448 int sep;
3450 if (!in_body ("restore"))
3451 return;
3453 sep = parse_operand_and_eval (&e1, ',');
3454 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3455 as_bad (_("First operand to .restore must be stack pointer (sp)"));
3457 if (sep == ',')
3459 expressionS e2;
3461 sep = parse_operand_and_eval (&e2, ',');
3462 if (e2.X_op != O_constant || e2.X_add_number < 0)
3464 as_bad (_("Second operand to .restore must be a constant >= 0"));
3465 e2.X_add_number = 0;
3467 ecount = e2.X_add_number;
3469 else
3470 ecount = unwind.prologue_count - 1;
3472 if (ecount >= unwind.prologue_count)
3474 as_bad (_("Epilogue count of %lu exceeds number of nested prologues (%u)"),
3475 ecount + 1, unwind.prologue_count);
3476 ecount = 0;
3479 add_unwind_entry (output_epilogue (ecount), sep);
3481 if (ecount < unwind.prologue_count)
3482 unwind.prologue_count -= ecount + 1;
3483 else
3484 unwind.prologue_count = 0;
3487 static void
3488 dot_restorereg (int pred)
3490 unsigned int qp, ab, reg;
3491 expressionS e;
3492 int sep;
3493 const char * const po = pred ? "restorereg.p" : "restorereg";
3495 if (!in_procedure (po))
3496 return;
3498 if (pred)
3499 sep = parse_predicate_and_operand (&e, &qp, po);
3500 else
3502 sep = parse_operand_and_eval (&e, ',');
3503 qp = 0;
3505 convert_expr_to_ab_reg (&e, &ab, &reg, po, 1 + pred);
3507 add_unwind_entry (output_spill_reg (ab, reg, 0, 0, qp), sep);
3510 static const char *special_linkonce_name[] =
3512 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
3515 static void
3516 start_unwind_section (const segT text_seg, int sec_index)
3519 Use a slightly ugly scheme to derive the unwind section names from
3520 the text section name:
3522 text sect. unwind table sect.
3523 name: name: comments:
3524 ---------- ----------------- --------------------------------
3525 .text .IA_64.unwind
3526 .text.foo .IA_64.unwind.text.foo
3527 .foo .IA_64.unwind.foo
3528 .gnu.linkonce.t.foo
3529 .gnu.linkonce.ia64unw.foo
3530 _info .IA_64.unwind_info gas issues error message (ditto)
3531 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
3533 This mapping is done so that:
3535 (a) An object file with unwind info only in .text will use
3536 unwind section names .IA_64.unwind and .IA_64.unwind_info.
3537 This follows the letter of the ABI and also ensures backwards
3538 compatibility with older toolchains.
3540 (b) An object file with unwind info in multiple text sections
3541 will use separate unwind sections for each text section.
3542 This allows us to properly set the "sh_info" and "sh_link"
3543 fields in SHT_IA_64_UNWIND as required by the ABI and also
3544 lets GNU ld support programs with multiple segments
3545 containing unwind info (as might be the case for certain
3546 embedded applications).
3548 (c) An error is issued if there would be a name clash.
3551 const char *text_name, *sec_text_name;
3552 char *sec_name;
3553 const char *prefix = special_section_name [sec_index];
3554 const char *suffix;
3556 sec_text_name = segment_name (text_seg);
3557 text_name = sec_text_name;
3558 if (startswith (text_name, "_info"))
3560 as_bad (_("Illegal section name `%s' (causes unwind section name clash)"),
3561 text_name);
3562 ignore_rest_of_line ();
3563 return;
3565 if (strcmp (text_name, ".text") == 0)
3566 text_name = "";
3568 /* Build the unwind section name by appending the (possibly stripped)
3569 text section name to the unwind prefix. */
3570 suffix = text_name;
3571 if (startswith (text_name, ".gnu.linkonce.t."))
3573 prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND];
3574 suffix += sizeof (".gnu.linkonce.t.") - 1;
3577 sec_name = concat (prefix, suffix, NULL);
3579 /* Handle COMDAT group. */
3580 if ((text_seg->flags & SEC_LINK_ONCE) != 0
3581 && (elf_section_flags (text_seg) & SHF_GROUP) != 0)
3583 char *section;
3584 const char *group_name = elf_group_name (text_seg);
3586 if (group_name == NULL)
3588 as_bad (_("Group section `%s' has no group signature"),
3589 sec_text_name);
3590 ignore_rest_of_line ();
3591 free (sec_name);
3592 return;
3595 /* We have to construct a fake section directive. */
3596 section = concat (sec_name, ",\"aG\",@progbits,", group_name, ",comdat", NULL);
3597 set_section (section);
3598 free (section);
3600 else
3602 set_section (sec_name);
3603 bfd_set_section_flags (now_seg, SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3606 elf_linked_to_section (now_seg) = text_seg;
3607 free (sec_name);
3610 static void
3611 generate_unwind_image (const segT text_seg)
3613 int size, pad;
3614 unw_rec_list *list;
3616 /* Mark the end of the unwind info, so that we can compute the size of the
3617 last unwind region. */
3618 add_unwind_entry (output_endp (), NOT_A_CHAR);
3620 /* Force out pending instructions, to make sure all unwind records have
3621 a valid slot_number field. */
3622 ia64_flush_insns ();
3624 /* Generate the unwind record. */
3625 list = optimize_unw_records (unwind.list);
3626 fixup_unw_records (list, 1);
3627 size = calc_record_size (list);
3629 if (size > 0 || unwind.force_unwind_entry)
3631 unwind.force_unwind_entry = 0;
3632 /* pad to pointer-size boundary. */
3633 pad = size % md.pointer_size;
3634 if (pad != 0)
3635 size += md.pointer_size - pad;
3636 /* Add 8 for the header. */
3637 size += 8;
3638 /* Add a pointer for the personality offset. */
3639 if (unwind.personality_routine)
3640 size += md.pointer_size;
3643 /* If there are unwind records, switch sections, and output the info. */
3644 if (size != 0)
3646 expressionS exp;
3647 bfd_reloc_code_real_type reloc;
3649 start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO);
3651 /* Make sure the section has 4 byte alignment for ILP32 and
3652 8 byte alignment for LP64. */
3653 frag_align (md.pointer_size_shift, 0, 0);
3654 record_alignment (now_seg, md.pointer_size_shift);
3656 /* Set expression which points to start of unwind descriptor area. */
3657 unwind.info = expr_build_dot ();
3659 frag_var (rs_machine_dependent, size, size, 0, 0,
3660 (offsetT) (long) unwind.personality_routine,
3661 (char *) list);
3663 /* Add the personality address to the image. */
3664 if (unwind.personality_routine != 0)
3666 exp.X_op = O_symbol;
3667 exp.X_add_symbol = unwind.personality_routine;
3668 exp.X_add_number = 0;
3670 if (md.flags & EF_IA_64_BE)
3672 if (md.flags & EF_IA_64_ABI64)
3673 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3674 else
3675 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3677 else
3679 if (md.flags & EF_IA_64_ABI64)
3680 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3681 else
3682 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3685 fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3686 md.pointer_size, &exp, 0, reloc);
3687 unwind.personality_routine = 0;
3691 free_saved_prologue_counts ();
3692 unwind.list = unwind.tail = unwind.current_entry = NULL;
3695 static void
3696 dot_handlerdata (int dummy ATTRIBUTE_UNUSED)
3698 if (!in_procedure ("handlerdata"))
3699 return;
3700 unwind.force_unwind_entry = 1;
3702 /* Remember which segment we're in so we can switch back after .endp */
3703 unwind.saved_text_seg = now_seg;
3704 unwind.saved_text_subseg = now_subseg;
3706 /* Generate unwind info into unwind-info section and then leave that
3707 section as the currently active one so dataXX directives go into
3708 the language specific data area of the unwind info block. */
3709 generate_unwind_image (now_seg);
3710 demand_empty_rest_of_line ();
3713 static void
3714 dot_unwentry (int dummy ATTRIBUTE_UNUSED)
3716 if (!in_procedure ("unwentry"))
3717 return;
3718 unwind.force_unwind_entry = 1;
3719 demand_empty_rest_of_line ();
3722 static void
3723 dot_altrp (int dummy ATTRIBUTE_UNUSED)
3725 expressionS e;
3726 unsigned reg;
3728 if (!in_prologue ("altrp"))
3729 return;
3731 parse_operand_and_eval (&e, 0);
3732 reg = e.X_add_number - REG_BR;
3733 if (e.X_op != O_register || reg > 7)
3735 as_bad (_("First operand to .altrp not a valid branch register"));
3736 reg = 0;
3738 add_unwind_entry (output_rp_br (reg), 0);
3741 static void
3742 dot_savemem (int psprel)
3744 expressionS e1, e2;
3745 int sep;
3746 int reg1, val;
3747 const char * const po = psprel ? "savepsp" : "savesp";
3749 if (!in_prologue (po))
3750 return;
3752 sep = parse_operand_and_eval (&e1, ',');
3753 if (sep == ',')
3754 sep = parse_operand_and_eval (&e2, ',');
3755 else
3756 e2.X_op = O_absent;
3758 reg1 = e1.X_add_number;
3759 val = e2.X_add_number;
3761 /* Make sure it's a valid ar.xxx reg, OR its br0, aka 'rp'. */
3762 if (e1.X_op != O_register)
3764 as_bad (_("First operand to .%s not a register"), po);
3765 reg1 = REG_PR; /* Anything valid is good here. */
3767 if (e2.X_op != O_constant)
3769 as_bad (_("Second operand to .%s not a constant"), po);
3770 val = 0;
3773 switch (reg1)
3775 case REG_AR + AR_BSP:
3776 add_unwind_entry (output_bsp_when (), sep);
3777 add_unwind_entry ((psprel
3778 ? output_bsp_psprel
3779 : output_bsp_sprel) (val), NOT_A_CHAR);
3780 break;
3781 case REG_AR + AR_BSPSTORE:
3782 add_unwind_entry (output_bspstore_when (), sep);
3783 add_unwind_entry ((psprel
3784 ? output_bspstore_psprel
3785 : output_bspstore_sprel) (val), NOT_A_CHAR);
3786 break;
3787 case REG_AR + AR_RNAT:
3788 add_unwind_entry (output_rnat_when (), sep);
3789 add_unwind_entry ((psprel
3790 ? output_rnat_psprel
3791 : output_rnat_sprel) (val), NOT_A_CHAR);
3792 break;
3793 case REG_AR + AR_UNAT:
3794 add_unwind_entry (output_unat_when (), sep);
3795 add_unwind_entry ((psprel
3796 ? output_unat_psprel
3797 : output_unat_sprel) (val), NOT_A_CHAR);
3798 break;
3799 case REG_AR + AR_FPSR:
3800 add_unwind_entry (output_fpsr_when (), sep);
3801 add_unwind_entry ((psprel
3802 ? output_fpsr_psprel
3803 : output_fpsr_sprel) (val), NOT_A_CHAR);
3804 break;
3805 case REG_AR + AR_PFS:
3806 add_unwind_entry (output_pfs_when (), sep);
3807 add_unwind_entry ((psprel
3808 ? output_pfs_psprel
3809 : output_pfs_sprel) (val), NOT_A_CHAR);
3810 break;
3811 case REG_AR + AR_LC:
3812 add_unwind_entry (output_lc_when (), sep);
3813 add_unwind_entry ((psprel
3814 ? output_lc_psprel
3815 : output_lc_sprel) (val), NOT_A_CHAR);
3816 break;
3817 case REG_BR:
3818 add_unwind_entry (output_rp_when (), sep);
3819 add_unwind_entry ((psprel
3820 ? output_rp_psprel
3821 : output_rp_sprel) (val), NOT_A_CHAR);
3822 break;
3823 case REG_PR:
3824 add_unwind_entry (output_preds_when (), sep);
3825 add_unwind_entry ((psprel
3826 ? output_preds_psprel
3827 : output_preds_sprel) (val), NOT_A_CHAR);
3828 break;
3829 case REG_PRIUNAT:
3830 add_unwind_entry (output_priunat_when_mem (), sep);
3831 add_unwind_entry ((psprel
3832 ? output_priunat_psprel
3833 : output_priunat_sprel) (val), NOT_A_CHAR);
3834 break;
3835 default:
3836 as_bad (_("First operand to .%s not a valid register"), po);
3837 add_unwind_entry (NULL, sep);
3838 break;
3842 static void
3843 dot_saveg (int dummy ATTRIBUTE_UNUSED)
3845 expressionS e;
3846 unsigned grmask;
3847 int sep;
3849 if (!in_prologue ("save.g"))
3850 return;
3852 sep = parse_operand_and_eval (&e, ',');
3854 grmask = e.X_add_number;
3855 if (e.X_op != O_constant
3856 || e.X_add_number <= 0
3857 || e.X_add_number > 0xf)
3859 as_bad (_("First operand to .save.g must be a positive 4-bit constant"));
3860 grmask = 0;
3863 if (sep == ',')
3865 unsigned reg;
3866 int n = popcount (grmask);
3868 parse_operand_and_eval (&e, 0);
3869 reg = e.X_add_number - REG_GR;
3870 if (e.X_op != O_register || reg > 127)
3872 as_bad (_("Second operand to .save.g must be a general register"));
3873 reg = 0;
3875 else if (reg > 128U - n)
3877 as_bad (_("Second operand to .save.g must be the first of %d general registers"), n);
3878 reg = 0;
3880 add_unwind_entry (output_gr_gr (grmask, reg), 0);
3882 else
3883 add_unwind_entry (output_gr_mem (grmask), 0);
3886 static void
3887 dot_savef (int dummy ATTRIBUTE_UNUSED)
3889 expressionS e;
3891 if (!in_prologue ("save.f"))
3892 return;
3894 parse_operand_and_eval (&e, 0);
3896 if (e.X_op != O_constant
3897 || e.X_add_number <= 0
3898 || e.X_add_number > 0xfffff)
3900 as_bad (_("Operand to .save.f must be a positive 20-bit constant"));
3901 e.X_add_number = 0;
3903 add_unwind_entry (output_fr_mem (e.X_add_number), 0);
3906 static void
3907 dot_saveb (int dummy ATTRIBUTE_UNUSED)
3909 expressionS e;
3910 unsigned brmask;
3911 int sep;
3913 if (!in_prologue ("save.b"))
3914 return;
3916 sep = parse_operand_and_eval (&e, ',');
3918 brmask = e.X_add_number;
3919 if (e.X_op != O_constant
3920 || e.X_add_number <= 0
3921 || e.X_add_number > 0x1f)
3923 as_bad (_("First operand to .save.b must be a positive 5-bit constant"));
3924 brmask = 0;
3927 if (sep == ',')
3929 unsigned reg;
3930 int n = popcount (brmask);
3932 parse_operand_and_eval (&e, 0);
3933 reg = e.X_add_number - REG_GR;
3934 if (e.X_op != O_register || reg > 127)
3936 as_bad (_("Second operand to .save.b must be a general register"));
3937 reg = 0;
3939 else if (reg > 128U - n)
3941 as_bad (_("Second operand to .save.b must be the first of %d general registers"), n);
3942 reg = 0;
3944 add_unwind_entry (output_br_gr (brmask, reg), 0);
3946 else
3947 add_unwind_entry (output_br_mem (brmask), 0);
3950 static void
3951 dot_savegf (int dummy ATTRIBUTE_UNUSED)
3953 expressionS e1, e2;
3955 if (!in_prologue ("save.gf"))
3956 return;
3958 if (parse_operand_and_eval (&e1, ',') == ',')
3959 parse_operand_and_eval (&e2, 0);
3960 else
3961 e2.X_op = O_absent;
3963 if (e1.X_op != O_constant
3964 || e1.X_add_number < 0
3965 || e1.X_add_number > 0xf)
3967 as_bad (_("First operand to .save.gf must be a non-negative 4-bit constant"));
3968 e1.X_op = O_absent;
3969 e1.X_add_number = 0;
3971 if (e2.X_op != O_constant
3972 || e2.X_add_number < 0
3973 || e2.X_add_number > 0xfffff)
3975 as_bad (_("Second operand to .save.gf must be a non-negative 20-bit constant"));
3976 e2.X_op = O_absent;
3977 e2.X_add_number = 0;
3979 if (e1.X_op == O_constant
3980 && e2.X_op == O_constant
3981 && e1.X_add_number == 0
3982 && e2.X_add_number == 0)
3983 as_bad (_("Operands to .save.gf may not be both zero"));
3985 add_unwind_entry (output_frgr_mem (e1.X_add_number, e2.X_add_number), 0);
3988 static void
3989 dot_spill (int dummy ATTRIBUTE_UNUSED)
3991 expressionS e;
3993 if (!in_prologue ("spill"))
3994 return;
3996 parse_operand_and_eval (&e, 0);
3998 if (e.X_op != O_constant)
4000 as_bad (_("Operand to .spill must be a constant"));
4001 e.X_add_number = 0;
4003 add_unwind_entry (output_spill_base (e.X_add_number), 0);
4006 static void
4007 dot_spillreg (int pred)
4009 int sep;
4010 unsigned int qp, ab, xy, reg, treg;
4011 expressionS e;
4012 const char * const po = pred ? "spillreg.p" : "spillreg";
4014 if (!in_procedure (po))
4015 return;
4017 if (pred)
4018 sep = parse_predicate_and_operand (&e, &qp, po);
4019 else
4021 sep = parse_operand_and_eval (&e, ',');
4022 qp = 0;
4024 convert_expr_to_ab_reg (&e, &ab, &reg, po, 1 + pred);
4026 if (sep == ',')
4027 sep = parse_operand_and_eval (&e, ',');
4028 else
4029 e.X_op = O_absent;
4030 convert_expr_to_xy_reg (&e, &xy, &treg, po, 2 + pred);
4032 add_unwind_entry (output_spill_reg (ab, reg, treg, xy, qp), sep);
4035 static void
4036 dot_spillmem (int psprel)
4038 expressionS e;
4039 int pred = (psprel < 0), sep;
4040 unsigned int qp, ab, reg;
4041 const char * po;
4043 if (pred)
4045 psprel = ~psprel;
4046 po = psprel ? "spillpsp.p" : "spillsp.p";
4048 else
4049 po = psprel ? "spillpsp" : "spillsp";
4051 if (!in_procedure (po))
4052 return;
4054 if (pred)
4055 sep = parse_predicate_and_operand (&e, &qp, po);
4056 else
4058 sep = parse_operand_and_eval (&e, ',');
4059 qp = 0;
4061 convert_expr_to_ab_reg (&e, &ab, &reg, po, 1 + pred);
4063 if (sep == ',')
4064 sep = parse_operand_and_eval (&e, ',');
4065 else
4066 e.X_op = O_absent;
4067 if (e.X_op != O_constant)
4069 as_bad (_("Operand %d to .%s must be a constant"), 2 + pred, po);
4070 e.X_add_number = 0;
4073 if (psprel)
4074 add_unwind_entry (output_spill_psprel (ab, reg, e.X_add_number, qp), sep);
4075 else
4076 add_unwind_entry (output_spill_sprel (ab, reg, e.X_add_number, qp), sep);
4079 static unsigned int
4080 get_saved_prologue_count (unsigned long lbl)
4082 label_prologue_count *lpc = unwind.saved_prologue_counts;
4084 while (lpc != NULL && lpc->label_number != lbl)
4085 lpc = lpc->next;
4087 if (lpc != NULL)
4088 return lpc->prologue_count;
4090 as_bad (_("Missing .label_state %ld"), lbl);
4091 return 1;
4094 static void
4095 save_prologue_count (unsigned long lbl, unsigned int count)
4097 label_prologue_count *lpc = unwind.saved_prologue_counts;
4099 while (lpc != NULL && lpc->label_number != lbl)
4100 lpc = lpc->next;
4102 if (lpc != NULL)
4103 lpc->prologue_count = count;
4104 else
4106 label_prologue_count *new_lpc = XNEW (label_prologue_count);
4108 new_lpc->next = unwind.saved_prologue_counts;
4109 new_lpc->label_number = lbl;
4110 new_lpc->prologue_count = count;
4111 unwind.saved_prologue_counts = new_lpc;
4115 static void
4116 free_saved_prologue_counts (void)
4118 label_prologue_count *lpc = unwind.saved_prologue_counts;
4119 label_prologue_count *next;
4121 while (lpc != NULL)
4123 next = lpc->next;
4124 free (lpc);
4125 lpc = next;
4128 unwind.saved_prologue_counts = NULL;
4131 static void
4132 dot_label_state (int dummy ATTRIBUTE_UNUSED)
4134 expressionS e;
4136 if (!in_body ("label_state"))
4137 return;
4139 parse_operand_and_eval (&e, 0);
4140 if (e.X_op == O_constant)
4141 save_prologue_count (e.X_add_number, unwind.prologue_count);
4142 else
4144 as_bad (_("Operand to .label_state must be a constant"));
4145 e.X_add_number = 0;
4147 add_unwind_entry (output_label_state (e.X_add_number), 0);
4150 static void
4151 dot_copy_state (int dummy ATTRIBUTE_UNUSED)
4153 expressionS e;
4155 if (!in_body ("copy_state"))
4156 return;
4158 parse_operand_and_eval (&e, 0);
4159 if (e.X_op == O_constant)
4160 unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
4161 else
4163 as_bad (_("Operand to .copy_state must be a constant"));
4164 e.X_add_number = 0;
4166 add_unwind_entry (output_copy_state (e.X_add_number), 0);
4169 static void
4170 dot_unwabi (int dummy ATTRIBUTE_UNUSED)
4172 expressionS e1, e2;
4173 unsigned char sep;
4175 if (!in_prologue ("unwabi"))
4176 return;
4178 sep = parse_operand_and_eval (&e1, ',');
4179 if (sep == ',')
4180 parse_operand_and_eval (&e2, 0);
4181 else
4182 e2.X_op = O_absent;
4184 if (e1.X_op != O_constant)
4186 as_bad (_("First operand to .unwabi must be a constant"));
4187 e1.X_add_number = 0;
4190 if (e2.X_op != O_constant)
4192 as_bad (_("Second operand to .unwabi must be a constant"));
4193 e2.X_add_number = 0;
4196 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number), 0);
4199 static void
4200 dot_personality (int dummy ATTRIBUTE_UNUSED)
4202 char *name, c;
4204 if (!in_procedure ("personality"))
4205 return;
4206 SKIP_WHITESPACE ();
4207 c = get_symbol_name (&name);
4208 unwind.personality_routine = symbol_find_or_make (name);
4209 unwind.force_unwind_entry = 1;
4210 restore_line_pointer (c);
4211 SKIP_WHITESPACE ();
4212 demand_empty_rest_of_line ();
4215 static void
4216 dot_proc (int dummy ATTRIBUTE_UNUSED)
4218 char *name, c;
4219 symbolS *sym;
4220 proc_pending *pending, *last_pending;
4222 if (unwind.proc_pending.sym)
4224 (md.unwind_check == unwind_check_warning
4225 ? as_warn
4226 : as_bad) (_("Missing .endp after previous .proc"));
4227 while (unwind.proc_pending.next)
4229 pending = unwind.proc_pending.next;
4230 unwind.proc_pending.next = pending->next;
4231 free (pending);
4234 last_pending = NULL;
4236 /* Parse names of main and alternate entry points and mark them as
4237 function symbols: */
4238 while (1)
4240 SKIP_WHITESPACE ();
4241 c = get_symbol_name (&name);
4242 if (!*name)
4243 as_bad (_("Empty argument of .proc"));
4244 else
4246 sym = symbol_find_or_make (name);
4247 if (S_IS_DEFINED (sym))
4248 as_bad (_("`%s' was already defined"), name);
4249 else if (!last_pending)
4251 unwind.proc_pending.sym = sym;
4252 last_pending = &unwind.proc_pending;
4254 else
4256 pending = XNEW (proc_pending);
4257 pending->sym = sym;
4258 last_pending = last_pending->next = pending;
4260 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
4262 restore_line_pointer (c);
4263 SKIP_WHITESPACE ();
4264 if (*input_line_pointer != ',')
4265 break;
4266 ++input_line_pointer;
4268 if (!last_pending)
4270 unwind.proc_pending.sym = expr_build_dot ();
4271 last_pending = &unwind.proc_pending;
4273 last_pending->next = NULL;
4274 demand_empty_rest_of_line ();
4275 do_align (4, NULL, 0, 0);
4277 unwind.prologue = 0;
4278 unwind.prologue_count = 0;
4279 unwind.body = 0;
4280 unwind.insn = 0;
4281 unwind.list = unwind.tail = unwind.current_entry = NULL;
4282 unwind.personality_routine = 0;
4285 static void
4286 dot_body (int dummy ATTRIBUTE_UNUSED)
4288 if (!in_procedure ("body"))
4289 return;
4290 if (!unwind.prologue && !unwind.body && unwind.insn)
4291 as_warn (_("Initial .body should precede any instructions"));
4292 check_pending_save ();
4294 unwind.prologue = 0;
4295 unwind.prologue_mask = 0;
4296 unwind.body = 1;
4298 add_unwind_entry (output_body (), 0);
4301 static void
4302 dot_prologue (int dummy ATTRIBUTE_UNUSED)
4304 unsigned mask = 0, grsave = 0;
4306 if (!in_procedure ("prologue"))
4307 return;
4308 if (unwind.prologue)
4310 as_bad (_(".prologue within prologue"));
4311 ignore_rest_of_line ();
4312 return;
4314 if (!unwind.body && unwind.insn)
4315 as_warn (_("Initial .prologue should precede any instructions"));
4317 if (!is_it_end_of_statement ())
4319 expressionS e;
4320 int n, sep = parse_operand_and_eval (&e, ',');
4322 if (e.X_op != O_constant
4323 || e.X_add_number < 0
4324 || e.X_add_number > 0xf)
4325 as_bad (_("First operand to .prologue must be a positive 4-bit constant"));
4326 else if (e.X_add_number == 0)
4327 as_warn (_("Pointless use of zero first operand to .prologue"));
4328 else
4329 mask = e.X_add_number;
4331 n = popcount (mask);
4333 if (sep == ',')
4334 parse_operand_and_eval (&e, 0);
4335 else
4336 e.X_op = O_absent;
4338 if (e.X_op == O_constant
4339 && e.X_add_number >= 0
4340 && e.X_add_number < 128)
4342 if (md.unwind_check == unwind_check_error)
4343 as_warn (_("Using a constant as second operand to .prologue is deprecated"));
4344 grsave = e.X_add_number;
4346 else if (e.X_op != O_register
4347 || (grsave = e.X_add_number - REG_GR) > 127)
4349 as_bad (_("Second operand to .prologue must be a general register"));
4350 grsave = 0;
4352 else if (grsave > 128U - n)
4354 as_bad (_("Second operand to .prologue must be the first of %d general registers"), n);
4355 grsave = 0;
4359 if (mask)
4360 add_unwind_entry (output_prologue_gr (mask, grsave), 0);
4361 else
4362 add_unwind_entry (output_prologue (), 0);
4364 unwind.prologue = 1;
4365 unwind.prologue_mask = mask;
4366 unwind.prologue_gr = grsave;
4367 unwind.body = 0;
4368 ++unwind.prologue_count;
4371 static void
4372 dot_endp (int dummy ATTRIBUTE_UNUSED)
4374 expressionS e;
4375 int bytes_per_address;
4376 long where;
4377 segT saved_seg;
4378 subsegT saved_subseg;
4379 proc_pending *pending;
4380 int unwind_check = md.unwind_check;
4382 md.unwind_check = unwind_check_error;
4383 if (!in_procedure ("endp"))
4384 return;
4385 md.unwind_check = unwind_check;
4387 if (unwind.saved_text_seg)
4389 saved_seg = unwind.saved_text_seg;
4390 saved_subseg = unwind.saved_text_subseg;
4391 unwind.saved_text_seg = NULL;
4393 else
4395 saved_seg = now_seg;
4396 saved_subseg = now_subseg;
4399 insn_group_break (1, 0, 0);
4401 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
4402 if (!unwind.info)
4403 generate_unwind_image (saved_seg);
4405 if (unwind.info || unwind.force_unwind_entry)
4407 symbolS *proc_end;
4409 subseg_set (md.last_text_seg, md.last_text_subseg);
4410 proc_end = expr_build_dot ();
4412 start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND);
4414 /* Make sure that section has 4 byte alignment for ILP32 and
4415 8 byte alignment for LP64. */
4416 record_alignment (now_seg, md.pointer_size_shift);
4418 /* Need space for 3 pointers for procedure start, procedure end,
4419 and unwind info. */
4420 memset (frag_more (3 * md.pointer_size), 0, 3 * md.pointer_size);
4421 where = frag_now_fix () - (3 * md.pointer_size);
4422 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4424 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
4425 e.X_op = O_pseudo_fixup;
4426 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4427 e.X_add_number = 0;
4428 if (!S_IS_LOCAL (unwind.proc_pending.sym)
4429 && S_IS_DEFINED (unwind.proc_pending.sym))
4430 e.X_add_symbol
4431 = symbol_temp_new (S_GET_SEGMENT (unwind.proc_pending.sym),
4432 symbol_get_frag (unwind.proc_pending.sym),
4433 S_GET_VALUE (unwind.proc_pending.sym));
4434 else
4435 e.X_add_symbol = unwind.proc_pending.sym;
4436 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e,
4437 BFD_RELOC_NONE);
4439 e.X_op = O_pseudo_fixup;
4440 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4441 e.X_add_number = 0;
4442 e.X_add_symbol = proc_end;
4443 ia64_cons_fix_new (frag_now, where + bytes_per_address,
4444 bytes_per_address, &e, BFD_RELOC_NONE);
4446 if (unwind.info)
4448 e.X_op = O_pseudo_fixup;
4449 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4450 e.X_add_number = 0;
4451 e.X_add_symbol = unwind.info;
4452 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4453 bytes_per_address, &e, BFD_RELOC_NONE);
4456 subseg_set (saved_seg, saved_subseg);
4458 /* Set symbol sizes. */
4459 pending = &unwind.proc_pending;
4460 if (S_GET_NAME (pending->sym))
4464 symbolS *sym = pending->sym;
4466 if (!S_IS_DEFINED (sym))
4467 as_bad (_("`%s' was not defined within procedure"), S_GET_NAME (sym));
4468 else if (S_GET_SIZE (sym) == 0
4469 && symbol_get_obj (sym)->size == NULL)
4471 fragS *frag = symbol_get_frag (sym);
4473 if (frag)
4475 if (frag == frag_now && SEG_NORMAL (now_seg))
4476 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4477 else
4479 symbol_get_obj (sym)->size = XNEW (expressionS);
4480 symbol_get_obj (sym)->size->X_op = O_subtract;
4481 symbol_get_obj (sym)->size->X_add_symbol
4482 = symbol_new (FAKE_LABEL_NAME, now_seg,
4483 frag_now, frag_now_fix ());
4484 symbol_get_obj (sym)->size->X_op_symbol = sym;
4485 symbol_get_obj (sym)->size->X_add_number = 0;
4489 } while ((pending = pending->next) != NULL);
4492 /* Parse names of main and alternate entry points. */
4493 while (1)
4495 char *name, c;
4497 SKIP_WHITESPACE ();
4498 c = get_symbol_name (&name);
4499 if (!*name)
4500 (md.unwind_check == unwind_check_warning
4501 ? as_warn
4502 : as_bad) (_("Empty argument of .endp"));
4503 else
4505 symbolS *sym = symbol_find (name);
4507 for (pending = &unwind.proc_pending; pending; pending = pending->next)
4509 if (sym == pending->sym)
4511 pending->sym = NULL;
4512 break;
4515 if (!sym || !pending)
4516 as_warn (_("`%s' was not specified with previous .proc"), name);
4518 restore_line_pointer (c);
4519 SKIP_WHITESPACE ();
4520 if (*input_line_pointer != ',')
4521 break;
4522 ++input_line_pointer;
4524 demand_empty_rest_of_line ();
4526 /* Deliberately only checking for the main entry point here; the
4527 language spec even says all arguments to .endp are ignored. */
4528 if (unwind.proc_pending.sym
4529 && S_GET_NAME (unwind.proc_pending.sym)
4530 && strcmp (S_GET_NAME (unwind.proc_pending.sym), FAKE_LABEL_NAME))
4531 as_warn (_("`%s' should be an operand to this .endp"),
4532 S_GET_NAME (unwind.proc_pending.sym));
4533 while (unwind.proc_pending.next)
4535 pending = unwind.proc_pending.next;
4536 unwind.proc_pending.next = pending->next;
4537 free (pending);
4539 unwind.proc_pending.sym = unwind.info = NULL;
4542 static void
4543 dot_template (int template_val)
4545 CURR_SLOT.user_template = template_val;
4548 static void
4549 dot_regstk (int dummy ATTRIBUTE_UNUSED)
4551 int ins, locs, outs, rots;
4553 if (is_it_end_of_statement ())
4554 ins = locs = outs = rots = 0;
4555 else
4557 ins = get_absolute_expression ();
4558 if (*input_line_pointer++ != ',')
4559 goto err;
4560 locs = get_absolute_expression ();
4561 if (*input_line_pointer++ != ',')
4562 goto err;
4563 outs = get_absolute_expression ();
4564 if (*input_line_pointer++ != ',')
4565 goto err;
4566 rots = get_absolute_expression ();
4568 set_regstack (ins, locs, outs, rots);
4569 return;
4571 err:
4572 as_bad (_("Comma expected"));
4573 ignore_rest_of_line ();
4576 static void
4577 dot_rot (int type)
4579 offsetT num_regs;
4580 valueT num_alloced = 0;
4581 struct dynreg **drpp, *dr;
4582 int ch, base_reg = 0;
4583 char *name, *start;
4584 size_t len;
4586 switch (type)
4588 case DYNREG_GR: base_reg = REG_GR + 32; break;
4589 case DYNREG_FR: base_reg = REG_FR + 32; break;
4590 case DYNREG_PR: base_reg = REG_P + 16; break;
4591 default: break;
4594 /* First, remove existing names from hash table. */
4595 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4597 str_hash_delete (md.dynreg_hash, dr->name);
4598 /* FIXME: Free dr->name. */
4599 dr->num_regs = 0;
4602 drpp = &md.dynreg[type];
4603 while (1)
4605 ch = get_symbol_name (&start);
4606 len = strlen (ia64_canonicalize_symbol_name (start));
4607 restore_line_pointer (ch);
4609 SKIP_WHITESPACE ();
4610 if (*input_line_pointer != '[')
4612 as_bad (_("Expected '['"));
4613 goto err;
4615 ++input_line_pointer; /* skip '[' */
4617 num_regs = get_absolute_expression ();
4619 if (*input_line_pointer++ != ']')
4621 as_bad (_("Expected ']'"));
4622 goto err;
4624 if (num_regs <= 0)
4626 as_bad (_("Number of elements must be positive"));
4627 goto err;
4629 SKIP_WHITESPACE ();
4631 num_alloced += num_regs;
4632 switch (type)
4634 case DYNREG_GR:
4635 if (num_alloced > md.rot.num_regs)
4637 as_bad (_("Used more than the declared %d rotating registers"),
4638 md.rot.num_regs);
4639 goto err;
4641 break;
4642 case DYNREG_FR:
4643 if (num_alloced > 96)
4645 as_bad (_("Used more than the available 96 rotating registers"));
4646 goto err;
4648 break;
4649 case DYNREG_PR:
4650 if (num_alloced > 48)
4652 as_bad (_("Used more than the available 48 rotating registers"));
4653 goto err;
4655 break;
4657 default:
4658 break;
4661 if (!*drpp)
4662 *drpp = notes_calloc (1, sizeof (**drpp));
4664 name = notes_memdup (start, len, len + 1);
4666 dr = *drpp;
4667 dr->name = name;
4668 dr->num_regs = num_regs;
4669 dr->base = base_reg;
4670 drpp = &dr->next;
4671 base_reg += num_regs;
4673 if (str_hash_insert (md.dynreg_hash, name, dr, 0) != NULL)
4675 as_bad (_("Attempt to redefine register set `%s'"), name);
4676 goto err;
4679 if (*input_line_pointer != ',')
4680 break;
4681 ++input_line_pointer; /* skip comma */
4682 SKIP_WHITESPACE ();
4684 demand_empty_rest_of_line ();
4685 return;
4687 err:
4688 ignore_rest_of_line ();
4691 static void
4692 dot_byteorder (int byteorder)
4694 segment_info_type *seginfo = seg_info (now_seg);
4696 if (byteorder == -1)
4698 if (seginfo->tc_segment_info_data.endian == 0)
4699 seginfo->tc_segment_info_data.endian = default_big_endian ? 1 : 2;
4700 byteorder = seginfo->tc_segment_info_data.endian == 1;
4702 else
4703 seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2;
4705 if (target_big_endian != byteorder)
4707 target_big_endian = byteorder;
4708 if (target_big_endian)
4710 ia64_number_to_chars = number_to_chars_bigendian;
4711 ia64_float_to_chars = ia64_float_to_chars_bigendian;
4713 else
4715 ia64_number_to_chars = number_to_chars_littleendian;
4716 ia64_float_to_chars = ia64_float_to_chars_littleendian;
4721 static void
4722 dot_psr (int dummy ATTRIBUTE_UNUSED)
4724 char *option;
4725 int ch;
4727 while (1)
4729 ch = get_symbol_name (&option);
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 restore_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 (int dummy ATTRIBUTE_UNUSED)
4755 new_logical_line (0, get_absolute_expression ());
4756 demand_empty_rest_of_line ();
4759 static void
4760 cross_section (int ref, void (*builder) (int), int ua)
4762 char *start, *end;
4763 int saved_auto_align;
4764 unsigned int section_count;
4765 const char *name;
4767 start = input_line_pointer;
4768 name = obj_elf_section_name ();
4769 if (name == NULL)
4770 return;
4771 end = input_line_pointer;
4772 if (*input_line_pointer != ',')
4774 as_bad (_("Comma expected after section name"));
4775 ignore_rest_of_line ();
4776 return;
4778 *end = '\0';
4779 end = input_line_pointer + 1; /* skip comma */
4780 input_line_pointer = start;
4781 md.keep_pending_output = 1;
4782 section_count = bfd_count_sections (stdoutput);
4783 obj_elf_section (0);
4784 if (section_count != bfd_count_sections (stdoutput))
4785 as_warn (_("Creating sections with .xdataN/.xrealN/.xstringZ is deprecated."));
4786 input_line_pointer = end;
4787 saved_auto_align = md.auto_align;
4788 if (ua)
4789 md.auto_align = 0;
4790 (*builder) (ref);
4791 if (ua)
4792 md.auto_align = saved_auto_align;
4793 obj_elf_previous (0);
4794 md.keep_pending_output = 0;
4797 static void
4798 dot_xdata (int size)
4800 cross_section (size, cons, 0);
4803 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4805 static void
4806 stmt_float_cons (int kind)
4808 size_t alignment;
4810 switch (kind)
4812 case 'd':
4813 alignment = 3;
4814 break;
4816 case 'x':
4817 case 'X':
4818 alignment = 4;
4819 break;
4821 case 'f':
4822 default:
4823 alignment = 2;
4824 break;
4826 do_align (alignment, NULL, 0, 0);
4827 float_cons (kind);
4830 static void
4831 stmt_cons_ua (int size)
4833 int saved_auto_align = md.auto_align;
4835 md.auto_align = 0;
4836 cons (size);
4837 md.auto_align = saved_auto_align;
4840 static void
4841 dot_xfloat_cons (int kind)
4843 cross_section (kind, stmt_float_cons, 0);
4846 static void
4847 dot_xstringer (int zero)
4849 cross_section (zero, stringer, 0);
4852 static void
4853 dot_xdata_ua (int size)
4855 cross_section (size, cons, 1);
4858 static void
4859 dot_xfloat_cons_ua (int kind)
4861 cross_section (kind, float_cons, 1);
4864 /* .reg.val <regname>,value */
4866 static void
4867 dot_reg_val (int dummy ATTRIBUTE_UNUSED)
4869 expressionS reg;
4871 expression_and_evaluate (&reg);
4872 if (reg.X_op != O_register)
4874 as_bad (_("Register name expected"));
4875 ignore_rest_of_line ();
4877 else if (*input_line_pointer++ != ',')
4879 as_bad (_("Comma expected"));
4880 ignore_rest_of_line ();
4882 else
4884 valueT value = get_absolute_expression ();
4885 int regno = reg.X_add_number;
4886 if (regno <= REG_GR || regno > REG_GR + 127)
4887 as_warn (_("Register value annotation ignored"));
4888 else
4890 gr_values[regno - REG_GR].known = 1;
4891 gr_values[regno - REG_GR].value = value;
4892 gr_values[regno - REG_GR].path = md.path;
4895 demand_empty_rest_of_line ();
4899 .serialize.data
4900 .serialize.instruction
4902 static void
4903 dot_serialize (int type)
4905 insn_group_break (0, 0, 0);
4906 if (type)
4907 instruction_serialization ();
4908 else
4909 data_serialization ();
4910 insn_group_break (0, 0, 0);
4911 demand_empty_rest_of_line ();
4914 /* select dv checking mode
4915 .auto
4916 .explicit
4917 .default
4919 A stop is inserted when changing modes
4922 static void
4923 dot_dv_mode (int type)
4925 if (md.manual_bundling)
4926 as_warn (_("Directive invalid within a bundle"));
4928 if (type == 'E' || type == 'A')
4929 md.mode_explicitly_set = 0;
4930 else
4931 md.mode_explicitly_set = 1;
4933 md.detect_dv = 1;
4934 switch (type)
4936 case 'A':
4937 case 'a':
4938 if (md.explicit_mode)
4939 insn_group_break (1, 0, 0);
4940 md.explicit_mode = 0;
4941 break;
4942 case 'E':
4943 case 'e':
4944 if (!md.explicit_mode)
4945 insn_group_break (1, 0, 0);
4946 md.explicit_mode = 1;
4947 break;
4948 default:
4949 case 'd':
4950 if (md.explicit_mode != md.default_explicit_mode)
4951 insn_group_break (1, 0, 0);
4952 md.explicit_mode = md.default_explicit_mode;
4953 md.mode_explicitly_set = 0;
4954 break;
4958 static void
4959 print_prmask (valueT mask)
4961 int regno;
4962 const char *comma = "";
4963 for (regno = 0; regno < 64; regno++)
4965 if (mask & ((valueT) 1 << regno))
4967 fprintf (stderr, "%s p%d", comma, regno);
4968 comma = ",";
4974 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear" or @clear)
4975 .pred.rel.imply p1, p2 (also .pred.rel "imply" or @imply)
4976 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex" or @mutex)
4977 .pred.safe_across_calls p1 [, p2 [,...]]
4980 static void
4981 dot_pred_rel (int type)
4983 valueT mask = 0;
4984 int count = 0;
4985 int p1 = -1, p2 = -1;
4987 if (type == 0)
4989 if (*input_line_pointer == '"')
4991 int len;
4992 char *form = demand_copy_C_string (&len);
4994 if (strcmp (form, "mutex") == 0)
4995 type = 'm';
4996 else if (strcmp (form, "clear") == 0)
4997 type = 'c';
4998 else if (strcmp (form, "imply") == 0)
4999 type = 'i';
5000 notes_free (form);
5002 else if (*input_line_pointer == '@')
5004 char *form;
5005 char c;
5007 ++input_line_pointer;
5008 c = get_symbol_name (&form);
5010 if (strcmp (form, "mutex") == 0)
5011 type = 'm';
5012 else if (strcmp (form, "clear") == 0)
5013 type = 'c';
5014 else if (strcmp (form, "imply") == 0)
5015 type = 'i';
5016 (void) restore_line_pointer (c);
5018 else
5020 as_bad (_("Missing predicate relation type"));
5021 ignore_rest_of_line ();
5022 return;
5024 if (type == 0)
5026 as_bad (_("Unrecognized predicate relation type"));
5027 ignore_rest_of_line ();
5028 return;
5030 if (*input_line_pointer == ',')
5031 ++input_line_pointer;
5032 SKIP_WHITESPACE ();
5035 while (1)
5037 valueT bits = 1;
5038 int sep, regno;
5039 expressionS pr, *pr1, *pr2;
5041 sep = parse_operand_and_eval (&pr, ',');
5042 if (pr.X_op == O_register
5043 && pr.X_add_number >= REG_P
5044 && pr.X_add_number <= REG_P + 63)
5046 regno = pr.X_add_number - REG_P;
5047 bits <<= regno;
5048 count++;
5049 if (p1 == -1)
5050 p1 = regno;
5051 else if (p2 == -1)
5052 p2 = regno;
5054 else if (type != 'i'
5055 && pr.X_op == O_subtract
5056 && (pr1 = symbol_get_value_expression (pr.X_add_symbol))
5057 && pr1->X_op == O_register
5058 && pr1->X_add_number >= REG_P
5059 && pr1->X_add_number <= REG_P + 63
5060 && (pr2 = symbol_get_value_expression (pr.X_op_symbol))
5061 && pr2->X_op == O_register
5062 && pr2->X_add_number >= REG_P
5063 && pr2->X_add_number <= REG_P + 63)
5065 /* It's a range. */
5066 int stop;
5068 regno = pr1->X_add_number - REG_P;
5069 stop = pr2->X_add_number - REG_P;
5070 if (regno >= stop)
5072 as_bad (_("Bad register range"));
5073 ignore_rest_of_line ();
5074 return;
5076 bits = ((bits << stop) << 1) - (bits << regno);
5077 count += stop - regno + 1;
5079 else
5081 as_bad (_("Predicate register expected"));
5082 ignore_rest_of_line ();
5083 return;
5085 if (mask & bits)
5086 as_warn (_("Duplicate predicate register ignored"));
5087 mask |= bits;
5088 if (sep != ',')
5089 break;
5092 switch (type)
5094 case 'c':
5095 if (count == 0)
5096 mask = ~(valueT) 0;
5097 clear_qp_mutex (mask);
5098 clear_qp_implies (mask, (valueT) 0);
5099 break;
5100 case 'i':
5101 if (count != 2 || p1 == -1 || p2 == -1)
5102 as_bad (_("Predicate source and target required"));
5103 else if (p1 == 0 || p2 == 0)
5104 as_bad (_("Use of p0 is not valid in this context"));
5105 else
5106 add_qp_imply (p1, p2);
5107 break;
5108 case 'm':
5109 if (count < 2)
5111 as_bad (_("At least two PR arguments expected"));
5112 break;
5114 else if (mask & 1)
5116 as_bad (_("Use of p0 is not valid in this context"));
5117 break;
5119 add_qp_mutex (mask);
5120 break;
5121 case 's':
5122 /* note that we don't override any existing relations */
5123 if (count == 0)
5125 as_bad (_("At least one PR argument expected"));
5126 break;
5128 if (md.debug_dv)
5130 fprintf (stderr, "Safe across calls: ");
5131 print_prmask (mask);
5132 fprintf (stderr, "\n");
5134 qp_safe_across_calls = mask;
5135 break;
5137 demand_empty_rest_of_line ();
5140 /* .entry label [, label [, ...]]
5141 Hint to DV code that the given labels are to be considered entry points.
5142 Otherwise, only global labels are considered entry points. */
5144 static void
5145 dot_entry (int dummy ATTRIBUTE_UNUSED)
5147 char *name;
5148 int c;
5149 symbolS *symbolP;
5153 c = get_symbol_name (&name);
5154 symbolP = symbol_find_or_make (name);
5156 if (str_hash_insert (md.entry_hash, S_GET_NAME (symbolP), symbolP, 0))
5157 as_bad (_("duplicate entry hint %s"), name);
5159 restore_line_pointer (c);
5160 SKIP_WHITESPACE ();
5161 c = *input_line_pointer;
5162 if (c == ',')
5164 input_line_pointer++;
5165 SKIP_WHITESPACE ();
5166 if (*input_line_pointer == '\n')
5167 c = '\n';
5170 while (c == ',');
5172 demand_empty_rest_of_line ();
5175 /* .mem.offset offset, base
5176 "base" is used to distinguish between offsets from a different base. */
5178 static void
5179 dot_mem_offset (int dummy ATTRIBUTE_UNUSED)
5181 md.mem_offset.hint = 1;
5182 md.mem_offset.offset = get_absolute_expression ();
5183 if (*input_line_pointer != ',')
5185 as_bad (_("Comma expected"));
5186 ignore_rest_of_line ();
5187 return;
5189 ++input_line_pointer;
5190 md.mem_offset.base = get_absolute_expression ();
5191 demand_empty_rest_of_line ();
5194 /* ia64-specific pseudo-ops: */
5195 const pseudo_typeS md_pseudo_table[] =
5197 { "radix", dot_radix, 0 },
5198 { "lcomm", s_lcomm_bytes, 1 },
5199 { "loc", dot_loc, 0 },
5200 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
5201 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
5202 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
5203 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
5204 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
5205 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
5206 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
5207 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
5208 { "proc", dot_proc, 0 },
5209 { "body", dot_body, 0 },
5210 { "prologue", dot_prologue, 0 },
5211 { "endp", dot_endp, 0 },
5213 { "fframe", dot_fframe, 0 },
5214 { "vframe", dot_vframe, 0 },
5215 { "vframesp", dot_vframesp, 0 },
5216 { "vframepsp", dot_vframesp, 1 },
5217 { "save", dot_save, 0 },
5218 { "restore", dot_restore, 0 },
5219 { "restorereg", dot_restorereg, 0 },
5220 { "restorereg.p", dot_restorereg, 1 },
5221 { "handlerdata", dot_handlerdata, 0 },
5222 { "unwentry", dot_unwentry, 0 },
5223 { "altrp", dot_altrp, 0 },
5224 { "savesp", dot_savemem, 0 },
5225 { "savepsp", dot_savemem, 1 },
5226 { "save.g", dot_saveg, 0 },
5227 { "save.f", dot_savef, 0 },
5228 { "save.b", dot_saveb, 0 },
5229 { "save.gf", dot_savegf, 0 },
5230 { "spill", dot_spill, 0 },
5231 { "spillreg", dot_spillreg, 0 },
5232 { "spillsp", dot_spillmem, 0 },
5233 { "spillpsp", dot_spillmem, 1 },
5234 { "spillreg.p", dot_spillreg, 1 },
5235 { "spillsp.p", dot_spillmem, ~0 },
5236 { "spillpsp.p", dot_spillmem, ~1 },
5237 { "label_state", dot_label_state, 0 },
5238 { "copy_state", dot_copy_state, 0 },
5239 { "unwabi", dot_unwabi, 0 },
5240 { "personality", dot_personality, 0 },
5241 { "mii", dot_template, 0x0 },
5242 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
5243 { "mlx", dot_template, 0x2 },
5244 { "mmi", dot_template, 0x4 },
5245 { "mfi", dot_template, 0x6 },
5246 { "mmf", dot_template, 0x7 },
5247 { "mib", dot_template, 0x8 },
5248 { "mbb", dot_template, 0x9 },
5249 { "bbb", dot_template, 0xb },
5250 { "mmb", dot_template, 0xc },
5251 { "mfb", dot_template, 0xe },
5252 { "align", dot_align, 0 },
5253 { "regstk", dot_regstk, 0 },
5254 { "rotr", dot_rot, DYNREG_GR },
5255 { "rotf", dot_rot, DYNREG_FR },
5256 { "rotp", dot_rot, DYNREG_PR },
5257 { "lsb", dot_byteorder, 0 },
5258 { "msb", dot_byteorder, 1 },
5259 { "psr", dot_psr, 0 },
5260 { "alias", dot_alias, 0 },
5261 { "secalias", dot_alias, 1 },
5262 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
5264 { "xdata1", dot_xdata, 1 },
5265 { "xdata2", dot_xdata, 2 },
5266 { "xdata4", dot_xdata, 4 },
5267 { "xdata8", dot_xdata, 8 },
5268 { "xdata16", dot_xdata, 16 },
5269 { "xreal4", dot_xfloat_cons, 'f' },
5270 { "xreal8", dot_xfloat_cons, 'd' },
5271 { "xreal10", dot_xfloat_cons, 'x' },
5272 { "xreal16", dot_xfloat_cons, 'X' },
5273 { "xstring", dot_xstringer, 8 + 0 },
5274 { "xstringz", dot_xstringer, 8 + 1 },
5276 /* unaligned versions: */
5277 { "xdata2.ua", dot_xdata_ua, 2 },
5278 { "xdata4.ua", dot_xdata_ua, 4 },
5279 { "xdata8.ua", dot_xdata_ua, 8 },
5280 { "xdata16.ua", dot_xdata_ua, 16 },
5281 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
5282 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
5283 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
5284 { "xreal16.ua", dot_xfloat_cons_ua, 'X' },
5286 /* annotations/DV checking support */
5287 { "entry", dot_entry, 0 },
5288 { "mem.offset", dot_mem_offset, 0 },
5289 { "pred.rel", dot_pred_rel, 0 },
5290 { "pred.rel.clear", dot_pred_rel, 'c' },
5291 { "pred.rel.imply", dot_pred_rel, 'i' },
5292 { "pred.rel.mutex", dot_pred_rel, 'm' },
5293 { "pred.safe_across_calls", dot_pred_rel, 's' },
5294 { "reg.val", dot_reg_val, 0 },
5295 { "serialize.data", dot_serialize, 0 },
5296 { "serialize.instruction", dot_serialize, 1 },
5297 { "auto", dot_dv_mode, 'a' },
5298 { "explicit", dot_dv_mode, 'e' },
5299 { "default", dot_dv_mode, 'd' },
5301 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
5302 IA-64 aligns data allocation pseudo-ops by default, so we have to
5303 tell it that these ones are supposed to be unaligned. Long term,
5304 should rewrite so that only IA-64 specific data allocation pseudo-ops
5305 are aligned by default. */
5306 {"2byte", stmt_cons_ua, 2},
5307 {"4byte", stmt_cons_ua, 4},
5308 {"8byte", stmt_cons_ua, 8},
5310 #ifdef TE_VMS
5311 {"vms_common", obj_elf_vms_common, 0},
5312 #endif
5314 { NULL, 0, 0 }
5317 static const struct pseudo_opcode
5319 const char *name;
5320 void (*handler) (int);
5321 int arg;
5323 pseudo_opcode[] =
5325 /* these are more like pseudo-ops, but don't start with a dot */
5326 { "data1", cons, 1 },
5327 { "data2", cons, 2 },
5328 { "data4", cons, 4 },
5329 { "data8", cons, 8 },
5330 { "data16", cons, 16 },
5331 { "real4", stmt_float_cons, 'f' },
5332 { "real8", stmt_float_cons, 'd' },
5333 { "real10", stmt_float_cons, 'x' },
5334 { "real16", stmt_float_cons, 'X' },
5335 { "string", stringer, 8 + 0 },
5336 { "stringz", stringer, 8 + 1 },
5338 /* unaligned versions: */
5339 { "data2.ua", stmt_cons_ua, 2 },
5340 { "data4.ua", stmt_cons_ua, 4 },
5341 { "data8.ua", stmt_cons_ua, 8 },
5342 { "data16.ua", stmt_cons_ua, 16 },
5343 { "real4.ua", float_cons, 'f' },
5344 { "real8.ua", float_cons, 'd' },
5345 { "real10.ua", float_cons, 'x' },
5346 { "real16.ua", float_cons, 'X' },
5349 /* Declare a register by creating a symbol for it and entering it in
5350 the symbol table. */
5352 static symbolS *
5353 declare_register (const char *name, unsigned int regnum)
5355 symbolS *sym;
5357 sym = symbol_create (name, reg_section, &zero_address_frag, regnum);
5359 if (str_hash_insert (md.reg_hash, S_GET_NAME (sym), sym, 0) != NULL)
5360 as_fatal (_("duplicate %s"), name);
5362 return sym;
5365 static void
5366 declare_register_set (const char *prefix,
5367 unsigned int num_regs,
5368 unsigned int base_regnum)
5370 char name[8];
5371 unsigned int i;
5373 for (i = 0; i < num_regs; ++i)
5375 snprintf (name, sizeof (name), "%s%u", prefix, i);
5376 declare_register (name, base_regnum + i);
5380 static unsigned int
5381 operand_width (enum ia64_opnd opnd)
5383 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5384 unsigned int bits = 0;
5385 int i;
5387 bits = 0;
5388 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5389 bits += odesc->field[i].bits;
5391 return bits;
5394 static enum operand_match_result
5395 operand_match (const struct ia64_opcode *idesc, int res_index, expressionS *e)
5397 enum ia64_opnd opnd = idesc->operands[res_index];
5398 int bits, relocatable = 0;
5399 struct insn_fix *fix;
5400 bfd_signed_vma val;
5402 switch (opnd)
5404 /* constants: */
5406 case IA64_OPND_AR_CCV:
5407 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5408 return OPERAND_MATCH;
5409 break;
5411 case IA64_OPND_AR_CSD:
5412 if (e->X_op == O_register && e->X_add_number == REG_AR + 25)
5413 return OPERAND_MATCH;
5414 break;
5416 case IA64_OPND_AR_PFS:
5417 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5418 return OPERAND_MATCH;
5419 break;
5421 case IA64_OPND_GR0:
5422 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5423 return OPERAND_MATCH;
5424 break;
5426 case IA64_OPND_IP:
5427 if (e->X_op == O_register && e->X_add_number == REG_IP)
5428 return OPERAND_MATCH;
5429 break;
5431 case IA64_OPND_PR:
5432 if (e->X_op == O_register && e->X_add_number == REG_PR)
5433 return OPERAND_MATCH;
5434 break;
5436 case IA64_OPND_PR_ROT:
5437 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5438 return OPERAND_MATCH;
5439 break;
5441 case IA64_OPND_PSR:
5442 if (e->X_op == O_register && e->X_add_number == REG_PSR)
5443 return OPERAND_MATCH;
5444 break;
5446 case IA64_OPND_PSR_L:
5447 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5448 return OPERAND_MATCH;
5449 break;
5451 case IA64_OPND_PSR_UM:
5452 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5453 return OPERAND_MATCH;
5454 break;
5456 case IA64_OPND_C1:
5457 if (e->X_op == O_constant)
5459 if (e->X_add_number == 1)
5460 return OPERAND_MATCH;
5461 else
5462 return OPERAND_OUT_OF_RANGE;
5464 break;
5466 case IA64_OPND_C8:
5467 if (e->X_op == O_constant)
5469 if (e->X_add_number == 8)
5470 return OPERAND_MATCH;
5471 else
5472 return OPERAND_OUT_OF_RANGE;
5474 break;
5476 case IA64_OPND_C16:
5477 if (e->X_op == O_constant)
5479 if (e->X_add_number == 16)
5480 return OPERAND_MATCH;
5481 else
5482 return OPERAND_OUT_OF_RANGE;
5484 break;
5486 /* register operands: */
5488 case IA64_OPND_AR3:
5489 if (e->X_op == O_register && e->X_add_number >= REG_AR
5490 && e->X_add_number < REG_AR + 128)
5491 return OPERAND_MATCH;
5492 break;
5494 case IA64_OPND_B1:
5495 case IA64_OPND_B2:
5496 if (e->X_op == O_register && e->X_add_number >= REG_BR
5497 && e->X_add_number < REG_BR + 8)
5498 return OPERAND_MATCH;
5499 break;
5501 case IA64_OPND_CR3:
5502 if (e->X_op == O_register && e->X_add_number >= REG_CR
5503 && e->X_add_number < REG_CR + 128)
5504 return OPERAND_MATCH;
5505 break;
5507 case IA64_OPND_DAHR3:
5508 if (e->X_op == O_register && e->X_add_number >= REG_DAHR
5509 && e->X_add_number < REG_DAHR + 8)
5510 return OPERAND_MATCH;
5511 break;
5513 case IA64_OPND_F1:
5514 case IA64_OPND_F2:
5515 case IA64_OPND_F3:
5516 case IA64_OPND_F4:
5517 if (e->X_op == O_register && e->X_add_number >= REG_FR
5518 && e->X_add_number < REG_FR + 128)
5519 return OPERAND_MATCH;
5520 break;
5522 case IA64_OPND_P1:
5523 case IA64_OPND_P2:
5524 if (e->X_op == O_register && e->X_add_number >= REG_P
5525 && e->X_add_number < REG_P + 64)
5526 return OPERAND_MATCH;
5527 break;
5529 case IA64_OPND_R1:
5530 case IA64_OPND_R2:
5531 case IA64_OPND_R3:
5532 if (e->X_op == O_register && e->X_add_number >= REG_GR
5533 && e->X_add_number < REG_GR + 128)
5534 return OPERAND_MATCH;
5535 break;
5537 case IA64_OPND_R3_2:
5538 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5540 if (e->X_add_number < REG_GR + 4)
5541 return OPERAND_MATCH;
5542 else if (e->X_add_number < REG_GR + 128)
5543 return OPERAND_OUT_OF_RANGE;
5545 break;
5547 /* indirect operands: */
5548 case IA64_OPND_CPUID_R3:
5549 case IA64_OPND_DBR_R3:
5550 case IA64_OPND_DTR_R3:
5551 case IA64_OPND_ITR_R3:
5552 case IA64_OPND_IBR_R3:
5553 case IA64_OPND_MSR_R3:
5554 case IA64_OPND_PKR_R3:
5555 case IA64_OPND_PMC_R3:
5556 case IA64_OPND_PMD_R3:
5557 case IA64_OPND_DAHR_R3:
5558 case IA64_OPND_RR_R3:
5559 if (e->X_op == O_index && e->X_op_symbol
5560 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5561 == opnd - IA64_OPND_CPUID_R3))
5562 return OPERAND_MATCH;
5563 break;
5565 case IA64_OPND_MR3:
5566 if (e->X_op == O_index && !e->X_op_symbol)
5567 return OPERAND_MATCH;
5568 break;
5570 /* immediate operands: */
5571 case IA64_OPND_CNT2a:
5572 case IA64_OPND_LEN4:
5573 case IA64_OPND_LEN6:
5574 bits = operand_width (idesc->operands[res_index]);
5575 if (e->X_op == O_constant)
5577 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5578 return OPERAND_MATCH;
5579 else
5580 return OPERAND_OUT_OF_RANGE;
5582 break;
5584 case IA64_OPND_CNT2b:
5585 if (e->X_op == O_constant)
5587 if ((bfd_vma) (e->X_add_number - 1) < 3)
5588 return OPERAND_MATCH;
5589 else
5590 return OPERAND_OUT_OF_RANGE;
5592 break;
5594 case IA64_OPND_CNT2c:
5595 val = e->X_add_number;
5596 if (e->X_op == O_constant)
5598 if ((val == 0 || val == 7 || val == 15 || val == 16))
5599 return OPERAND_MATCH;
5600 else
5601 return OPERAND_OUT_OF_RANGE;
5603 break;
5605 case IA64_OPND_SOR:
5606 /* SOR must be an integer multiple of 8 */
5607 if (e->X_op == O_constant && e->X_add_number & 0x7)
5608 return OPERAND_OUT_OF_RANGE;
5609 /* Fall through. */
5610 case IA64_OPND_SOF:
5611 case IA64_OPND_SOL:
5612 if (e->X_op == O_constant)
5614 if ((bfd_vma) e->X_add_number <= 96)
5615 return OPERAND_MATCH;
5616 else
5617 return OPERAND_OUT_OF_RANGE;
5619 break;
5621 case IA64_OPND_IMMU62:
5622 if (e->X_op == O_constant)
5624 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5625 return OPERAND_MATCH;
5626 else
5627 return OPERAND_OUT_OF_RANGE;
5629 else
5631 /* FIXME -- need 62-bit relocation type */
5632 as_bad (_("62-bit relocation not yet implemented"));
5634 break;
5636 case IA64_OPND_IMMU64:
5637 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5638 || e->X_op == O_subtract)
5640 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5641 fix->code = BFD_RELOC_IA64_IMM64;
5642 if (e->X_op != O_subtract)
5644 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5645 if (e->X_op == O_pseudo_fixup)
5646 e->X_op = O_symbol;
5649 fix->opnd = idesc->operands[res_index];
5650 fix->expr = *e;
5651 fix->is_pcrel = 0;
5652 ++CURR_SLOT.num_fixups;
5653 return OPERAND_MATCH;
5655 else if (e->X_op == O_constant)
5656 return OPERAND_MATCH;
5657 break;
5659 case IA64_OPND_IMMU5b:
5660 if (e->X_op == O_constant)
5662 val = e->X_add_number;
5663 if (val >= 32 && val <= 63)
5664 return OPERAND_MATCH;
5665 else
5666 return OPERAND_OUT_OF_RANGE;
5668 break;
5670 case IA64_OPND_CCNT5:
5671 case IA64_OPND_CNT5:
5672 case IA64_OPND_CNT6:
5673 case IA64_OPND_CPOS6a:
5674 case IA64_OPND_CPOS6b:
5675 case IA64_OPND_CPOS6c:
5676 case IA64_OPND_IMMU2:
5677 case IA64_OPND_IMMU7a:
5678 case IA64_OPND_IMMU7b:
5679 case IA64_OPND_IMMU16:
5680 case IA64_OPND_IMMU19:
5681 case IA64_OPND_IMMU21:
5682 case IA64_OPND_IMMU24:
5683 case IA64_OPND_MBTYPE4:
5684 case IA64_OPND_MHTYPE8:
5685 case IA64_OPND_POS6:
5686 bits = operand_width (idesc->operands[res_index]);
5687 if (e->X_op == O_constant)
5689 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5690 return OPERAND_MATCH;
5691 else
5692 return OPERAND_OUT_OF_RANGE;
5694 break;
5696 case IA64_OPND_IMMU9:
5697 bits = operand_width (idesc->operands[res_index]);
5698 if (e->X_op == O_constant)
5700 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5702 int lobits = e->X_add_number & 0x3;
5703 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5704 e->X_add_number |= (bfd_vma) 0x3;
5705 return OPERAND_MATCH;
5707 else
5708 return OPERAND_OUT_OF_RANGE;
5710 break;
5712 case IA64_OPND_IMM44:
5713 /* least 16 bits must be zero */
5714 if ((e->X_add_number & 0xffff) != 0)
5715 /* XXX technically, this is wrong: we should not be issuing warning
5716 messages until we're sure this instruction pattern is going to
5717 be used! */
5718 as_warn (_("lower 16 bits of mask ignored"));
5720 if (e->X_op == O_constant)
5722 if (((e->X_add_number >= 0
5723 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5724 || (e->X_add_number < 0
5725 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5727 /* sign-extend */
5728 if (e->X_add_number >= 0
5729 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5731 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5733 return OPERAND_MATCH;
5735 else
5736 return OPERAND_OUT_OF_RANGE;
5738 break;
5740 case IA64_OPND_IMM17:
5741 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5742 if (e->X_op == O_constant)
5744 if (((e->X_add_number >= 0
5745 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5746 || (e->X_add_number < 0
5747 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5749 /* sign-extend */
5750 if (e->X_add_number >= 0
5751 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5753 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5755 return OPERAND_MATCH;
5757 else
5758 return OPERAND_OUT_OF_RANGE;
5760 break;
5762 case IA64_OPND_IMM14:
5763 case IA64_OPND_IMM22:
5764 relocatable = 1;
5765 /* Fall through. */
5766 case IA64_OPND_IMM1:
5767 case IA64_OPND_IMM8:
5768 case IA64_OPND_IMM8U4:
5769 case IA64_OPND_IMM8M1:
5770 case IA64_OPND_IMM8M1U4:
5771 case IA64_OPND_IMM8M1U8:
5772 case IA64_OPND_IMM9a:
5773 case IA64_OPND_IMM9b:
5774 bits = operand_width (idesc->operands[res_index]);
5775 if (relocatable && (e->X_op == O_symbol
5776 || e->X_op == O_subtract
5777 || e->X_op == O_pseudo_fixup))
5779 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5781 if (idesc->operands[res_index] == IA64_OPND_IMM14)
5782 fix->code = BFD_RELOC_IA64_IMM14;
5783 else
5784 fix->code = BFD_RELOC_IA64_IMM22;
5786 if (e->X_op != O_subtract)
5788 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5789 if (e->X_op == O_pseudo_fixup)
5790 e->X_op = O_symbol;
5793 fix->opnd = idesc->operands[res_index];
5794 fix->expr = *e;
5795 fix->is_pcrel = 0;
5796 ++CURR_SLOT.num_fixups;
5797 return OPERAND_MATCH;
5799 else if (e->X_op != O_constant
5800 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5801 return OPERAND_MISMATCH;
5803 if (opnd == IA64_OPND_IMM8M1U4)
5805 /* Zero is not valid for unsigned compares that take an adjusted
5806 constant immediate range. */
5807 if (e->X_add_number == 0)
5808 return OPERAND_OUT_OF_RANGE;
5810 /* Sign-extend 32-bit unsigned numbers, so that the following range
5811 checks will work. */
5812 val = e->X_add_number;
5813 if ((val & (~(bfd_vma) 0 << 32)) == 0)
5814 val = (val ^ ((bfd_vma) 1 << 31)) - ((bfd_vma) 1 << 31);
5816 /* Check for 0x100000000. This is valid because
5817 0x100000000-1 is the same as ((uint32_t) -1). */
5818 if (val == ((bfd_signed_vma) 1 << 32))
5819 return OPERAND_MATCH;
5821 val = val - 1;
5823 else if (opnd == IA64_OPND_IMM8M1U8)
5825 /* Zero is not valid for unsigned compares that take an adjusted
5826 constant immediate range. */
5827 if (e->X_add_number == 0)
5828 return OPERAND_OUT_OF_RANGE;
5830 /* Check for 0x10000000000000000. */
5831 if (e->X_op == O_big)
5833 if (generic_bignum[0] == 0
5834 && generic_bignum[1] == 0
5835 && generic_bignum[2] == 0
5836 && generic_bignum[3] == 0
5837 && generic_bignum[4] == 1)
5838 return OPERAND_MATCH;
5839 else
5840 return OPERAND_OUT_OF_RANGE;
5842 else
5843 val = e->X_add_number - 1;
5845 else if (opnd == IA64_OPND_IMM8M1)
5846 val = e->X_add_number - 1;
5847 else if (opnd == IA64_OPND_IMM8U4)
5849 /* Sign-extend 32-bit unsigned numbers, so that the following range
5850 checks will work. */
5851 val = e->X_add_number;
5852 if ((val & (~(bfd_vma) 0 << 32)) == 0)
5853 val = (val ^ ((bfd_vma) 1 << 31)) - ((bfd_vma) 1 << 31);
5855 else
5856 val = e->X_add_number;
5858 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5859 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5860 return OPERAND_MATCH;
5861 else
5862 return OPERAND_OUT_OF_RANGE;
5864 case IA64_OPND_INC3:
5865 /* +/- 1, 4, 8, 16 */
5866 val = e->X_add_number;
5867 if (val < 0)
5868 val = -val;
5869 if (e->X_op == O_constant)
5871 if ((val == 1 || val == 4 || val == 8 || val == 16))
5872 return OPERAND_MATCH;
5873 else
5874 return OPERAND_OUT_OF_RANGE;
5876 break;
5878 case IA64_OPND_TGT25:
5879 case IA64_OPND_TGT25b:
5880 case IA64_OPND_TGT25c:
5881 case IA64_OPND_TGT64:
5882 if (e->X_op == O_symbol)
5884 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5885 if (opnd == IA64_OPND_TGT25)
5886 fix->code = BFD_RELOC_IA64_PCREL21F;
5887 else if (opnd == IA64_OPND_TGT25b)
5888 fix->code = BFD_RELOC_IA64_PCREL21M;
5889 else if (opnd == IA64_OPND_TGT25c)
5890 fix->code = BFD_RELOC_IA64_PCREL21B;
5891 else if (opnd == IA64_OPND_TGT64)
5892 fix->code = BFD_RELOC_IA64_PCREL60B;
5893 else
5894 abort ();
5896 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5897 fix->opnd = idesc->operands[res_index];
5898 fix->expr = *e;
5899 fix->is_pcrel = 1;
5900 ++CURR_SLOT.num_fixups;
5901 return OPERAND_MATCH;
5903 /* Fall through. */
5904 case IA64_OPND_TAG13:
5905 case IA64_OPND_TAG13b:
5906 switch (e->X_op)
5908 case O_constant:
5909 return OPERAND_MATCH;
5911 case O_symbol:
5912 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5913 /* There are no external relocs for TAG13/TAG13b fields, so we
5914 create a dummy reloc. This will not live past md_apply_fix. */
5915 fix->code = BFD_RELOC_UNUSED;
5916 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5917 fix->opnd = idesc->operands[res_index];
5918 fix->expr = *e;
5919 fix->is_pcrel = 1;
5920 ++CURR_SLOT.num_fixups;
5921 return OPERAND_MATCH;
5923 default:
5924 break;
5926 break;
5928 case IA64_OPND_LDXMOV:
5929 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5930 fix->code = BFD_RELOC_IA64_LDXMOV;
5931 fix->opnd = idesc->operands[res_index];
5932 fix->expr = *e;
5933 fix->is_pcrel = 0;
5934 ++CURR_SLOT.num_fixups;
5935 return OPERAND_MATCH;
5937 case IA64_OPND_STRD5b:
5938 if (e->X_op == O_constant)
5940 /* 5-bit signed scaled by 64 */
5941 if ((e->X_add_number <= ( 0xf << 6 ))
5942 && (e->X_add_number >= -( 0x10 << 6 )))
5945 /* Must be a multiple of 64 */
5946 if ((e->X_add_number & 0x3f) != 0)
5947 as_warn (_("stride must be a multiple of 64; lower 6 bits ignored"));
5949 e->X_add_number &= ~ 0x3f;
5950 return OPERAND_MATCH;
5952 else
5953 return OPERAND_OUT_OF_RANGE;
5955 break;
5956 case IA64_OPND_CNT6a:
5957 if (e->X_op == O_constant)
5959 /* 6-bit unsigned biased by 1 -- count 0 is meaningless */
5960 if ((e->X_add_number <= 64)
5961 && (e->X_add_number > 0) )
5963 return OPERAND_MATCH;
5965 else
5966 return OPERAND_OUT_OF_RANGE;
5968 break;
5970 default:
5971 break;
5973 return OPERAND_MISMATCH;
5976 static int
5977 parse_operand (expressionS *e, int more)
5979 int sep = '\0';
5981 memset (e, 0, sizeof (*e));
5982 e->X_op = O_absent;
5983 SKIP_WHITESPACE ();
5984 expression (e);
5985 resolve_register (e);
5986 sep = *input_line_pointer;
5987 if (more && (sep == ',' || sep == more))
5988 ++input_line_pointer;
5989 return sep;
5992 static int
5993 parse_operand_and_eval (expressionS *e, int more)
5995 int sep = parse_operand (e, more);
5996 resolve_expression (e);
5997 return sep;
6000 static int
6001 parse_operand_maybe_eval (expressionS *e, int more, enum ia64_opnd op)
6003 int sep = parse_operand (e, more);
6004 switch (op)
6006 case IA64_OPND_IMM14:
6007 case IA64_OPND_IMM22:
6008 case IA64_OPND_IMMU64:
6009 case IA64_OPND_TGT25:
6010 case IA64_OPND_TGT25b:
6011 case IA64_OPND_TGT25c:
6012 case IA64_OPND_TGT64:
6013 case IA64_OPND_TAG13:
6014 case IA64_OPND_TAG13b:
6015 case IA64_OPND_LDXMOV:
6016 break;
6017 default:
6018 resolve_expression (e);
6019 break;
6021 return sep;
6024 /* Returns the next entry in the opcode table that matches the one in
6025 IDESC, and frees the entry in IDESC. If no matching entry is
6026 found, NULL is returned instead. */
6028 static struct ia64_opcode *
6029 get_next_opcode (struct ia64_opcode *idesc)
6031 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
6032 ia64_free_opcode (idesc);
6033 return next;
6036 /* Parse the operands for the opcode and find the opcode variant that
6037 matches the specified operands, or NULL if no match is possible. */
6039 static struct ia64_opcode *
6040 parse_operands (struct ia64_opcode *idesc)
6042 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
6043 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
6044 int reg1, reg2;
6045 char reg_class;
6046 enum ia64_opnd expected_operand = IA64_OPND_NIL;
6047 enum operand_match_result result;
6048 char mnemonic[129];
6049 char *first_arg = 0, *end, *saved_input_pointer;
6050 unsigned int sof;
6052 gas_assert (strlen (idesc->name) <= 128);
6054 strcpy (mnemonic, idesc->name);
6055 if (idesc->operands[2] == IA64_OPND_SOF
6056 || idesc->operands[1] == IA64_OPND_SOF)
6058 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
6059 can't parse the first operand until we have parsed the
6060 remaining operands of the "alloc" instruction. */
6061 SKIP_WHITESPACE ();
6062 first_arg = input_line_pointer;
6063 end = strchr (input_line_pointer, '=');
6064 if (!end)
6066 as_bad (_("Expected separator `='"));
6067 return 0;
6069 input_line_pointer = end + 1;
6070 ++i;
6071 ++num_outputs;
6074 for (; ; ++i)
6076 if (i < NELEMS (CURR_SLOT.opnd))
6078 enum ia64_opnd op = IA64_OPND_NIL;
6079 if (i < NELEMS (idesc->operands))
6080 op = idesc->operands[i];
6081 sep = parse_operand_maybe_eval (CURR_SLOT.opnd + i, '=', op);
6082 if (CURR_SLOT.opnd[i].X_op == O_absent)
6083 break;
6085 else
6087 expressionS dummy;
6089 sep = parse_operand (&dummy, '=');
6090 if (dummy.X_op == O_absent)
6091 break;
6094 ++num_operands;
6096 if (sep != '=' && sep != ',')
6097 break;
6099 if (sep == '=')
6101 if (num_outputs > 0)
6102 as_bad (_("Duplicate equal sign (=) in instruction"));
6103 else
6104 num_outputs = i + 1;
6107 if (sep != '\0')
6109 as_bad (_("Illegal operand separator `%c'"), sep);
6110 return 0;
6113 if (idesc->operands[2] == IA64_OPND_SOF
6114 || idesc->operands[1] == IA64_OPND_SOF)
6116 /* Map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r.
6117 Note, however, that due to that mapping operand numbers in error
6118 messages for any of the constant operands will not be correct. */
6119 know (strcmp (idesc->name, "alloc") == 0);
6120 /* The first operand hasn't been parsed/initialized, yet (but
6121 num_operands intentionally doesn't account for that). */
6122 i = num_operands > 4 ? 2 : 1;
6123 #define FORCE_CONST(n) (CURR_SLOT.opnd[n].X_op == O_constant \
6124 ? CURR_SLOT.opnd[n].X_add_number \
6125 : 0)
6126 sof = set_regstack (FORCE_CONST(i),
6127 FORCE_CONST(i + 1),
6128 FORCE_CONST(i + 2),
6129 FORCE_CONST(i + 3));
6130 #undef FORCE_CONST
6132 /* now we can parse the first arg: */
6133 saved_input_pointer = input_line_pointer;
6134 input_line_pointer = first_arg;
6135 sep = parse_operand_maybe_eval (CURR_SLOT.opnd + 0, '=',
6136 idesc->operands[0]);
6137 if (sep != '=')
6138 --num_outputs; /* force error */
6139 input_line_pointer = saved_input_pointer;
6141 CURR_SLOT.opnd[i].X_add_number = sof;
6142 if (CURR_SLOT.opnd[i + 1].X_op == O_constant
6143 && CURR_SLOT.opnd[i + 2].X_op == O_constant)
6144 CURR_SLOT.opnd[i + 1].X_add_number
6145 = sof - CURR_SLOT.opnd[i + 2].X_add_number;
6146 else
6147 CURR_SLOT.opnd[i + 1].X_op = O_illegal;
6148 CURR_SLOT.opnd[i + 2] = CURR_SLOT.opnd[i + 3];
6151 highest_unmatched_operand = -4;
6152 curr_out_of_range_pos = -1;
6153 error_pos = 0;
6154 for (; idesc; idesc = get_next_opcode (idesc))
6156 if (num_outputs != idesc->num_outputs)
6157 continue; /* mismatch in # of outputs */
6158 if (highest_unmatched_operand < 0)
6159 highest_unmatched_operand |= 1;
6160 if (num_operands > NELEMS (idesc->operands)
6161 || (num_operands < NELEMS (idesc->operands)
6162 && idesc->operands[num_operands])
6163 || (num_operands > 0 && !idesc->operands[num_operands - 1]))
6164 continue; /* mismatch in number of arguments */
6165 if (highest_unmatched_operand < 0)
6166 highest_unmatched_operand |= 2;
6168 CURR_SLOT.num_fixups = 0;
6170 /* Try to match all operands. If we see an out-of-range operand,
6171 then continue trying to match the rest of the operands, since if
6172 the rest match, then this idesc will give the best error message. */
6174 out_of_range_pos = -1;
6175 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
6177 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
6178 if (result != OPERAND_MATCH)
6180 if (result != OPERAND_OUT_OF_RANGE)
6181 break;
6182 if (out_of_range_pos < 0)
6183 /* remember position of the first out-of-range operand: */
6184 out_of_range_pos = i;
6188 /* If we did not match all operands, or if at least one operand was
6189 out-of-range, then this idesc does not match. Keep track of which
6190 idesc matched the most operands before failing. If we have two
6191 idescs that failed at the same position, and one had an out-of-range
6192 operand, then prefer the out-of-range operand. Thus if we have
6193 "add r0=0x1000000,r1" we get an error saying the constant is out
6194 of range instead of an error saying that the constant should have been
6195 a register. */
6197 if (i != num_operands || out_of_range_pos >= 0)
6199 if (i > highest_unmatched_operand
6200 || (i == highest_unmatched_operand
6201 && out_of_range_pos > curr_out_of_range_pos))
6203 highest_unmatched_operand = i;
6204 if (out_of_range_pos >= 0)
6206 expected_operand = idesc->operands[out_of_range_pos];
6207 error_pos = out_of_range_pos;
6209 else
6211 expected_operand = idesc->operands[i];
6212 error_pos = i;
6214 curr_out_of_range_pos = out_of_range_pos;
6216 continue;
6219 break;
6221 if (!idesc)
6223 if (expected_operand)
6224 as_bad (_("Operand %u of `%s' should be %s"),
6225 error_pos + 1, mnemonic,
6226 elf64_ia64_operands[expected_operand].desc);
6227 else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 1))
6228 as_bad (_("Wrong number of output operands"));
6229 else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 2))
6230 as_bad (_("Wrong number of input operands"));
6231 else
6232 as_bad (_("Operand mismatch"));
6233 return 0;
6236 /* Check that the instruction doesn't use
6237 - r0, f0, or f1 as output operands
6238 - the same predicate twice as output operands
6239 - r0 as address of a base update load or store
6240 - the same GR as output and address of a base update load
6241 - two even- or two odd-numbered FRs as output operands of a floating
6242 point parallel load.
6243 At most two (conflicting) output (or output-like) operands can exist,
6244 (floating point parallel loads have three outputs, but the base register,
6245 if updated, cannot conflict with the actual outputs). */
6246 reg2 = reg1 = -1;
6247 for (i = 0; i < num_operands; ++i)
6249 int regno = 0;
6251 reg_class = 0;
6252 switch (idesc->operands[i])
6254 case IA64_OPND_R1:
6255 case IA64_OPND_R2:
6256 case IA64_OPND_R3:
6257 if (i < num_outputs)
6259 if (CURR_SLOT.opnd[i].X_add_number == REG_GR)
6260 reg_class = 'r';
6261 else if (reg1 < 0)
6262 reg1 = CURR_SLOT.opnd[i].X_add_number;
6263 else if (reg2 < 0)
6264 reg2 = CURR_SLOT.opnd[i].X_add_number;
6266 break;
6267 case IA64_OPND_P1:
6268 case IA64_OPND_P2:
6269 if (i < num_outputs)
6271 if (reg1 < 0)
6272 reg1 = CURR_SLOT.opnd[i].X_add_number;
6273 else if (reg2 < 0)
6274 reg2 = CURR_SLOT.opnd[i].X_add_number;
6276 break;
6277 case IA64_OPND_F1:
6278 case IA64_OPND_F2:
6279 case IA64_OPND_F3:
6280 case IA64_OPND_F4:
6281 if (i < num_outputs)
6283 if (CURR_SLOT.opnd[i].X_add_number >= REG_FR
6284 && CURR_SLOT.opnd[i].X_add_number <= REG_FR + 1)
6286 reg_class = 'f';
6287 regno = CURR_SLOT.opnd[i].X_add_number - REG_FR;
6289 else if (reg1 < 0)
6290 reg1 = CURR_SLOT.opnd[i].X_add_number;
6291 else if (reg2 < 0)
6292 reg2 = CURR_SLOT.opnd[i].X_add_number;
6294 break;
6295 case IA64_OPND_MR3:
6296 if (idesc->flags & IA64_OPCODE_POSTINC)
6298 if (CURR_SLOT.opnd[i].X_add_number == REG_GR)
6299 reg_class = 'm';
6300 else if (reg1 < 0)
6301 reg1 = CURR_SLOT.opnd[i].X_add_number;
6302 else if (reg2 < 0)
6303 reg2 = CURR_SLOT.opnd[i].X_add_number;
6305 break;
6306 default:
6307 break;
6309 switch (reg_class)
6311 case 0:
6312 break;
6313 default:
6314 as_warn (_("Invalid use of `%c%d' as output operand"), reg_class, regno);
6315 break;
6316 case 'm':
6317 as_warn (_("Invalid use of `r%d' as base update address operand"), regno);
6318 break;
6321 if (reg1 == reg2)
6323 if (reg1 >= REG_GR && reg1 <= REG_GR + 127)
6325 reg1 -= REG_GR;
6326 reg_class = 'r';
6328 else if (reg1 >= REG_P && reg1 <= REG_P + 63)
6330 reg1 -= REG_P;
6331 reg_class = 'p';
6333 else if (reg1 >= REG_FR && reg1 <= REG_FR + 127)
6335 reg1 -= REG_FR;
6336 reg_class = 'f';
6338 else
6339 reg_class = 0;
6340 if (reg_class)
6341 as_warn (_("Invalid duplicate use of `%c%d'"), reg_class, reg1);
6343 else if (((reg1 >= REG_FR && reg1 <= REG_FR + 31
6344 && reg2 >= REG_FR && reg2 <= REG_FR + 31)
6345 || (reg1 >= REG_FR + 32 && reg1 <= REG_FR + 127
6346 && reg2 >= REG_FR + 32 && reg2 <= REG_FR + 127))
6347 && ! ((reg1 ^ reg2) & 1))
6348 as_warn (_("Invalid simultaneous use of `f%d' and `f%d'"),
6349 reg1 - REG_FR, reg2 - REG_FR);
6350 else if ((reg1 >= REG_FR && reg1 <= REG_FR + 31
6351 && reg2 >= REG_FR + 32 && reg2 <= REG_FR + 127)
6352 || (reg1 >= REG_FR + 32 && reg1 <= REG_FR + 127
6353 && reg2 >= REG_FR && reg2 <= REG_FR + 31))
6354 as_warn (_("Dangerous simultaneous use of `f%d' and `f%d'"),
6355 reg1 - REG_FR, reg2 - REG_FR);
6356 return idesc;
6359 static void
6360 build_insn (struct slot *slot, bfd_vma *insnp)
6362 const struct ia64_operand *odesc, *o2desc;
6363 struct ia64_opcode *idesc = slot->idesc;
6364 bfd_vma insn;
6365 bfd_signed_vma val;
6366 const char *err;
6367 int i;
6369 insn = idesc->opcode | slot->qp_regno;
6371 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
6373 if (slot->opnd[i].X_op == O_register
6374 || slot->opnd[i].X_op == O_constant
6375 || slot->opnd[i].X_op == O_index)
6376 val = slot->opnd[i].X_add_number;
6377 else if (slot->opnd[i].X_op == O_big)
6379 /* This must be the value 0x10000000000000000. */
6380 gas_assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
6381 val = 0;
6383 else
6384 val = 0;
6386 switch (idesc->operands[i])
6388 case IA64_OPND_IMMU64:
6389 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
6390 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
6391 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
6392 | (((val >> 63) & 0x1) << 36));
6393 continue;
6395 case IA64_OPND_IMMU62:
6396 val &= 0x3fffffffffffffffULL;
6397 if (val != slot->opnd[i].X_add_number)
6398 as_warn (_("Value truncated to 62 bits"));
6399 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
6400 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
6401 continue;
6403 case IA64_OPND_TGT64:
6404 val >>= 4;
6405 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
6406 insn |= ((((val >> 59) & 0x1) << 36)
6407 | (((val >> 0) & 0xfffff) << 13));
6408 continue;
6410 case IA64_OPND_AR3:
6411 val -= REG_AR;
6412 break;
6414 case IA64_OPND_B1:
6415 case IA64_OPND_B2:
6416 val -= REG_BR;
6417 break;
6419 case IA64_OPND_CR3:
6420 val -= REG_CR;
6421 break;
6423 case IA64_OPND_DAHR3:
6424 val -= REG_DAHR;
6425 break;
6427 case IA64_OPND_F1:
6428 case IA64_OPND_F2:
6429 case IA64_OPND_F3:
6430 case IA64_OPND_F4:
6431 val -= REG_FR;
6432 break;
6434 case IA64_OPND_P1:
6435 case IA64_OPND_P2:
6436 val -= REG_P;
6437 break;
6439 case IA64_OPND_R1:
6440 case IA64_OPND_R2:
6441 case IA64_OPND_R3:
6442 case IA64_OPND_R3_2:
6443 case IA64_OPND_CPUID_R3:
6444 case IA64_OPND_DBR_R3:
6445 case IA64_OPND_DTR_R3:
6446 case IA64_OPND_ITR_R3:
6447 case IA64_OPND_IBR_R3:
6448 case IA64_OPND_MR3:
6449 case IA64_OPND_MSR_R3:
6450 case IA64_OPND_PKR_R3:
6451 case IA64_OPND_PMC_R3:
6452 case IA64_OPND_PMD_R3:
6453 case IA64_OPND_DAHR_R3:
6454 case IA64_OPND_RR_R3:
6455 val -= REG_GR;
6456 break;
6458 default:
6459 break;
6462 odesc = elf64_ia64_operands + idesc->operands[i];
6463 err = (*odesc->insert) (odesc, val, &insn);
6464 if (err)
6465 as_bad_where (slot->src_file, slot->src_line,
6466 _("Bad operand value: %s"), err);
6467 if (idesc->flags & IA64_OPCODE_PSEUDO)
6469 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
6470 && odesc == elf64_ia64_operands + IA64_OPND_F3)
6472 o2desc = elf64_ia64_operands + IA64_OPND_F2;
6473 (*o2desc->insert) (o2desc, val, &insn);
6475 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
6476 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
6477 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
6479 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
6480 (*o2desc->insert) (o2desc, 64 - val, &insn);
6484 *insnp = insn;
6487 static void
6488 emit_one_bundle (void)
6490 int manual_bundling_off = 0, manual_bundling = 0;
6491 enum ia64_unit required_unit, insn_unit = 0;
6492 enum ia64_insn_type type[3], insn_type;
6493 unsigned int template_val, orig_template;
6494 bfd_vma insn[3] = { -1, -1, -1 };
6495 struct ia64_opcode *idesc;
6496 int end_of_insn_group = 0, user_template = -1;
6497 int n, i, j, first, curr, last_slot;
6498 bfd_vma t0 = 0, t1 = 0;
6499 struct label_fix *lfix;
6500 bool mark_label;
6501 struct insn_fix *ifix;
6502 char mnemonic[16];
6503 fixS *fix;
6504 char *f;
6505 int addr_mod;
6507 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
6508 know (first >= 0 && first < NUM_SLOTS);
6509 n = MIN (3, md.num_slots_in_use);
6511 /* Determine template: user user_template if specified, best match
6512 otherwise: */
6514 if (md.slot[first].user_template >= 0)
6515 user_template = template_val = md.slot[first].user_template;
6516 else
6518 /* Auto select appropriate template. */
6519 memset (type, 0, sizeof (type));
6520 curr = first;
6521 for (i = 0; i < n; ++i)
6523 if (md.slot[curr].label_fixups && i != 0)
6524 break;
6525 type[i] = md.slot[curr].idesc->type;
6526 curr = (curr + 1) % NUM_SLOTS;
6528 template_val = best_template[type[0]][type[1]][type[2]];
6531 /* initialize instructions with appropriate nops: */
6532 for (i = 0; i < 3; ++i)
6533 insn[i] = nop[ia64_templ_desc[template_val].exec_unit[i]];
6535 f = frag_more (16);
6537 /* Check to see if this bundle is at an offset that is a multiple of 16-bytes
6538 from the start of the frag. */
6539 addr_mod = frag_now_fix () & 15;
6540 if (frag_now->has_code && frag_now->insn_addr != addr_mod)
6541 as_bad (_("instruction address is not a multiple of 16"));
6542 frag_now->insn_addr = addr_mod;
6543 frag_now->has_code = 1;
6545 /* now fill in slots with as many insns as possible: */
6546 curr = first;
6547 idesc = md.slot[curr].idesc;
6548 end_of_insn_group = 0;
6549 last_slot = -1;
6550 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6552 /* If we have unwind records, we may need to update some now. */
6553 unw_rec_list *ptr = md.slot[curr].unwind_record;
6554 unw_rec_list *end_ptr = NULL;
6556 if (ptr)
6558 /* Find the last prologue/body record in the list for the current
6559 insn, and set the slot number for all records up to that point.
6560 This needs to be done now, because prologue/body records refer to
6561 the current point, not the point after the instruction has been
6562 issued. This matters because there may have been nops emitted
6563 meanwhile. Any non-prologue non-body record followed by a
6564 prologue/body record must also refer to the current point. */
6565 unw_rec_list *last_ptr;
6567 for (j = 1; end_ptr == NULL && j < md.num_slots_in_use; ++j)
6568 end_ptr = md.slot[(curr + j) % NUM_SLOTS].unwind_record;
6569 for (last_ptr = NULL; ptr != end_ptr; ptr = ptr->next)
6570 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6571 || ptr->r.type == body)
6572 last_ptr = ptr;
6573 if (last_ptr)
6575 /* Make last_ptr point one after the last prologue/body
6576 record. */
6577 last_ptr = last_ptr->next;
6578 for (ptr = md.slot[curr].unwind_record; ptr != last_ptr;
6579 ptr = ptr->next)
6581 ptr->slot_number = (unsigned long) f + i;
6582 ptr->slot_frag = frag_now;
6584 /* Remove the initialized records, so that we won't accidentally
6585 update them again if we insert a nop and continue. */
6586 md.slot[curr].unwind_record = last_ptr;
6590 manual_bundling_off = md.slot[curr].manual_bundling_off;
6591 if (md.slot[curr].manual_bundling_on)
6593 if (curr == first)
6594 manual_bundling = 1;
6595 else
6596 break; /* Need to start a new bundle. */
6599 /* If this instruction specifies a template, then it must be the first
6600 instruction of a bundle. */
6601 if (curr != first && md.slot[curr].user_template >= 0)
6602 break;
6604 if (idesc->flags & IA64_OPCODE_SLOT2)
6606 if (manual_bundling && !manual_bundling_off)
6608 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6609 _("`%s' must be last in bundle"), idesc->name);
6610 if (i < 2)
6611 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6613 i = 2;
6615 if (idesc->flags & IA64_OPCODE_LAST)
6617 int required_slot;
6618 unsigned int required_template;
6620 /* If we need a stop bit after an M slot, our only choice is
6621 template 5 (M;;MI). If we need a stop bit after a B
6622 slot, our only choice is to place it at the end of the
6623 bundle, because the only available templates are MIB,
6624 MBB, BBB, MMB, and MFB. We don't handle anything other
6625 than M and B slots because these are the only kind of
6626 instructions that can have the IA64_OPCODE_LAST bit set. */
6627 required_template = template_val;
6628 switch (idesc->type)
6630 case IA64_TYPE_M:
6631 required_slot = 0;
6632 required_template = 5;
6633 break;
6635 case IA64_TYPE_B:
6636 required_slot = 2;
6637 break;
6639 default:
6640 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6641 _("Internal error: don't know how to force %s to end of instruction group"),
6642 idesc->name);
6643 required_slot = i;
6644 break;
6646 if (manual_bundling
6647 && (i > required_slot
6648 || (required_slot == 2 && !manual_bundling_off)
6649 || (user_template >= 0
6650 /* Changing from MMI to M;MI is OK. */
6651 && (template_val ^ required_template) > 1)))
6653 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6654 _("`%s' must be last in instruction group"),
6655 idesc->name);
6656 if (i < 2 && required_slot == 2 && !manual_bundling_off)
6657 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6659 if (required_slot < i)
6660 /* Can't fit this instruction. */
6661 break;
6663 i = required_slot;
6664 if (required_template != template_val)
6666 /* If we switch the template, we need to reset the NOPs
6667 after slot i. The slot-types of the instructions ahead
6668 of i never change, so we don't need to worry about
6669 changing NOPs in front of this slot. */
6670 for (j = i; j < 3; ++j)
6671 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6673 /* We just picked a template that includes the stop bit in the
6674 middle, so we don't need another one emitted later. */
6675 md.slot[curr].end_of_insn_group = 0;
6677 template_val = required_template;
6679 if (curr != first && md.slot[curr].label_fixups)
6681 if (manual_bundling)
6683 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6684 _("Label must be first in a bundle"));
6685 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6687 /* This insn must go into the first slot of a bundle. */
6688 break;
6691 if (end_of_insn_group && md.num_slots_in_use >= 1)
6693 /* We need an instruction group boundary in the middle of a
6694 bundle. See if we can switch to an other template with
6695 an appropriate boundary. */
6697 orig_template = template_val;
6698 if (i == 1 && (user_template == 4
6699 || (user_template < 0
6700 && (ia64_templ_desc[template_val].exec_unit[0]
6701 == IA64_UNIT_M))))
6703 template_val = 5;
6704 end_of_insn_group = 0;
6706 else if (i == 2 && (user_template == 0
6707 || (user_template < 0
6708 && (ia64_templ_desc[template_val].exec_unit[1]
6709 == IA64_UNIT_I)))
6710 /* This test makes sure we don't switch the template if
6711 the next instruction is one that needs to be first in
6712 an instruction group. Since all those instructions are
6713 in the M group, there is no way such an instruction can
6714 fit in this bundle even if we switch the template. The
6715 reason we have to check for this is that otherwise we
6716 may end up generating "MI;;I M.." which has the deadly
6717 effect that the second M instruction is no longer the
6718 first in the group! --davidm 99/12/16 */
6719 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6721 template_val = 1;
6722 end_of_insn_group = 0;
6724 else if (i == 1
6725 && user_template == 0
6726 && !(idesc->flags & IA64_OPCODE_FIRST))
6727 /* Use the next slot. */
6728 continue;
6729 else if (curr != first)
6730 /* can't fit this insn */
6731 break;
6733 if (template_val != orig_template)
6734 /* if we switch the template, we need to reset the NOPs
6735 after slot i. The slot-types of the instructions ahead
6736 of i never change, so we don't need to worry about
6737 changing NOPs in front of this slot. */
6738 for (j = i; j < 3; ++j)
6739 insn[j] = nop[ia64_templ_desc[template_val].exec_unit[j]];
6741 required_unit = ia64_templ_desc[template_val].exec_unit[i];
6743 /* resolve dynamic opcodes such as "break", "hint", and "nop": */
6744 if (idesc->type == IA64_TYPE_DYN)
6746 enum ia64_opnd opnd1, opnd2;
6748 if ((strcmp (idesc->name, "nop") == 0)
6749 || (strcmp (idesc->name, "break") == 0))
6750 insn_unit = required_unit;
6751 else if (strcmp (idesc->name, "hint") == 0)
6753 insn_unit = required_unit;
6754 if (required_unit == IA64_UNIT_B)
6756 switch (md.hint_b)
6758 case hint_b_ok:
6759 break;
6760 case hint_b_warning:
6761 as_warn (_("hint in B unit may be treated as nop"));
6762 break;
6763 case hint_b_error:
6764 /* When manual bundling is off and there is no
6765 user template, we choose a different unit so
6766 that hint won't go into the current slot. We
6767 will fill the current bundle with nops and
6768 try to put hint into the next bundle. */
6769 if (!manual_bundling && user_template < 0)
6770 insn_unit = IA64_UNIT_I;
6771 else
6772 as_bad (_("hint in B unit can't be used"));
6773 break;
6777 else if (strcmp (idesc->name, "chk.s") == 0
6778 || strcmp (idesc->name, "mov") == 0)
6780 insn_unit = IA64_UNIT_M;
6781 if (required_unit == IA64_UNIT_I
6782 || (required_unit == IA64_UNIT_F && template_val == 6))
6783 insn_unit = IA64_UNIT_I;
6785 else
6786 as_fatal (_("emit_one_bundle: unexpected dynamic op"));
6788 snprintf (mnemonic, sizeof (mnemonic), "%s.%c",
6789 idesc->name, "?imbfxx"[insn_unit]);
6790 opnd1 = idesc->operands[0];
6791 opnd2 = idesc->operands[1];
6792 ia64_free_opcode (idesc);
6793 idesc = ia64_find_opcode (mnemonic);
6794 /* moves to/from ARs have collisions */
6795 if (opnd1 == IA64_OPND_AR3 || opnd2 == IA64_OPND_AR3)
6797 while (idesc != NULL
6798 && (idesc->operands[0] != opnd1
6799 || idesc->operands[1] != opnd2))
6800 idesc = get_next_opcode (idesc);
6802 md.slot[curr].idesc = idesc;
6804 else
6806 insn_type = idesc->type;
6807 insn_unit = IA64_UNIT_NIL;
6808 switch (insn_type)
6810 case IA64_TYPE_A:
6811 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6812 insn_unit = required_unit;
6813 break;
6814 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6815 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6816 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6817 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6818 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6819 default: break;
6823 if (insn_unit != required_unit)
6824 continue; /* Try next slot. */
6826 /* Now is a good time to fix up the labels for this insn. */
6827 mark_label = false;
6828 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6830 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6831 symbol_set_frag (lfix->sym, frag_now);
6832 mark_label |= lfix->dw2_mark_labels;
6834 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6836 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6837 symbol_set_frag (lfix->sym, frag_now);
6840 if (debug_type == DEBUG_DWARF2
6841 || md.slot[curr].loc_directive_seen
6842 || mark_label)
6844 bfd_vma addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6846 md.slot[curr].loc_directive_seen = 0;
6847 if (mark_label)
6848 md.slot[curr].debug_line.flags |= DWARF2_FLAG_BASIC_BLOCK;
6850 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6853 build_insn (md.slot + curr, insn + i);
6855 ptr = md.slot[curr].unwind_record;
6856 if (ptr)
6858 /* Set slot numbers for all remaining unwind records belonging to the
6859 current insn. There can not be any prologue/body unwind records
6860 here. */
6861 for (; ptr != end_ptr; ptr = ptr->next)
6863 ptr->slot_number = (unsigned long) f + i;
6864 ptr->slot_frag = frag_now;
6866 md.slot[curr].unwind_record = NULL;
6869 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6871 unsigned long where;
6873 ifix = md.slot[curr].fixup + j;
6874 where = frag_now_fix () - 16 + i;
6875 #ifdef TE_HPUX
6876 /* Relocations for instructions specify the slot in the
6877 bottom two bits of r_offset. The IA64 HP-UX linker
6878 expects PCREL60B relocations to specify slot 2 of an
6879 instruction. gas generates PCREL60B against slot 1. */
6880 if (ifix->code == BFD_RELOC_IA64_PCREL60B)
6882 know (i == 1);
6883 ++where;
6885 #endif
6887 fix = fix_new_exp (frag_now, where, 8,
6888 &ifix->expr, ifix->is_pcrel, ifix->code);
6889 fix->tc_fix_data.opnd = ifix->opnd;
6890 fix->fx_file = md.slot[curr].src_file;
6891 fix->fx_line = md.slot[curr].src_line;
6894 end_of_insn_group = md.slot[curr].end_of_insn_group;
6896 /* This adjustment to "i" must occur after the fix, otherwise the fix
6897 is assigned to the wrong slot, and the VMS linker complains. */
6898 if (required_unit == IA64_UNIT_L)
6900 know (i == 1);
6901 /* skip one slot for long/X-unit instructions */
6902 ++i;
6904 --md.num_slots_in_use;
6905 last_slot = i;
6907 /* clear slot: */
6908 ia64_free_opcode (md.slot[curr].idesc);
6909 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6910 md.slot[curr].user_template = -1;
6912 if (manual_bundling_off)
6914 manual_bundling = 0;
6915 break;
6917 curr = (curr + 1) % NUM_SLOTS;
6918 idesc = md.slot[curr].idesc;
6921 /* A user template was specified, but the first following instruction did
6922 not fit. This can happen with or without manual bundling. */
6923 if (md.num_slots_in_use > 0 && last_slot < 0)
6925 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6926 _("`%s' does not fit into %s template"),
6927 idesc->name, ia64_templ_desc[template_val].name);
6928 /* Drop first insn so we don't livelock. */
6929 --md.num_slots_in_use;
6930 know (curr == first);
6931 ia64_free_opcode (md.slot[curr].idesc);
6932 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6933 md.slot[curr].user_template = -1;
6935 else if (manual_bundling > 0)
6937 if (md.num_slots_in_use > 0)
6939 if (last_slot >= 2)
6940 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6941 _("`%s' does not fit into bundle"), idesc->name);
6942 else
6944 const char *where;
6946 if (template_val == 2)
6947 where = "X slot";
6948 else if (last_slot == 0)
6949 where = "slots 2 or 3";
6950 else
6951 where = "slot 3";
6952 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6953 _("`%s' can't go in %s of %s template"),
6954 idesc->name, where, ia64_templ_desc[template_val].name);
6957 else
6958 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6959 _("Missing '}' at end of file"));
6962 know (md.num_slots_in_use < NUM_SLOTS);
6964 t0 = end_of_insn_group | (template_val << 1) | (insn[0] << 5) | (insn[1] << 46);
6965 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6967 number_to_chars_littleendian (f + 0, t0, 8);
6968 number_to_chars_littleendian (f + 8, t1, 8);
6972 md_parse_option (int c, const char *arg)
6975 switch (c)
6977 /* Switches from the Intel assembler. */
6978 case 'm':
6979 if (strcmp (arg, "ilp64") == 0
6980 || strcmp (arg, "lp64") == 0
6981 || strcmp (arg, "p64") == 0)
6983 md.flags |= EF_IA_64_ABI64;
6985 else if (strcmp (arg, "ilp32") == 0)
6987 md.flags &= ~EF_IA_64_ABI64;
6989 else if (strcmp (arg, "le") == 0)
6991 md.flags &= ~EF_IA_64_BE;
6992 default_big_endian = 0;
6994 else if (strcmp (arg, "be") == 0)
6996 md.flags |= EF_IA_64_BE;
6997 default_big_endian = 1;
6999 else if (startswith (arg, "unwind-check="))
7001 arg += 13;
7002 if (strcmp (arg, "warning") == 0)
7003 md.unwind_check = unwind_check_warning;
7004 else if (strcmp (arg, "error") == 0)
7005 md.unwind_check = unwind_check_error;
7006 else
7007 return 0;
7009 else if (startswith (arg, "hint.b="))
7011 arg += 7;
7012 if (strcmp (arg, "ok") == 0)
7013 md.hint_b = hint_b_ok;
7014 else if (strcmp (arg, "warning") == 0)
7015 md.hint_b = hint_b_warning;
7016 else if (strcmp (arg, "error") == 0)
7017 md.hint_b = hint_b_error;
7018 else
7019 return 0;
7021 else if (startswith (arg, "tune="))
7023 arg += 5;
7024 if (strcmp (arg, "itanium1") == 0)
7025 md.tune = itanium1;
7026 else if (strcmp (arg, "itanium2") == 0)
7027 md.tune = itanium2;
7028 else
7029 return 0;
7031 else
7032 return 0;
7033 break;
7035 case 'N':
7036 if (strcmp (arg, "so") == 0)
7038 /* Suppress signon message. */
7040 else if (strcmp (arg, "pi") == 0)
7042 /* Reject privileged instructions. FIXME */
7044 else if (strcmp (arg, "us") == 0)
7046 /* Allow union of signed and unsigned range. FIXME */
7048 else if (strcmp (arg, "close_fcalls") == 0)
7050 /* Do not resolve global function calls. */
7052 else
7053 return 0;
7054 break;
7056 case 'C':
7057 /* temp[="prefix"] Insert temporary labels into the object file
7058 symbol table prefixed by "prefix".
7059 Default prefix is ":temp:".
7061 break;
7063 case 'a':
7064 /* indirect=<tgt> Assume unannotated indirect branches behavior
7065 according to <tgt> --
7066 exit: branch out from the current context (default)
7067 labels: all labels in context may be branch targets
7069 if (!startswith (arg, "indirect="))
7070 return 0;
7071 break;
7073 case 'x':
7074 /* -X conflicts with an ignored option, use -x instead */
7075 md.detect_dv = 1;
7076 if (!arg || strcmp (arg, "explicit") == 0)
7078 /* set default mode to explicit */
7079 md.default_explicit_mode = 1;
7080 break;
7082 else if (strcmp (arg, "auto") == 0)
7084 md.default_explicit_mode = 0;
7086 else if (strcmp (arg, "none") == 0)
7088 md.detect_dv = 0;
7090 else if (strcmp (arg, "debug") == 0)
7092 md.debug_dv = 1;
7094 else if (strcmp (arg, "debugx") == 0)
7096 md.default_explicit_mode = 1;
7097 md.debug_dv = 1;
7099 else if (strcmp (arg, "debugn") == 0)
7101 md.debug_dv = 1;
7102 md.detect_dv = 0;
7104 else
7106 as_bad (_("Unrecognized option '-x%s'"), arg);
7108 break;
7110 case 'S':
7111 /* nops Print nops statistics. */
7112 break;
7114 /* GNU specific switches for gcc. */
7115 case OPTION_MCONSTANT_GP:
7116 md.flags |= EF_IA_64_CONS_GP;
7117 break;
7119 case OPTION_MAUTO_PIC:
7120 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
7121 break;
7123 default:
7124 return 0;
7127 return 1;
7130 void
7131 md_show_usage (FILE *stream)
7133 fputs (_("\
7134 IA-64 options:\n\
7135 --mconstant-gp mark output file as using the constant-GP model\n\
7136 (sets ELF header flag EF_IA_64_CONS_GP)\n\
7137 --mauto-pic mark output file as using the constant-GP model\n\
7138 without function descriptors (sets ELF header flag\n\
7139 EF_IA_64_NOFUNCDESC_CONS_GP)\n\
7140 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
7141 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
7142 -mtune=[itanium1|itanium2]\n\
7143 tune for a specific CPU (default -mtune=itanium2)\n\
7144 -munwind-check=[warning|error]\n\
7145 unwind directive check (default -munwind-check=warning)\n\
7146 -mhint.b=[ok|warning|error]\n\
7147 hint.b check (default -mhint.b=error)\n\
7148 -x | -xexplicit turn on dependency violation checking\n"), stream);
7149 /* Note for translators: "automagically" can be translated as "automatically" here. */
7150 fputs (_("\
7151 -xauto automagically remove dependency violations (default)\n\
7152 -xnone turn off dependency violation checking\n\
7153 -xdebug debug dependency violation checker\n\
7154 -xdebugn debug dependency violation checker but turn off\n\
7155 dependency violation checking\n\
7156 -xdebugx debug dependency violation checker and turn on\n\
7157 dependency violation checking\n"),
7158 stream);
7161 void
7162 ia64_after_parse_args (void)
7164 if (debug_type == DEBUG_STABS)
7165 as_fatal (_("--gstabs is not supported for ia64"));
7168 /* Return true if TYPE fits in TEMPL at SLOT. */
7170 static int
7171 match (int templ, int type, int slot)
7173 enum ia64_unit unit;
7174 int result;
7176 unit = ia64_templ_desc[templ].exec_unit[slot];
7177 switch (type)
7179 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
7180 case IA64_TYPE_A:
7181 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
7182 break;
7183 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
7184 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
7185 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
7186 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
7187 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
7188 default: result = 0; break;
7190 return result;
7193 /* For Itanium 1, add a bit of extra goodness if a nop of type F or B would fit
7194 in TEMPL at SLOT. For Itanium 2, add a bit of extra goodness if a nop of
7195 type M or I would fit in TEMPL at SLOT. */
7197 static inline int
7198 extra_goodness (int templ, int slot)
7200 switch (md.tune)
7202 case itanium1:
7203 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
7204 return 2;
7205 else if (slot == 2 && match (templ, IA64_TYPE_B, slot))
7206 return 1;
7207 else
7208 return 0;
7209 break;
7210 case itanium2:
7211 if (match (templ, IA64_TYPE_M, slot)
7212 || match (templ, IA64_TYPE_I, slot))
7213 /* Favor M- and I-unit NOPs. We definitely want to avoid
7214 F-unit and B-unit may cause split-issue or less-than-optimal
7215 branch-prediction. */
7216 return 2;
7217 else
7218 return 0;
7219 break;
7220 default:
7221 abort ();
7222 return 0;
7226 /* This function is called once, at assembler startup time. It sets
7227 up all the tables, etc. that the MD part of the assembler will need
7228 that can be determined before arguments are parsed. */
7229 void
7230 md_begin (void)
7232 int i, j, k, t, goodness, best, ok;
7234 md.auto_align = 1;
7235 md.explicit_mode = md.default_explicit_mode;
7237 bfd_set_section_alignment (text_section, 4);
7239 /* Make sure function pointers get initialized. */
7240 target_big_endian = -1;
7241 dot_byteorder (default_big_endian);
7243 alias_hash = str_htab_create ();
7244 alias_name_hash = str_htab_create ();
7245 secalias_hash = str_htab_create ();
7246 secalias_name_hash = str_htab_create ();
7248 pseudo_func[FUNC_DTP_MODULE].u.sym =
7249 symbol_new (".<dtpmod>", undefined_section,
7250 &zero_address_frag, FUNC_DTP_MODULE);
7252 pseudo_func[FUNC_DTP_RELATIVE].u.sym =
7253 symbol_new (".<dtprel>", undefined_section,
7254 &zero_address_frag, FUNC_DTP_RELATIVE);
7256 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
7257 symbol_new (".<fptr>", undefined_section,
7258 &zero_address_frag, FUNC_FPTR_RELATIVE);
7260 pseudo_func[FUNC_GP_RELATIVE].u.sym =
7261 symbol_new (".<gprel>", undefined_section,
7262 &zero_address_frag, FUNC_GP_RELATIVE);
7264 pseudo_func[FUNC_LT_RELATIVE].u.sym =
7265 symbol_new (".<ltoff>", undefined_section,
7266 &zero_address_frag, FUNC_LT_RELATIVE);
7268 pseudo_func[FUNC_LT_RELATIVE_X].u.sym =
7269 symbol_new (".<ltoffx>", undefined_section,
7270 &zero_address_frag, FUNC_LT_RELATIVE_X);
7272 pseudo_func[FUNC_PC_RELATIVE].u.sym =
7273 symbol_new (".<pcrel>", undefined_section,
7274 &zero_address_frag, FUNC_PC_RELATIVE);
7276 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
7277 symbol_new (".<pltoff>", undefined_section,
7278 &zero_address_frag, FUNC_PLT_RELATIVE);
7280 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
7281 symbol_new (".<secrel>", undefined_section,
7282 &zero_address_frag, FUNC_SEC_RELATIVE);
7284 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
7285 symbol_new (".<segrel>", undefined_section,
7286 &zero_address_frag, FUNC_SEG_RELATIVE);
7288 pseudo_func[FUNC_TP_RELATIVE].u.sym =
7289 symbol_new (".<tprel>", undefined_section,
7290 &zero_address_frag, FUNC_TP_RELATIVE);
7292 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
7293 symbol_new (".<ltv>", undefined_section,
7294 &zero_address_frag, FUNC_LTV_RELATIVE);
7296 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
7297 symbol_new (".<ltoff.fptr>", undefined_section,
7298 &zero_address_frag, FUNC_LT_FPTR_RELATIVE);
7300 pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
7301 symbol_new (".<ltoff.dtpmod>", undefined_section,
7302 &zero_address_frag, FUNC_LT_DTP_MODULE);
7304 pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
7305 symbol_new (".<ltoff.dptrel>", undefined_section,
7306 &zero_address_frag, FUNC_LT_DTP_RELATIVE);
7308 pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
7309 symbol_new (".<ltoff.tprel>", undefined_section,
7310 &zero_address_frag, FUNC_LT_TP_RELATIVE);
7312 pseudo_func[FUNC_IPLT_RELOC].u.sym =
7313 symbol_new (".<iplt>", undefined_section,
7314 &zero_address_frag, FUNC_IPLT_RELOC);
7316 #ifdef TE_VMS
7317 pseudo_func[FUNC_SLOTCOUNT_RELOC].u.sym =
7318 symbol_new (".<slotcount>", undefined_section,
7319 &zero_address_frag, FUNC_SLOTCOUNT_RELOC);
7320 #endif
7322 if (md.tune != itanium1)
7324 /* Convert MFI NOPs bundles into MMI NOPs bundles. */
7325 le_nop[0] = 0x8;
7326 le_nop_stop[0] = 0x9;
7329 /* Compute the table of best templates. We compute goodness as a
7330 base 4 value, in which each match counts for 3. Match-failures
7331 result in NOPs and we use extra_goodness() to pick the execution
7332 units that are best suited for issuing the NOP. */
7333 for (i = 0; i < IA64_NUM_TYPES; ++i)
7334 for (j = 0; j < IA64_NUM_TYPES; ++j)
7335 for (k = 0; k < IA64_NUM_TYPES; ++k)
7337 best = 0;
7338 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
7340 goodness = 0;
7341 if (match (t, i, 0))
7343 if (match (t, j, 1))
7345 if ((t == 2 && j == IA64_TYPE_X) || match (t, k, 2))
7346 goodness = 3 + 3 + 3;
7347 else
7348 goodness = 3 + 3 + extra_goodness (t, 2);
7350 else if (match (t, j, 2))
7351 goodness = 3 + 3 + extra_goodness (t, 1);
7352 else
7354 goodness = 3;
7355 goodness += extra_goodness (t, 1);
7356 goodness += extra_goodness (t, 2);
7359 else if (match (t, i, 1))
7361 if ((t == 2 && i == IA64_TYPE_X) || match (t, j, 2))
7362 goodness = 3 + 3;
7363 else
7364 goodness = 3 + extra_goodness (t, 2);
7366 else if (match (t, i, 2))
7367 goodness = 3 + extra_goodness (t, 1);
7369 if (goodness > best)
7371 best = goodness;
7372 best_template[i][j][k] = t;
7377 #ifdef DEBUG_TEMPLATES
7378 /* For debugging changes to the best_template calculations. We don't care
7379 about combinations with invalid instructions, so start the loops at 1. */
7380 for (i = 0; i < IA64_NUM_TYPES; ++i)
7381 for (j = 0; j < IA64_NUM_TYPES; ++j)
7382 for (k = 0; k < IA64_NUM_TYPES; ++k)
7384 char type_letter[IA64_NUM_TYPES] = { 'n', 'a', 'i', 'm', 'b', 'f',
7385 'x', 'd' };
7386 fprintf (stderr, "%c%c%c %s\n", type_letter[i], type_letter[j],
7387 type_letter[k],
7388 ia64_templ_desc[best_template[i][j][k]].name);
7390 #endif
7392 for (i = 0; i < NUM_SLOTS; ++i)
7393 md.slot[i].user_template = -1;
7395 md.pseudo_hash = str_htab_create ();
7396 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
7397 if (str_hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
7398 pseudo_opcode + i, 0) != NULL)
7399 as_fatal (_("duplicate %s"), pseudo_opcode[i].name);
7401 md.reg_hash = str_htab_create ();
7402 md.dynreg_hash = str_htab_create ();
7403 md.const_hash = str_htab_create ();
7404 md.entry_hash = str_htab_create ();
7406 /* general registers: */
7407 declare_register_set ("r", 128, REG_GR);
7408 declare_register ("gp", REG_GR + 1);
7409 declare_register ("sp", REG_GR + 12);
7410 declare_register ("tp", REG_GR + 13);
7411 declare_register_set ("ret", 4, REG_GR + 8);
7413 /* floating point registers: */
7414 declare_register_set ("f", 128, REG_FR);
7415 declare_register_set ("farg", 8, REG_FR + 8);
7416 declare_register_set ("fret", 8, REG_FR + 8);
7418 /* branch registers: */
7419 declare_register_set ("b", 8, REG_BR);
7420 declare_register ("rp", REG_BR + 0);
7422 /* predicate registers: */
7423 declare_register_set ("p", 64, REG_P);
7424 declare_register ("pr", REG_PR);
7425 declare_register ("pr.rot", REG_PR_ROT);
7427 /* application registers: */
7428 declare_register_set ("ar", 128, REG_AR);
7429 for (i = 0; i < NELEMS (ar); ++i)
7430 declare_register (ar[i].name, REG_AR + ar[i].regnum);
7432 /* control registers: */
7433 declare_register_set ("cr", 128, REG_CR);
7434 for (i = 0; i < NELEMS (cr); ++i)
7435 declare_register (cr[i].name, REG_CR + cr[i].regnum);
7437 /* dahr registers: */
7438 declare_register_set ("dahr", 8, REG_DAHR);
7440 declare_register ("ip", REG_IP);
7441 declare_register ("cfm", REG_CFM);
7442 declare_register ("psr", REG_PSR);
7443 declare_register ("psr.l", REG_PSR_L);
7444 declare_register ("psr.um", REG_PSR_UM);
7446 for (i = 0; i < NELEMS (indirect_reg); ++i)
7448 unsigned int regnum = indirect_reg[i].regnum;
7450 md.indregsym[regnum - IND_CPUID] = declare_register (indirect_reg[i].name, regnum);
7453 /* pseudo-registers used to specify unwind info: */
7454 declare_register ("psp", REG_PSP);
7456 for (i = 0; i < NELEMS (const_bits); ++i)
7457 if (str_hash_insert (md.const_hash, const_bits[i].name, const_bits + i, 0))
7458 as_fatal (_("duplicate %s"), const_bits[i].name);
7460 /* Set the architecture and machine depending on defaults and command line
7461 options. */
7462 if (md.flags & EF_IA_64_ABI64)
7463 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
7464 else
7465 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
7467 if (! ok)
7468 as_warn (_("Could not set architecture and machine"));
7470 /* Set the pointer size and pointer shift size depending on md.flags */
7472 if (md.flags & EF_IA_64_ABI64)
7474 md.pointer_size = 8; /* pointers are 8 bytes */
7475 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
7477 else
7479 md.pointer_size = 4; /* pointers are 4 bytes */
7480 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
7483 md.mem_offset.hint = 0;
7484 md.path = 0;
7485 md.maxpaths = 0;
7486 md.entry_labels = NULL;
7489 /* Set the default options in md. Cannot do this in md_begin because
7490 that is called after md_parse_option which is where we set the
7491 options in md based on command line options. */
7493 void
7494 ia64_init (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
7496 md.flags = MD_FLAGS_DEFAULT;
7497 #ifndef TE_VMS
7498 /* Don't turn on dependency checking for VMS, doesn't work. */
7499 md.detect_dv = 1;
7500 #endif
7501 /* FIXME: We should change it to unwind_check_error someday. */
7502 md.unwind_check = unwind_check_warning;
7503 md.hint_b = hint_b_error;
7504 md.tune = itanium2;
7507 /* Return a string for the target object file format. */
7509 const char *
7510 ia64_target_format (void)
7512 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
7514 if (md.flags & EF_IA_64_BE)
7516 if (md.flags & EF_IA_64_ABI64)
7517 #if defined(TE_AIX50)
7518 return "elf64-ia64-aix-big";
7519 #elif defined(TE_HPUX)
7520 return "elf64-ia64-hpux-big";
7521 #else
7522 return "elf64-ia64-big";
7523 #endif
7524 else
7525 #if defined(TE_AIX50)
7526 return "elf32-ia64-aix-big";
7527 #elif defined(TE_HPUX)
7528 return "elf32-ia64-hpux-big";
7529 #else
7530 return "elf32-ia64-big";
7531 #endif
7533 else
7535 if (md.flags & EF_IA_64_ABI64)
7536 #if defined (TE_AIX50)
7537 return "elf64-ia64-aix-little";
7538 #elif defined (TE_VMS)
7540 md.flags |= EF_IA_64_ARCHVER_1;
7541 return "elf64-ia64-vms";
7543 #else
7544 return "elf64-ia64-little";
7545 #endif
7546 else
7547 #ifdef TE_AIX50
7548 return "elf32-ia64-aix-little";
7549 #else
7550 return "elf32-ia64-little";
7551 #endif
7554 else
7555 return "unknown-format";
7558 void
7559 ia64_md_finish (void)
7561 /* terminate insn group upon reaching end of file: */
7562 insn_group_break (1, 0, 0);
7564 /* emits slots we haven't written yet: */
7565 ia64_flush_insns ();
7567 bfd_set_private_flags (stdoutput, md.flags);
7569 md.mem_offset.hint = 0;
7572 void
7573 ia64_start_line (void)
7575 static int first;
7577 if (!first) {
7578 /* Make sure we don't reference input_line_pointer[-1] when that's
7579 not valid. */
7580 first = 1;
7581 return;
7584 if (md.qp.X_op == O_register)
7585 as_bad (_("qualifying predicate not followed by instruction"));
7586 md.qp.X_op = O_absent;
7588 if (ignore_input ())
7589 return;
7591 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
7593 if (md.detect_dv && !md.explicit_mode)
7595 static int warned;
7597 if (!warned)
7599 warned = 1;
7600 as_warn (_("Explicit stops are ignored in auto mode"));
7603 else
7604 insn_group_break (1, 0, 0);
7606 else if (input_line_pointer[-1] == '{')
7608 if (md.manual_bundling)
7609 as_warn (_("Found '{' when manual bundling is already turned on"));
7610 else
7611 CURR_SLOT.manual_bundling_on = 1;
7612 md.manual_bundling = 1;
7614 /* Bundling is only acceptable in explicit mode
7615 or when in default automatic mode. */
7616 if (md.detect_dv && !md.explicit_mode)
7618 if (!md.mode_explicitly_set
7619 && !md.default_explicit_mode)
7620 dot_dv_mode ('E');
7621 else
7622 as_warn (_("Found '{' after explicit switch to automatic mode"));
7625 else if (input_line_pointer[-1] == '}')
7627 if (!md.manual_bundling)
7628 as_warn (_("Found '}' when manual bundling is off"));
7629 else
7630 PREV_SLOT.manual_bundling_off = 1;
7631 md.manual_bundling = 0;
7633 /* switch back to automatic mode, if applicable */
7634 if (md.detect_dv
7635 && md.explicit_mode
7636 && !md.mode_explicitly_set
7637 && !md.default_explicit_mode)
7638 dot_dv_mode ('A');
7642 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
7643 labels. */
7644 static int defining_tag = 0;
7647 ia64_unrecognized_line (int ch)
7649 switch (ch)
7651 case '(':
7652 expression_and_evaluate (&md.qp);
7653 if (*input_line_pointer++ != ')')
7655 as_bad (_("Expected ')'"));
7656 return 0;
7658 if (md.qp.X_op != O_register)
7660 as_bad (_("Qualifying predicate expected"));
7661 return 0;
7663 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
7665 as_bad (_("Predicate register expected"));
7666 return 0;
7668 return 1;
7670 case '[':
7672 char *s;
7673 char c;
7674 symbolS *tag;
7675 int temp;
7677 if (md.qp.X_op == O_register)
7679 as_bad (_("Tag must come before qualifying predicate."));
7680 return 0;
7683 /* This implements just enough of read_a_source_file in read.c to
7684 recognize labels. */
7685 if (is_name_beginner (*input_line_pointer))
7687 c = get_symbol_name (&s);
7689 else if (LOCAL_LABELS_FB
7690 && ISDIGIT (*input_line_pointer))
7692 temp = 0;
7693 while (ISDIGIT (*input_line_pointer))
7694 temp = (temp * 10) + *input_line_pointer++ - '0';
7695 fb_label_instance_inc (temp);
7696 s = fb_label_name (temp, 0);
7697 c = *input_line_pointer;
7699 else
7701 s = NULL;
7702 c = '\0';
7704 if (c != ':')
7706 /* Put ':' back for error messages' sake. */
7707 *input_line_pointer++ = ':';
7708 as_bad (_("Expected ':'"));
7709 return 0;
7712 defining_tag = 1;
7713 tag = colon (s);
7714 defining_tag = 0;
7715 /* Put ':' back for error messages' sake. */
7716 *input_line_pointer++ = ':';
7717 if (*input_line_pointer++ != ']')
7719 as_bad (_("Expected ']'"));
7720 return 0;
7722 if (! tag)
7724 as_bad (_("Tag name expected"));
7725 return 0;
7727 return 1;
7730 default:
7731 break;
7734 /* Not a valid line. */
7735 return 0;
7738 void
7739 ia64_frob_label (struct symbol *sym)
7741 struct label_fix *fix;
7743 /* Tags need special handling since they are not bundle breaks like
7744 labels. */
7745 if (defining_tag)
7747 fix = XOBNEW (&notes, struct label_fix);
7748 fix->sym = sym;
7749 fix->next = CURR_SLOT.tag_fixups;
7750 fix->dw2_mark_labels = false;
7751 CURR_SLOT.tag_fixups = fix;
7753 return;
7756 if (bfd_section_flags (now_seg) & SEC_CODE)
7758 md.last_text_seg = now_seg;
7759 md.last_text_subseg = now_subseg;
7760 fix = XOBNEW (&notes, struct label_fix);
7761 fix->sym = sym;
7762 fix->next = CURR_SLOT.label_fixups;
7763 fix->dw2_mark_labels = dwarf2_loc_mark_labels;
7764 CURR_SLOT.label_fixups = fix;
7766 /* Keep track of how many code entry points we've seen. */
7767 if (md.path == md.maxpaths)
7769 md.maxpaths += 20;
7770 md.entry_labels = XRESIZEVEC (const char *, md.entry_labels,
7771 md.maxpaths);
7773 md.entry_labels[md.path++] = S_GET_NAME (sym);
7777 #ifdef TE_HPUX
7778 /* The HP-UX linker will give unresolved symbol errors for symbols
7779 that are declared but unused. This routine removes declared,
7780 unused symbols from an object. */
7782 ia64_frob_symbol (struct symbol *sym)
7784 if ((S_GET_SEGMENT (sym) == bfd_und_section_ptr && ! symbol_used_p (sym) &&
7785 ELF_ST_VISIBILITY (S_GET_OTHER (sym)) == STV_DEFAULT)
7786 || (S_GET_SEGMENT (sym) == bfd_abs_section_ptr
7787 && ! S_IS_EXTERNAL (sym)))
7788 return 1;
7789 return 0;
7791 #endif
7793 void
7794 ia64_flush_pending_output (void)
7796 if (!md.keep_pending_output
7797 && bfd_section_flags (now_seg) & SEC_CODE)
7799 /* ??? This causes many unnecessary stop bits to be emitted.
7800 Unfortunately, it isn't clear if it is safe to remove this. */
7801 insn_group_break (1, 0, 0);
7802 ia64_flush_insns ();
7806 /* Do ia64-specific expression optimization. All that's done here is
7807 to transform index expressions that are either due to the indexing
7808 of rotating registers or due to the indexing of indirect register
7809 sets. */
7811 ia64_optimize_expr (expressionS *l, operatorT op, expressionS *r)
7813 if (op != O_index)
7814 return 0;
7815 resolve_expression (l);
7816 if (l->X_op == O_register)
7818 unsigned num_regs = l->X_add_number >> 16;
7820 resolve_expression (r);
7821 if (num_regs)
7823 /* Left side is a .rotX-allocated register. */
7824 if (r->X_op != O_constant)
7826 as_bad (_("Rotating register index must be a non-negative constant"));
7827 r->X_add_number = 0;
7829 else if ((valueT) r->X_add_number >= num_regs)
7831 as_bad (_("Index out of range 0..%u"), num_regs - 1);
7832 r->X_add_number = 0;
7834 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7835 return 1;
7837 else if (l->X_add_number >= IND_CPUID && l->X_add_number <= IND_RR)
7839 if (r->X_op != O_register
7840 || r->X_add_number < REG_GR
7841 || r->X_add_number > REG_GR + 127)
7843 as_bad (_("Indirect register index must be a general register"));
7844 r->X_add_number = REG_GR;
7846 l->X_op = O_index;
7847 l->X_op_symbol = md.indregsym[l->X_add_number - IND_CPUID];
7848 l->X_add_number = r->X_add_number;
7849 return 1;
7852 as_bad (_("Index can only be applied to rotating or indirect registers"));
7853 /* Fall back to some register use of which has as little as possible
7854 side effects, to minimize subsequent error messages. */
7855 l->X_op = O_register;
7856 l->X_add_number = REG_GR + 3;
7857 return 1;
7861 ia64_parse_name (char *name, expressionS *e, char *nextcharP)
7863 struct const_desc *cdesc;
7864 struct dynreg *dr = 0;
7865 unsigned int idx;
7866 struct symbol *sym;
7867 char *end;
7869 if (*name == '@')
7871 enum pseudo_type pseudo_type = PSEUDO_FUNC_NONE;
7873 /* Find what relocation pseudo-function we're dealing with. */
7874 for (idx = 0; idx < NELEMS (pseudo_func); ++idx)
7875 if (pseudo_func[idx].name
7876 && pseudo_func[idx].name[0] == name[1]
7877 && strcmp (pseudo_func[idx].name + 1, name + 2) == 0)
7879 pseudo_type = pseudo_func[idx].type;
7880 break;
7882 switch (pseudo_type)
7884 case PSEUDO_FUNC_RELOC:
7885 end = input_line_pointer;
7886 if (*nextcharP != '(')
7888 as_bad (_("Expected '('"));
7889 break;
7891 /* Skip '('. */
7892 ++input_line_pointer;
7893 expression (e);
7894 if (*input_line_pointer != ')')
7896 as_bad (_("Missing ')'"));
7897 goto done;
7899 /* Skip ')'. */
7900 ++input_line_pointer;
7901 #ifdef TE_VMS
7902 if (idx == FUNC_SLOTCOUNT_RELOC)
7904 /* @slotcount can accept any expression. Canonicalize. */
7905 e->X_add_symbol = make_expr_symbol (e);
7906 e->X_op = O_symbol;
7907 e->X_add_number = 0;
7909 #endif
7910 if (e->X_op != O_symbol)
7912 if (e->X_op != O_pseudo_fixup)
7914 as_bad (_("Not a symbolic expression"));
7915 goto done;
7917 if (idx != FUNC_LT_RELATIVE)
7919 as_bad (_("Illegal combination of relocation functions"));
7920 goto done;
7922 switch (S_GET_VALUE (e->X_op_symbol))
7924 case FUNC_FPTR_RELATIVE:
7925 idx = FUNC_LT_FPTR_RELATIVE; break;
7926 case FUNC_DTP_MODULE:
7927 idx = FUNC_LT_DTP_MODULE; break;
7928 case FUNC_DTP_RELATIVE:
7929 idx = FUNC_LT_DTP_RELATIVE; break;
7930 case FUNC_TP_RELATIVE:
7931 idx = FUNC_LT_TP_RELATIVE; break;
7932 default:
7933 as_bad (_("Illegal combination of relocation functions"));
7934 goto done;
7937 /* Make sure gas doesn't get rid of local symbols that are used
7938 in relocs. */
7939 e->X_op = O_pseudo_fixup;
7940 e->X_op_symbol = pseudo_func[idx].u.sym;
7941 done:
7942 *nextcharP = *input_line_pointer;
7943 break;
7945 case PSEUDO_FUNC_CONST:
7946 e->X_op = O_constant;
7947 e->X_add_number = pseudo_func[idx].u.ival;
7948 break;
7950 case PSEUDO_FUNC_REG:
7951 e->X_op = O_register;
7952 e->X_add_number = pseudo_func[idx].u.ival;
7953 break;
7955 default:
7956 return 0;
7958 return 1;
7961 /* first see if NAME is a known register name: */
7962 sym = str_hash_find (md.reg_hash, name);
7963 if (sym)
7965 e->X_op = O_register;
7966 e->X_add_number = S_GET_VALUE (sym);
7967 return 1;
7970 cdesc = str_hash_find (md.const_hash, name);
7971 if (cdesc)
7973 e->X_op = O_constant;
7974 e->X_add_number = cdesc->value;
7975 return 1;
7978 /* check for inN, locN, or outN: */
7979 idx = 0;
7980 switch (name[0])
7982 case 'i':
7983 if (name[1] == 'n' && ISDIGIT (name[2]))
7985 dr = &md.in;
7986 idx = 2;
7988 break;
7990 case 'l':
7991 if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7993 dr = &md.loc;
7994 idx = 3;
7996 break;
7998 case 'o':
7999 if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
8001 dr = &md.out;
8002 idx = 3;
8004 break;
8006 default:
8007 break;
8010 /* Ignore register numbers with leading zeroes, except zero itself. */
8011 if (dr && (name[idx] != '0' || name[idx + 1] == '\0'))
8013 unsigned long regnum;
8015 /* The name is inN, locN, or outN; parse the register number. */
8016 regnum = strtoul (name + idx, &end, 10);
8017 if (end > name + idx && *end == '\0' && regnum < 96)
8019 if (regnum >= dr->num_regs)
8021 if (!dr->num_regs)
8022 as_bad (_("No current frame"));
8023 else
8024 as_bad (_("Register number out of range 0..%u"),
8025 dr->num_regs - 1);
8026 regnum = 0;
8028 e->X_op = O_register;
8029 e->X_add_number = dr->base + regnum;
8030 return 1;
8034 end = xstrdup (name);
8035 name = ia64_canonicalize_symbol_name (end);
8036 if ((dr = str_hash_find (md.dynreg_hash, name)))
8038 /* We've got ourselves the name of a rotating register set.
8039 Store the base register number in the low 16 bits of
8040 X_add_number and the size of the register set in the top 16
8041 bits. */
8042 e->X_op = O_register;
8043 e->X_add_number = dr->base | (dr->num_regs << 16);
8044 free (end);
8045 return 1;
8047 free (end);
8048 return 0;
8051 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
8053 char *
8054 ia64_canonicalize_symbol_name (char *name)
8056 size_t len = strlen (name), full = len;
8058 while (len > 0 && name[len - 1] == '#')
8059 --len;
8060 if (len <= 0)
8062 if (full > 0)
8063 as_bad (_("Standalone `#' is illegal"));
8065 else if (len < full - 1)
8066 as_warn (_("Redundant `#' suffix operators"));
8067 name[len] = '\0';
8068 return name;
8071 /* Return true if idesc is a conditional branch instruction. This excludes
8072 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
8073 because they always read/write resources regardless of the value of the
8074 qualifying predicate. br.ia must always use p0, and hence is always
8075 taken. Thus this function returns true for branches which can fall
8076 through, and which use no resources if they do fall through. */
8078 static int
8079 is_conditional_branch (struct ia64_opcode *idesc)
8081 /* br is a conditional branch. Everything that starts with br. except
8082 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
8083 Everything that starts with brl is a conditional branch. */
8084 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
8085 && (idesc->name[2] == '\0'
8086 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
8087 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
8088 || idesc->name[2] == 'l'
8089 /* br.cond, br.call, br.clr */
8090 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
8091 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
8092 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
8095 /* Return whether the given opcode is a taken branch. If there's any doubt,
8096 returns zero. */
8098 static int
8099 is_taken_branch (struct ia64_opcode *idesc)
8101 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
8102 || startswith (idesc->name, "br.ia"));
8105 /* Return whether the given opcode is an interruption or rfi. If there's any
8106 doubt, returns zero. */
8108 static int
8109 is_interruption_or_rfi (struct ia64_opcode *idesc)
8111 if (strcmp (idesc->name, "rfi") == 0)
8112 return 1;
8113 return 0;
8116 /* Returns the index of the given dependency in the opcode's list of chks, or
8117 -1 if there is no dependency. */
8119 static int
8120 depends_on (int depind, struct ia64_opcode *idesc)
8122 int i;
8123 const struct ia64_opcode_dependency *dep = idesc->dependencies;
8124 for (i = 0; i < dep->nchks; i++)
8126 if (depind == DEP (dep->chks[i]))
8127 return i;
8129 return -1;
8132 /* Determine a set of specific resources used for a particular resource
8133 class. Returns the number of specific resources identified For those
8134 cases which are not determinable statically, the resource returned is
8135 marked nonspecific.
8137 Meanings of value in 'NOTE':
8138 1) only read/write when the register number is explicitly encoded in the
8139 insn.
8140 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
8141 accesses CFM when qualifying predicate is in the rotating region.
8142 3) general register value is used to specify an indirect register; not
8143 determinable statically.
8144 4) only read the given resource when bits 7:0 of the indirect index
8145 register value does not match the register number of the resource; not
8146 determinable statically.
8147 5) all rules are implementation specific.
8148 6) only when both the index specified by the reader and the index specified
8149 by the writer have the same value in bits 63:61; not determinable
8150 statically.
8151 7) only access the specified resource when the corresponding mask bit is
8153 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
8154 only read when these insns reference FR2-31
8155 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
8156 written when these insns write FR32-127
8157 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
8158 instruction
8159 11) The target predicates are written independently of PR[qp], but source
8160 registers are only read if PR[qp] is true. Since the state of PR[qp]
8161 cannot statically be determined, all source registers are marked used.
8162 12) This insn only reads the specified predicate register when that
8163 register is the PR[qp].
8164 13) This reference to ld-c only applies to the GR whose value is loaded
8165 with data returned from memory, not the post-incremented address register.
8166 14) The RSE resource includes the implementation-specific RSE internal
8167 state resources. At least one (and possibly more) of these resources are
8168 read by each instruction listed in IC:rse-readers. At least one (and
8169 possibly more) of these resources are written by each insn listed in
8170 IC:rse-writers.
8171 15+16) Represents reserved instructions, which the assembler does not
8172 generate.
8173 17) CR[TPR] has a RAW dependency only between mov-to-CR-TPR and
8174 mov-to-PSR-l or ssm instructions that set PSR.i, PSR.pp or PSR.up.
8176 Memory resources (i.e. locations in memory) are *not* marked or tracked by
8177 this code; there are no dependency violations based on memory access.
8180 #define MAX_SPECS 256
8181 #define DV_CHK 1
8182 #define DV_REG 0
8184 static int
8185 specify_resource (const struct ia64_dependency *dep,
8186 struct ia64_opcode *idesc,
8187 /* is this a DV chk or a DV reg? */
8188 int type,
8189 /* returned specific resources */
8190 struct rsrc specs[MAX_SPECS],
8191 /* resource note for this insn's usage */
8192 int note,
8193 /* which execution path to examine */
8194 int path)
8196 int count = 0;
8197 int i;
8198 int rsrc_write = 0;
8199 struct rsrc tmpl;
8201 if (dep->mode == IA64_DV_WAW
8202 || (dep->mode == IA64_DV_RAW && type == DV_REG)
8203 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
8204 rsrc_write = 1;
8206 /* template for any resources we identify */
8207 tmpl.dependency = dep;
8208 tmpl.note = note;
8209 tmpl.insn_srlz = tmpl.data_srlz = 0;
8210 tmpl.qp_regno = CURR_SLOT.qp_regno;
8211 tmpl.link_to_qp_branch = 1;
8212 tmpl.mem_offset.hint = 0;
8213 tmpl.mem_offset.offset = 0;
8214 tmpl.mem_offset.base = 0;
8215 tmpl.specific = 1;
8216 tmpl.index = -1;
8217 tmpl.cmp_type = CMP_NONE;
8218 tmpl.depind = 0;
8219 tmpl.file = NULL;
8220 tmpl.line = 0;
8221 tmpl.path = 0;
8223 #define UNHANDLED \
8224 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
8225 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
8226 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
8228 /* we don't need to track these */
8229 if (dep->semantics == IA64_DVS_NONE)
8230 return 0;
8232 switch (dep->specifier)
8234 case IA64_RS_AR_K:
8235 if (note == 1)
8237 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8239 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8240 if (regno >= 0 && regno <= 7)
8242 specs[count] = tmpl;
8243 specs[count++].index = regno;
8247 else if (note == 0)
8249 for (i = 0; i < 8; i++)
8251 specs[count] = tmpl;
8252 specs[count++].index = i;
8255 else
8257 UNHANDLED;
8259 break;
8261 case IA64_RS_AR_UNAT:
8262 /* This is a mov =AR or mov AR= instruction. */
8263 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8265 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8266 if (regno == AR_UNAT)
8268 specs[count++] = tmpl;
8271 else
8273 /* This is a spill/fill, or other instruction that modifies the
8274 unat register. */
8276 /* Unless we can determine the specific bits used, mark the whole
8277 thing; bits 8:3 of the memory address indicate the bit used in
8278 UNAT. The .mem.offset hint may be used to eliminate a small
8279 subset of conflicts. */
8280 specs[count] = tmpl;
8281 if (md.mem_offset.hint)
8283 if (md.debug_dv)
8284 fprintf (stderr, " Using hint for spill/fill\n");
8285 /* The index isn't actually used, just set it to something
8286 approximating the bit index. */
8287 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
8288 specs[count].mem_offset.hint = 1;
8289 specs[count].mem_offset.offset = md.mem_offset.offset;
8290 specs[count++].mem_offset.base = md.mem_offset.base;
8292 else
8294 specs[count++].specific = 0;
8297 break;
8299 case IA64_RS_AR:
8300 if (note == 1)
8302 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8304 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8305 if ((regno >= 8 && regno <= 15)
8306 || (regno >= 20 && regno <= 23)
8307 || (regno >= 31 && regno <= 39)
8308 || (regno >= 41 && regno <= 47)
8309 || (regno >= 67 && regno <= 111))
8311 specs[count] = tmpl;
8312 specs[count++].index = regno;
8316 else
8318 UNHANDLED;
8320 break;
8322 case IA64_RS_ARb:
8323 if (note == 1)
8325 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8327 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8328 if ((regno >= 48 && regno <= 63)
8329 || (regno >= 112 && regno <= 127))
8331 specs[count] = tmpl;
8332 specs[count++].index = regno;
8336 else if (note == 0)
8338 for (i = 48; i < 64; i++)
8340 specs[count] = tmpl;
8341 specs[count++].index = i;
8343 for (i = 112; i < 128; i++)
8345 specs[count] = tmpl;
8346 specs[count++].index = i;
8349 else
8351 UNHANDLED;
8353 break;
8355 case IA64_RS_BR:
8356 if (note != 1)
8358 UNHANDLED;
8360 else
8362 if (rsrc_write)
8364 for (i = 0; i < idesc->num_outputs; i++)
8365 if (idesc->operands[i] == IA64_OPND_B1
8366 || idesc->operands[i] == IA64_OPND_B2)
8368 specs[count] = tmpl;
8369 specs[count++].index =
8370 CURR_SLOT.opnd[i].X_add_number - REG_BR;
8373 else
8375 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8376 if (idesc->operands[i] == IA64_OPND_B1
8377 || idesc->operands[i] == IA64_OPND_B2)
8379 specs[count] = tmpl;
8380 specs[count++].index =
8381 CURR_SLOT.opnd[i].X_add_number - REG_BR;
8385 break;
8387 case IA64_RS_CPUID: /* four or more registers */
8388 if (note == 3)
8390 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
8392 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8393 if (regno >= 0 && regno < NELEMS (gr_values)
8394 && KNOWN (regno))
8396 specs[count] = tmpl;
8397 specs[count++].index = gr_values[regno].value & 0xFF;
8399 else
8401 specs[count] = tmpl;
8402 specs[count++].specific = 0;
8406 else
8408 UNHANDLED;
8410 break;
8412 case IA64_RS_DBR: /* four or more registers */
8413 if (note == 3)
8415 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
8417 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8418 if (regno >= 0 && regno < NELEMS (gr_values)
8419 && KNOWN (regno))
8421 specs[count] = tmpl;
8422 specs[count++].index = gr_values[regno].value & 0xFF;
8424 else
8426 specs[count] = tmpl;
8427 specs[count++].specific = 0;
8431 else if (note == 0 && !rsrc_write)
8433 specs[count] = tmpl;
8434 specs[count++].specific = 0;
8436 else
8438 UNHANDLED;
8440 break;
8442 case IA64_RS_IBR: /* four or more registers */
8443 if (note == 3)
8445 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
8447 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8448 if (regno >= 0 && regno < NELEMS (gr_values)
8449 && KNOWN (regno))
8451 specs[count] = tmpl;
8452 specs[count++].index = gr_values[regno].value & 0xFF;
8454 else
8456 specs[count] = tmpl;
8457 specs[count++].specific = 0;
8461 else
8463 UNHANDLED;
8465 break;
8467 case IA64_RS_MSR:
8468 if (note == 5)
8470 /* These are implementation specific. Force all references to
8471 conflict with all other references. */
8472 specs[count] = tmpl;
8473 specs[count++].specific = 0;
8475 else
8477 UNHANDLED;
8479 break;
8481 case IA64_RS_PKR: /* 16 or more registers */
8482 if (note == 3 || note == 4)
8484 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
8486 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8487 if (regno >= 0 && regno < NELEMS (gr_values)
8488 && KNOWN (regno))
8490 if (note == 3)
8492 specs[count] = tmpl;
8493 specs[count++].index = gr_values[regno].value & 0xFF;
8495 else
8496 for (i = 0; i < NELEMS (gr_values); i++)
8498 /* Uses all registers *except* the one in R3. */
8499 if ((unsigned)i != (gr_values[regno].value & 0xFF))
8501 specs[count] = tmpl;
8502 specs[count++].index = i;
8506 else
8508 specs[count] = tmpl;
8509 specs[count++].specific = 0;
8513 else if (note == 0)
8515 /* probe et al. */
8516 specs[count] = tmpl;
8517 specs[count++].specific = 0;
8519 break;
8521 case IA64_RS_PMC: /* four or more registers */
8522 if (note == 3)
8524 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
8525 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
8528 int reg_index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
8529 ? 1 : !rsrc_write);
8530 int regno = CURR_SLOT.opnd[reg_index].X_add_number - REG_GR;
8531 if (regno >= 0 && regno < NELEMS (gr_values)
8532 && KNOWN (regno))
8534 specs[count] = tmpl;
8535 specs[count++].index = gr_values[regno].value & 0xFF;
8537 else
8539 specs[count] = tmpl;
8540 specs[count++].specific = 0;
8544 else
8546 UNHANDLED;
8548 break;
8550 case IA64_RS_PMD: /* four or more registers */
8551 if (note == 3)
8553 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
8555 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8556 if (regno >= 0 && regno < NELEMS (gr_values)
8557 && KNOWN (regno))
8559 specs[count] = tmpl;
8560 specs[count++].index = gr_values[regno].value & 0xFF;
8562 else
8564 specs[count] = tmpl;
8565 specs[count++].specific = 0;
8569 else
8571 UNHANDLED;
8573 break;
8575 case IA64_RS_RR: /* eight registers */
8576 if (note == 6)
8578 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
8580 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8581 if (regno >= 0 && regno < NELEMS (gr_values)
8582 && KNOWN (regno))
8584 specs[count] = tmpl;
8585 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
8587 else
8589 specs[count] = tmpl;
8590 specs[count++].specific = 0;
8594 else if (note == 0 && !rsrc_write)
8596 specs[count] = tmpl;
8597 specs[count++].specific = 0;
8599 else
8601 UNHANDLED;
8603 break;
8605 case IA64_RS_CR_IRR:
8606 if (note == 0)
8608 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
8609 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
8610 if (rsrc_write
8611 && idesc->operands[1] == IA64_OPND_CR3
8612 && regno == CR_IVR)
8614 for (i = 0; i < 4; i++)
8616 specs[count] = tmpl;
8617 specs[count++].index = CR_IRR0 + i;
8621 else if (note == 1)
8623 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8624 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8625 && regno >= CR_IRR0
8626 && regno <= CR_IRR3)
8628 specs[count] = tmpl;
8629 specs[count++].index = regno;
8632 else
8634 UNHANDLED;
8636 break;
8638 case IA64_RS_CR_IIB:
8639 if (note != 0)
8641 UNHANDLED;
8643 else
8645 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8646 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8647 && (regno == CR_IIB0 || regno == CR_IIB1))
8649 specs[count] = tmpl;
8650 specs[count++].index = regno;
8653 break;
8655 case IA64_RS_CR_LRR:
8656 if (note != 1)
8658 UNHANDLED;
8660 else
8662 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8663 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8664 && (regno == CR_LRR0 || regno == CR_LRR1))
8666 specs[count] = tmpl;
8667 specs[count++].index = regno;
8670 break;
8672 case IA64_RS_CR:
8673 if (note == 1)
8675 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8677 specs[count] = tmpl;
8678 specs[count++].index =
8679 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8682 else
8684 UNHANDLED;
8686 break;
8688 case IA64_RS_DAHR:
8689 if (note == 0)
8691 if (idesc->operands[!rsrc_write] == IA64_OPND_DAHR3)
8693 specs[count] = tmpl;
8694 specs[count++].index =
8695 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_DAHR;
8698 else
8700 UNHANDLED;
8702 break;
8704 case IA64_RS_FR:
8705 case IA64_RS_FRb:
8706 if (note != 1)
8708 UNHANDLED;
8710 else if (rsrc_write)
8712 if (dep->specifier == IA64_RS_FRb
8713 && idesc->operands[0] == IA64_OPND_F1)
8715 specs[count] = tmpl;
8716 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
8719 else
8721 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8723 if (idesc->operands[i] == IA64_OPND_F2
8724 || idesc->operands[i] == IA64_OPND_F3
8725 || idesc->operands[i] == IA64_OPND_F4)
8727 specs[count] = tmpl;
8728 specs[count++].index =
8729 CURR_SLOT.opnd[i].X_add_number - REG_FR;
8733 break;
8735 case IA64_RS_GR:
8736 if (note == 13)
8738 /* This reference applies only to the GR whose value is loaded with
8739 data returned from memory. */
8740 specs[count] = tmpl;
8741 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
8743 else if (note == 1)
8745 if (rsrc_write)
8747 for (i = 0; i < idesc->num_outputs; i++)
8748 if (idesc->operands[i] == IA64_OPND_R1
8749 || idesc->operands[i] == IA64_OPND_R2
8750 || idesc->operands[i] == IA64_OPND_R3)
8752 specs[count] = tmpl;
8753 specs[count++].index =
8754 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8756 if (idesc->flags & IA64_OPCODE_POSTINC)
8757 for (i = 0; i < NELEMS (idesc->operands); i++)
8758 if (idesc->operands[i] == IA64_OPND_MR3)
8760 specs[count] = tmpl;
8761 specs[count++].index =
8762 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8765 else
8767 /* Look for anything that reads a GR. */
8768 for (i = 0; i < NELEMS (idesc->operands); i++)
8770 if (idesc->operands[i] == IA64_OPND_MR3
8771 || idesc->operands[i] == IA64_OPND_CPUID_R3
8772 || idesc->operands[i] == IA64_OPND_DBR_R3
8773 || idesc->operands[i] == IA64_OPND_IBR_R3
8774 || idesc->operands[i] == IA64_OPND_MSR_R3
8775 || idesc->operands[i] == IA64_OPND_PKR_R3
8776 || idesc->operands[i] == IA64_OPND_PMC_R3
8777 || idesc->operands[i] == IA64_OPND_PMD_R3
8778 || idesc->operands[i] == IA64_OPND_DAHR_R3
8779 || idesc->operands[i] == IA64_OPND_RR_R3
8780 || ((i >= idesc->num_outputs)
8781 && (idesc->operands[i] == IA64_OPND_R1
8782 || idesc->operands[i] == IA64_OPND_R2
8783 || idesc->operands[i] == IA64_OPND_R3
8784 /* addl source register. */
8785 || idesc->operands[i] == IA64_OPND_R3_2)))
8787 specs[count] = tmpl;
8788 specs[count++].index =
8789 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8794 else
8796 UNHANDLED;
8798 break;
8800 /* This is the same as IA64_RS_PRr, except that the register range is
8801 from 1 - 15, and there are no rotating register reads/writes here. */
8802 case IA64_RS_PR:
8803 if (note == 0)
8805 for (i = 1; i < 16; i++)
8807 specs[count] = tmpl;
8808 specs[count++].index = i;
8811 else if (note == 7)
8813 valueT mask = 0;
8814 /* Mark only those registers indicated by the mask. */
8815 if (rsrc_write)
8817 mask = CURR_SLOT.opnd[2].X_add_number;
8818 for (i = 1; i < 16; i++)
8819 if (mask & ((valueT) 1 << i))
8821 specs[count] = tmpl;
8822 specs[count++].index = i;
8825 else
8827 UNHANDLED;
8830 else if (note == 11) /* note 11 implies note 1 as well */
8832 if (rsrc_write)
8834 for (i = 0; i < idesc->num_outputs; i++)
8836 if (idesc->operands[i] == IA64_OPND_P1
8837 || idesc->operands[i] == IA64_OPND_P2)
8839 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8840 if (regno >= 1 && regno < 16)
8842 specs[count] = tmpl;
8843 specs[count++].index = regno;
8848 else
8850 UNHANDLED;
8853 else if (note == 12)
8855 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8857 specs[count] = tmpl;
8858 specs[count++].index = CURR_SLOT.qp_regno;
8861 else if (note == 1)
8863 if (rsrc_write)
8865 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8866 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8867 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8868 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8870 if ((idesc->operands[0] == IA64_OPND_P1
8871 || idesc->operands[0] == IA64_OPND_P2)
8872 && p1 >= 1 && p1 < 16)
8874 specs[count] = tmpl;
8875 specs[count].cmp_type =
8876 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8877 specs[count++].index = p1;
8879 if ((idesc->operands[1] == IA64_OPND_P1
8880 || idesc->operands[1] == IA64_OPND_P2)
8881 && p2 >= 1 && p2 < 16)
8883 specs[count] = tmpl;
8884 specs[count].cmp_type =
8885 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8886 specs[count++].index = p2;
8889 else
8891 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8893 specs[count] = tmpl;
8894 specs[count++].index = CURR_SLOT.qp_regno;
8896 if (idesc->operands[1] == IA64_OPND_PR)
8898 for (i = 1; i < 16; i++)
8900 specs[count] = tmpl;
8901 specs[count++].index = i;
8906 else
8908 UNHANDLED;
8910 break;
8912 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
8913 simplified cases of this. */
8914 case IA64_RS_PRr:
8915 if (note == 0)
8917 for (i = 16; i < 63; i++)
8919 specs[count] = tmpl;
8920 specs[count++].index = i;
8923 else if (note == 7)
8925 valueT mask = 0;
8926 /* Mark only those registers indicated by the mask. */
8927 if (rsrc_write
8928 && idesc->operands[0] == IA64_OPND_PR)
8930 mask = CURR_SLOT.opnd[2].X_add_number;
8931 if (mask & ((valueT) 1 << 16))
8932 for (i = 16; i < 63; i++)
8934 specs[count] = tmpl;
8935 specs[count++].index = i;
8938 else if (rsrc_write
8939 && idesc->operands[0] == IA64_OPND_PR_ROT)
8941 for (i = 16; i < 63; i++)
8943 specs[count] = tmpl;
8944 specs[count++].index = i;
8947 else
8949 UNHANDLED;
8952 else if (note == 11) /* note 11 implies note 1 as well */
8954 if (rsrc_write)
8956 for (i = 0; i < idesc->num_outputs; i++)
8958 if (idesc->operands[i] == IA64_OPND_P1
8959 || idesc->operands[i] == IA64_OPND_P2)
8961 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8962 if (regno >= 16 && regno < 63)
8964 specs[count] = tmpl;
8965 specs[count++].index = regno;
8970 else
8972 UNHANDLED;
8975 else if (note == 12)
8977 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8979 specs[count] = tmpl;
8980 specs[count++].index = CURR_SLOT.qp_regno;
8983 else if (note == 1)
8985 if (rsrc_write)
8987 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8988 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8989 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8990 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8992 if ((idesc->operands[0] == IA64_OPND_P1
8993 || idesc->operands[0] == IA64_OPND_P2)
8994 && p1 >= 16 && p1 < 63)
8996 specs[count] = tmpl;
8997 specs[count].cmp_type =
8998 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8999 specs[count++].index = p1;
9001 if ((idesc->operands[1] == IA64_OPND_P1
9002 || idesc->operands[1] == IA64_OPND_P2)
9003 && p2 >= 16 && p2 < 63)
9005 specs[count] = tmpl;
9006 specs[count].cmp_type =
9007 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
9008 specs[count++].index = p2;
9011 else
9013 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
9015 specs[count] = tmpl;
9016 specs[count++].index = CURR_SLOT.qp_regno;
9018 if (idesc->operands[1] == IA64_OPND_PR)
9020 for (i = 16; i < 63; i++)
9022 specs[count] = tmpl;
9023 specs[count++].index = i;
9028 else
9030 UNHANDLED;
9032 break;
9034 case IA64_RS_PSR:
9035 /* Verify that the instruction is using the PSR bit indicated in
9036 dep->regindex. */
9037 if (note == 0)
9039 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
9041 if (dep->regindex < 6)
9043 specs[count++] = tmpl;
9046 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
9048 if (dep->regindex < 32
9049 || dep->regindex == 35
9050 || dep->regindex == 36
9051 || (!rsrc_write && dep->regindex == PSR_CPL))
9053 specs[count++] = tmpl;
9056 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
9058 if (dep->regindex < 32
9059 || dep->regindex == 35
9060 || dep->regindex == 36
9061 || (rsrc_write && dep->regindex == PSR_CPL))
9063 specs[count++] = tmpl;
9066 else
9068 /* Several PSR bits have very specific dependencies. */
9069 switch (dep->regindex)
9071 default:
9072 specs[count++] = tmpl;
9073 break;
9074 case PSR_IC:
9075 if (rsrc_write)
9077 specs[count++] = tmpl;
9079 else
9081 /* Only certain CR accesses use PSR.ic */
9082 if (idesc->operands[0] == IA64_OPND_CR3
9083 || idesc->operands[1] == IA64_OPND_CR3)
9085 int reg_index =
9086 ((idesc->operands[0] == IA64_OPND_CR3)
9087 ? 0 : 1);
9088 int regno =
9089 CURR_SLOT.opnd[reg_index].X_add_number - REG_CR;
9091 switch (regno)
9093 default:
9094 break;
9095 case CR_ITIR:
9096 case CR_IFS:
9097 case CR_IIM:
9098 case CR_IIP:
9099 case CR_IPSR:
9100 case CR_ISR:
9101 case CR_IFA:
9102 case CR_IHA:
9103 case CR_IIB0:
9104 case CR_IIB1:
9105 case CR_IIPA:
9106 specs[count++] = tmpl;
9107 break;
9111 break;
9112 case PSR_CPL:
9113 if (rsrc_write)
9115 specs[count++] = tmpl;
9117 else
9119 /* Only some AR accesses use cpl */
9120 if (idesc->operands[0] == IA64_OPND_AR3
9121 || idesc->operands[1] == IA64_OPND_AR3)
9123 int reg_index =
9124 ((idesc->operands[0] == IA64_OPND_AR3)
9125 ? 0 : 1);
9126 int regno =
9127 CURR_SLOT.opnd[reg_index].X_add_number - REG_AR;
9129 if (regno == AR_ITC
9130 || regno == AR_RUC
9131 || (reg_index == 0
9132 && (regno == AR_RSC
9133 || (regno >= AR_K0
9134 && regno <= AR_K7))))
9136 specs[count++] = tmpl;
9139 else
9141 specs[count++] = tmpl;
9143 break;
9148 else if (note == 7)
9150 valueT mask = 0;
9151 if (idesc->operands[0] == IA64_OPND_IMMU24)
9153 mask = CURR_SLOT.opnd[0].X_add_number;
9155 else
9157 UNHANDLED;
9159 if (mask & ((valueT) 1 << dep->regindex))
9161 specs[count++] = tmpl;
9164 else if (note == 8)
9166 int min = dep->regindex == PSR_DFL ? 2 : 32;
9167 int max = dep->regindex == PSR_DFL ? 31 : 127;
9168 /* dfh is read on FR32-127; dfl is read on FR2-31 */
9169 for (i = 0; i < NELEMS (idesc->operands); i++)
9171 if (idesc->operands[i] == IA64_OPND_F1
9172 || idesc->operands[i] == IA64_OPND_F2
9173 || idesc->operands[i] == IA64_OPND_F3
9174 || idesc->operands[i] == IA64_OPND_F4)
9176 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9177 if (reg >= min && reg <= max)
9179 specs[count++] = tmpl;
9184 else if (note == 9)
9186 int min = dep->regindex == PSR_MFL ? 2 : 32;
9187 int max = dep->regindex == PSR_MFL ? 31 : 127;
9188 /* mfh is read on writes to FR32-127; mfl is read on writes to
9189 FR2-31 */
9190 for (i = 0; i < idesc->num_outputs; i++)
9192 if (idesc->operands[i] == IA64_OPND_F1)
9194 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9195 if (reg >= min && reg <= max)
9197 specs[count++] = tmpl;
9202 else if (note == 10)
9204 for (i = 0; i < NELEMS (idesc->operands); i++)
9206 if (idesc->operands[i] == IA64_OPND_R1
9207 || idesc->operands[i] == IA64_OPND_R2
9208 || idesc->operands[i] == IA64_OPND_R3)
9210 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9211 if (regno >= 16 && regno <= 31)
9213 specs[count++] = tmpl;
9218 else
9220 UNHANDLED;
9222 break;
9224 case IA64_RS_AR_FPSR:
9225 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
9227 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
9228 if (regno == AR_FPSR)
9230 specs[count++] = tmpl;
9233 else
9235 specs[count++] = tmpl;
9237 break;
9239 case IA64_RS_ARX:
9240 /* Handle all AR[REG] resources */
9241 if (note == 0 || note == 1)
9243 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
9244 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
9245 && regno == dep->regindex)
9247 specs[count++] = tmpl;
9249 /* other AR[REG] resources may be affected by AR accesses */
9250 else if (idesc->operands[0] == IA64_OPND_AR3)
9252 /* AR[] writes */
9253 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
9254 switch (dep->regindex)
9256 default:
9257 break;
9258 case AR_BSP:
9259 case AR_RNAT:
9260 if (regno == AR_BSPSTORE)
9262 specs[count++] = tmpl;
9264 /* Fall through. */
9265 case AR_RSC:
9266 if (!rsrc_write &&
9267 (regno == AR_BSPSTORE
9268 || regno == AR_RNAT))
9270 specs[count++] = tmpl;
9272 break;
9275 else if (idesc->operands[1] == IA64_OPND_AR3)
9277 /* AR[] reads */
9278 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
9279 switch (dep->regindex)
9281 default:
9282 break;
9283 case AR_RSC:
9284 if (regno == AR_BSPSTORE || regno == AR_RNAT)
9286 specs[count++] = tmpl;
9288 break;
9291 else
9293 specs[count++] = tmpl;
9296 else
9298 UNHANDLED;
9300 break;
9302 case IA64_RS_CRX:
9303 /* Handle all CR[REG] resources.
9304 ??? FIXME: The rule 17 isn't really handled correctly. */
9305 if (note == 0 || note == 1 || note == 17)
9307 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
9309 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
9310 if (regno == dep->regindex)
9312 specs[count++] = tmpl;
9314 else if (!rsrc_write)
9316 /* Reads from CR[IVR] affect other resources. */
9317 if (regno == CR_IVR)
9319 if ((dep->regindex >= CR_IRR0
9320 && dep->regindex <= CR_IRR3)
9321 || dep->regindex == CR_TPR)
9323 specs[count++] = tmpl;
9328 else
9330 specs[count++] = tmpl;
9333 else
9335 UNHANDLED;
9337 break;
9339 case IA64_RS_INSERVICE:
9340 /* look for write of EOI (67) or read of IVR (65) */
9341 if ((idesc->operands[0] == IA64_OPND_CR3
9342 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
9343 || (idesc->operands[1] == IA64_OPND_CR3
9344 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
9346 specs[count++] = tmpl;
9348 break;
9350 case IA64_RS_GR0:
9351 if (note == 1)
9353 specs[count++] = tmpl;
9355 else
9357 UNHANDLED;
9359 break;
9361 case IA64_RS_CFM:
9362 if (note != 2)
9364 specs[count++] = tmpl;
9366 else
9368 /* Check if any of the registers accessed are in the rotating region.
9369 mov to/from pr accesses CFM only when qp_regno is in the rotating
9370 region */
9371 for (i = 0; i < NELEMS (idesc->operands); i++)
9373 if (idesc->operands[i] == IA64_OPND_R1
9374 || idesc->operands[i] == IA64_OPND_R2
9375 || idesc->operands[i] == IA64_OPND_R3)
9377 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9378 /* Assumes that md.rot.num_regs is always valid */
9379 if (md.rot.num_regs > 0
9380 && num > 31
9381 && num < 31 + md.rot.num_regs)
9383 specs[count] = tmpl;
9384 specs[count++].specific = 0;
9387 else if (idesc->operands[i] == IA64_OPND_F1
9388 || idesc->operands[i] == IA64_OPND_F2
9389 || idesc->operands[i] == IA64_OPND_F3
9390 || idesc->operands[i] == IA64_OPND_F4)
9392 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9393 if (num > 31)
9395 specs[count] = tmpl;
9396 specs[count++].specific = 0;
9399 else if (idesc->operands[i] == IA64_OPND_P1
9400 || idesc->operands[i] == IA64_OPND_P2)
9402 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
9403 if (num > 15)
9405 specs[count] = tmpl;
9406 specs[count++].specific = 0;
9410 if (CURR_SLOT.qp_regno > 15)
9412 specs[count] = tmpl;
9413 specs[count++].specific = 0;
9416 break;
9418 /* This is the same as IA64_RS_PRr, except simplified to account for
9419 the fact that there is only one register. */
9420 case IA64_RS_PR63:
9421 if (note == 0)
9423 specs[count++] = tmpl;
9425 else if (note == 7)
9427 valueT mask = 0;
9428 if (idesc->operands[2] == IA64_OPND_IMM17)
9429 mask = CURR_SLOT.opnd[2].X_add_number;
9430 if (mask & ((valueT) 1 << 63))
9431 specs[count++] = tmpl;
9433 else if (note == 11)
9435 if ((idesc->operands[0] == IA64_OPND_P1
9436 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
9437 || (idesc->operands[1] == IA64_OPND_P2
9438 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
9440 specs[count++] = tmpl;
9443 else if (note == 12)
9445 if (CURR_SLOT.qp_regno == 63)
9447 specs[count++] = tmpl;
9450 else if (note == 1)
9452 if (rsrc_write)
9454 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9455 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9456 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
9457 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
9459 if (p1 == 63
9460 && (idesc->operands[0] == IA64_OPND_P1
9461 || idesc->operands[0] == IA64_OPND_P2))
9463 specs[count] = tmpl;
9464 specs[count++].cmp_type =
9465 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
9467 if (p2 == 63
9468 && (idesc->operands[1] == IA64_OPND_P1
9469 || idesc->operands[1] == IA64_OPND_P2))
9471 specs[count] = tmpl;
9472 specs[count++].cmp_type =
9473 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
9476 else
9478 if (CURR_SLOT.qp_regno == 63)
9480 specs[count++] = tmpl;
9484 else
9486 UNHANDLED;
9488 break;
9490 case IA64_RS_RSE:
9491 /* FIXME we can identify some individual RSE written resources, but RSE
9492 read resources have not yet been completely identified, so for now
9493 treat RSE as a single resource */
9494 if (startswith (idesc->name, "mov"))
9496 if (rsrc_write)
9498 if (idesc->operands[0] == IA64_OPND_AR3
9499 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
9501 specs[count++] = tmpl;
9504 else
9506 if (idesc->operands[0] == IA64_OPND_AR3)
9508 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
9509 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
9511 specs[count++] = tmpl;
9514 else if (idesc->operands[1] == IA64_OPND_AR3)
9516 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
9517 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
9518 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
9520 specs[count++] = tmpl;
9525 else
9527 specs[count++] = tmpl;
9529 break;
9531 case IA64_RS_ANY:
9532 /* FIXME -- do any of these need to be non-specific? */
9533 specs[count++] = tmpl;
9534 break;
9536 default:
9537 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
9538 break;
9541 return count;
9544 /* Clear branch flags on marked resources. This breaks the link between the
9545 QP of the marking instruction and a subsequent branch on the same QP. */
9547 static void
9548 clear_qp_branch_flag (valueT mask)
9550 int i;
9551 for (i = 0; i < regdepslen; i++)
9553 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
9554 if ((bit & mask) != 0)
9556 regdeps[i].link_to_qp_branch = 0;
9561 /* MASK contains 2 and only 2 PRs which are mutually exclusive. Remove
9562 any mutexes which contain one of the PRs and create new ones when
9563 needed. */
9565 static int
9566 update_qp_mutex (valueT mask)
9568 int i;
9569 int add = 0;
9571 i = 0;
9572 while (i < qp_mutexeslen)
9574 if ((qp_mutexes[i].prmask & mask) != 0)
9576 /* If it destroys and creates the same mutex, do nothing. */
9577 if (qp_mutexes[i].prmask == mask
9578 && qp_mutexes[i].path == md.path)
9580 i++;
9581 add = -1;
9583 else
9585 int keep = 0;
9587 if (md.debug_dv)
9589 fprintf (stderr, " Clearing mutex relation");
9590 print_prmask (qp_mutexes[i].prmask);
9591 fprintf (stderr, "\n");
9594 /* Deal with the old mutex with more than 3+ PRs only if
9595 the new mutex on the same execution path with it.
9597 FIXME: The 3+ mutex support is incomplete.
9598 dot_pred_rel () may be a better place to fix it. */
9599 if (qp_mutexes[i].path == md.path)
9601 /* If it is a proper subset of the mutex, create a
9602 new mutex. */
9603 if (add == 0
9604 && (qp_mutexes[i].prmask & mask) == mask)
9605 add = 1;
9607 qp_mutexes[i].prmask &= ~mask;
9608 if (qp_mutexes[i].prmask & (qp_mutexes[i].prmask - 1))
9610 /* Modify the mutex if there are more than one
9611 PR left. */
9612 keep = 1;
9613 i++;
9617 if (keep == 0)
9618 /* Remove the mutex. */
9619 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
9622 else
9623 ++i;
9626 if (add == 1)
9627 add_qp_mutex (mask);
9629 return add;
9632 /* Remove any mutexes which contain any of the PRs indicated in the mask.
9634 Any changes to a PR clears the mutex relations which include that PR. */
9636 static void
9637 clear_qp_mutex (valueT mask)
9639 int i;
9641 i = 0;
9642 while (i < qp_mutexeslen)
9644 if ((qp_mutexes[i].prmask & mask) != 0)
9646 if (md.debug_dv)
9648 fprintf (stderr, " Clearing mutex relation");
9649 print_prmask (qp_mutexes[i].prmask);
9650 fprintf (stderr, "\n");
9652 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
9654 else
9655 ++i;
9659 /* Clear implies relations which contain PRs in the given masks.
9660 P1_MASK indicates the source of the implies relation, while P2_MASK
9661 indicates the implied PR. */
9663 static void
9664 clear_qp_implies (valueT p1_mask, valueT p2_mask)
9666 int i;
9668 i = 0;
9669 while (i < qp_implieslen)
9671 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
9672 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
9674 if (md.debug_dv)
9675 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
9676 qp_implies[i].p1, qp_implies[i].p2);
9677 qp_implies[i] = qp_implies[--qp_implieslen];
9679 else
9680 ++i;
9684 /* Add the PRs specified to the list of implied relations. */
9686 static void
9687 add_qp_imply (int p1, int p2)
9689 valueT mask;
9690 valueT bit;
9691 int i;
9693 /* p0 is not meaningful here. */
9694 if (p1 == 0 || p2 == 0)
9695 abort ();
9697 if (p1 == p2)
9698 return;
9700 /* If it exists already, ignore it. */
9701 for (i = 0; i < qp_implieslen; i++)
9703 if (qp_implies[i].p1 == p1
9704 && qp_implies[i].p2 == p2
9705 && qp_implies[i].path == md.path
9706 && !qp_implies[i].p2_branched)
9707 return;
9710 if (qp_implieslen == qp_impliestotlen)
9712 qp_impliestotlen += 20;
9713 qp_implies = XRESIZEVEC (struct qp_imply, qp_implies, qp_impliestotlen);
9715 if (md.debug_dv)
9716 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
9717 qp_implies[qp_implieslen].p1 = p1;
9718 qp_implies[qp_implieslen].p2 = p2;
9719 qp_implies[qp_implieslen].path = md.path;
9720 qp_implies[qp_implieslen++].p2_branched = 0;
9722 /* Add in the implied transitive relations; for everything that p2 implies,
9723 make p1 imply that, too; for everything that implies p1, make it imply p2
9724 as well. */
9725 for (i = 0; i < qp_implieslen; i++)
9727 if (qp_implies[i].p1 == p2)
9728 add_qp_imply (p1, qp_implies[i].p2);
9729 if (qp_implies[i].p2 == p1)
9730 add_qp_imply (qp_implies[i].p1, p2);
9732 /* Add in mutex relations implied by this implies relation; for each mutex
9733 relation containing p2, duplicate it and replace p2 with p1. */
9734 bit = (valueT) 1 << p1;
9735 mask = (valueT) 1 << p2;
9736 for (i = 0; i < qp_mutexeslen; i++)
9738 if (qp_mutexes[i].prmask & mask)
9739 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
9743 /* Add the PRs specified in the mask to the mutex list; this means that only
9744 one of the PRs can be true at any time. PR0 should never be included in
9745 the mask. */
9747 static void
9748 add_qp_mutex (valueT mask)
9750 if (mask & 0x1)
9751 abort ();
9753 if (qp_mutexeslen == qp_mutexestotlen)
9755 qp_mutexestotlen += 20;
9756 qp_mutexes = XRESIZEVEC (struct qpmutex, qp_mutexes, qp_mutexestotlen);
9758 if (md.debug_dv)
9760 fprintf (stderr, " Registering mutex on");
9761 print_prmask (mask);
9762 fprintf (stderr, "\n");
9764 qp_mutexes[qp_mutexeslen].path = md.path;
9765 qp_mutexes[qp_mutexeslen++].prmask = mask;
9768 static int
9769 has_suffix_p (const char *name, const char *suffix)
9771 size_t namelen = strlen (name);
9772 size_t sufflen = strlen (suffix);
9774 if (namelen <= sufflen)
9775 return 0;
9776 return strcmp (name + namelen - sufflen, suffix) == 0;
9779 static void
9780 clear_register_values (void)
9782 int i;
9783 if (md.debug_dv)
9784 fprintf (stderr, " Clearing register values\n");
9785 for (i = 1; i < NELEMS (gr_values); i++)
9786 gr_values[i].known = 0;
9789 /* Keep track of register values/changes which affect DV tracking.
9791 optimization note: should add a flag to classes of insns where otherwise we
9792 have to examine a group of strings to identify them. */
9794 static void
9795 note_register_values (struct ia64_opcode *idesc)
9797 valueT qp_changemask = 0;
9798 int i;
9800 /* Invalidate values for registers being written to. */
9801 for (i = 0; i < idesc->num_outputs; i++)
9803 if (idesc->operands[i] == IA64_OPND_R1
9804 || idesc->operands[i] == IA64_OPND_R2
9805 || idesc->operands[i] == IA64_OPND_R3)
9807 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9808 if (regno > 0 && regno < NELEMS (gr_values))
9809 gr_values[regno].known = 0;
9811 else if (idesc->operands[i] == IA64_OPND_R3_2)
9813 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9814 if (regno > 0 && regno < 4)
9815 gr_values[regno].known = 0;
9817 else if (idesc->operands[i] == IA64_OPND_P1
9818 || idesc->operands[i] == IA64_OPND_P2)
9820 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
9821 qp_changemask |= (valueT) 1 << regno;
9823 else if (idesc->operands[i] == IA64_OPND_PR)
9825 if (idesc->operands[2] & (valueT) 0x10000)
9826 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
9827 else
9828 qp_changemask = idesc->operands[2];
9829 break;
9831 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
9833 if (idesc->operands[1] & ((valueT) 1 << 43))
9834 qp_changemask = -((valueT) 1 << 44) | idesc->operands[1];
9835 else
9836 qp_changemask = idesc->operands[1];
9837 qp_changemask &= ~(valueT) 0xFFFF;
9838 break;
9842 /* Always clear qp branch flags on any PR change. */
9843 /* FIXME there may be exceptions for certain compares. */
9844 clear_qp_branch_flag (qp_changemask);
9846 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
9847 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
9849 qp_changemask |= ~(valueT) 0xFFFF;
9850 if (strcmp (idesc->name, "clrrrb.pr") != 0)
9852 for (i = 32; i < 32 + md.rot.num_regs; i++)
9853 gr_values[i].known = 0;
9855 clear_qp_mutex (qp_changemask);
9856 clear_qp_implies (qp_changemask, qp_changemask);
9858 /* After a call, all register values are undefined, except those marked
9859 as "safe". */
9860 else if (startswith (idesc->name, "br.call")
9861 || startswith (idesc->name, "brl.call"))
9863 /* FIXME keep GR values which are marked as "safe_across_calls" */
9864 clear_register_values ();
9865 clear_qp_mutex (~qp_safe_across_calls);
9866 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
9867 clear_qp_branch_flag (~qp_safe_across_calls);
9869 else if (is_interruption_or_rfi (idesc)
9870 || is_taken_branch (idesc))
9872 clear_register_values ();
9873 clear_qp_mutex (~(valueT) 0);
9874 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
9876 /* Look for mutex and implies relations. */
9877 else if ((idesc->operands[0] == IA64_OPND_P1
9878 || idesc->operands[0] == IA64_OPND_P2)
9879 && (idesc->operands[1] == IA64_OPND_P1
9880 || idesc->operands[1] == IA64_OPND_P2))
9882 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9883 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9884 valueT p1mask = (p1 != 0) ? (valueT) 1 << p1 : 0;
9885 valueT p2mask = (p2 != 0) ? (valueT) 1 << p2 : 0;
9887 /* If both PRs are PR0, we can't really do anything. */
9888 if (p1 == 0 && p2 == 0)
9890 if (md.debug_dv)
9891 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
9893 /* In general, clear mutexes and implies which include P1 or P2,
9894 with the following exceptions. */
9895 else if (has_suffix_p (idesc->name, ".or.andcm")
9896 || has_suffix_p (idesc->name, ".and.orcm"))
9898 clear_qp_implies (p2mask, p1mask);
9900 else if (has_suffix_p (idesc->name, ".andcm")
9901 || has_suffix_p (idesc->name, ".and"))
9903 clear_qp_implies (0, p1mask | p2mask);
9905 else if (has_suffix_p (idesc->name, ".orcm")
9906 || has_suffix_p (idesc->name, ".or"))
9908 clear_qp_mutex (p1mask | p2mask);
9909 clear_qp_implies (p1mask | p2mask, 0);
9911 else
9913 int added = 0;
9915 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
9917 /* If one of the PRs is PR0, we call clear_qp_mutex. */
9918 if (p1 == 0 || p2 == 0)
9919 clear_qp_mutex (p1mask | p2mask);
9920 else
9921 added = update_qp_mutex (p1mask | p2mask);
9923 if (CURR_SLOT.qp_regno == 0
9924 || has_suffix_p (idesc->name, ".unc"))
9926 if (added == 0 && p1 && p2)
9927 add_qp_mutex (p1mask | p2mask);
9928 if (CURR_SLOT.qp_regno != 0)
9930 if (p1)
9931 add_qp_imply (p1, CURR_SLOT.qp_regno);
9932 if (p2)
9933 add_qp_imply (p2, CURR_SLOT.qp_regno);
9938 /* Look for mov imm insns into GRs. */
9939 else if (idesc->operands[0] == IA64_OPND_R1
9940 && (idesc->operands[1] == IA64_OPND_IMM22
9941 || idesc->operands[1] == IA64_OPND_IMMU64)
9942 && CURR_SLOT.opnd[1].X_op == O_constant
9943 && (strcmp (idesc->name, "mov") == 0
9944 || strcmp (idesc->name, "movl") == 0))
9946 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9947 if (regno > 0 && regno < NELEMS (gr_values))
9949 gr_values[regno].known = 1;
9950 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
9951 gr_values[regno].path = md.path;
9952 if (md.debug_dv)
9953 fprintf (stderr, " Know gr%d = %" PRIx64 "\n",
9954 regno, gr_values[regno].value);
9957 /* Look for dep.z imm insns. */
9958 else if (idesc->operands[0] == IA64_OPND_R1
9959 && idesc->operands[1] == IA64_OPND_IMM8
9960 && strcmp (idesc->name, "dep.z") == 0)
9962 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9963 if (regno > 0 && regno < NELEMS (gr_values))
9965 valueT value = CURR_SLOT.opnd[1].X_add_number;
9967 if (CURR_SLOT.opnd[3].X_add_number < 64)
9968 value &= ((valueT)1 << CURR_SLOT.opnd[3].X_add_number) - 1;
9969 value <<= CURR_SLOT.opnd[2].X_add_number;
9970 gr_values[regno].known = 1;
9971 gr_values[regno].value = value;
9972 gr_values[regno].path = md.path;
9973 if (md.debug_dv)
9974 fprintf (stderr, " Know gr%d = %" PRIx64 "\n",
9975 regno, gr_values[regno].value);
9978 else
9980 clear_qp_mutex (qp_changemask);
9981 clear_qp_implies (qp_changemask, qp_changemask);
9985 /* Return whether the given predicate registers are currently mutex. */
9987 static int
9988 qp_mutex (int p1, int p2, int path)
9990 int i;
9991 valueT mask;
9993 if (p1 != p2)
9995 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9996 for (i = 0; i < qp_mutexeslen; i++)
9998 if (qp_mutexes[i].path >= path
9999 && (qp_mutexes[i].prmask & mask) == mask)
10000 return 1;
10003 return 0;
10006 /* Return whether the given resource is in the given insn's list of chks
10007 Return 1 if the conflict is absolutely determined, 2 if it's a potential
10008 conflict. */
10010 static int
10011 resources_match (struct rsrc *rs,
10012 struct ia64_opcode *idesc,
10013 int note,
10014 int qp_regno,
10015 int path)
10017 struct rsrc specs[MAX_SPECS];
10018 int count;
10020 /* If the marked resource's qp_regno and the given qp_regno are mutex,
10021 we don't need to check. One exception is note 11, which indicates that
10022 target predicates are written regardless of PR[qp]. */
10023 if (qp_mutex (rs->qp_regno, qp_regno, path)
10024 && note != 11)
10025 return 0;
10027 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
10028 while (count-- > 0)
10030 /* UNAT checking is a bit more specific than other resources */
10031 if (rs->dependency->specifier == IA64_RS_AR_UNAT
10032 && specs[count].mem_offset.hint
10033 && rs->mem_offset.hint)
10035 if (rs->mem_offset.base == specs[count].mem_offset.base)
10037 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
10038 ((specs[count].mem_offset.offset >> 3) & 0x3F))
10039 return 1;
10040 else
10041 continue;
10045 /* Skip apparent PR write conflicts where both writes are an AND or both
10046 writes are an OR. */
10047 if (rs->dependency->specifier == IA64_RS_PR
10048 || rs->dependency->specifier == IA64_RS_PRr
10049 || rs->dependency->specifier == IA64_RS_PR63)
10051 if (specs[count].cmp_type != CMP_NONE
10052 && specs[count].cmp_type == rs->cmp_type)
10054 if (md.debug_dv)
10055 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
10056 dv_mode[rs->dependency->mode],
10057 rs->dependency->specifier != IA64_RS_PR63 ?
10058 specs[count].index : 63);
10059 continue;
10061 if (md.debug_dv)
10062 fprintf (stderr,
10063 " %s on parallel compare conflict %s vs %s on PR%d\n",
10064 dv_mode[rs->dependency->mode],
10065 dv_cmp_type[rs->cmp_type],
10066 dv_cmp_type[specs[count].cmp_type],
10067 rs->dependency->specifier != IA64_RS_PR63 ?
10068 specs[count].index : 63);
10072 /* If either resource is not specific, conservatively assume a conflict
10074 if (!specs[count].specific || !rs->specific)
10075 return 2;
10076 else if (specs[count].index == rs->index)
10077 return 1;
10080 return 0;
10083 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
10084 insert a stop to create the break. Update all resource dependencies
10085 appropriately. If QP_REGNO is non-zero, only apply the break to resources
10086 which use the same QP_REGNO and have the link_to_qp_branch flag set.
10087 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
10088 instruction. */
10090 static void
10091 insn_group_break (int insert_stop, int qp_regno, int save_current)
10093 int i;
10095 if (insert_stop && md.num_slots_in_use > 0)
10096 PREV_SLOT.end_of_insn_group = 1;
10098 if (md.debug_dv)
10100 fprintf (stderr, " Insn group break%s",
10101 (insert_stop ? " (w/stop)" : ""));
10102 if (qp_regno != 0)
10103 fprintf (stderr, " effective for QP=%d", qp_regno);
10104 fprintf (stderr, "\n");
10107 i = 0;
10108 while (i < regdepslen)
10110 const struct ia64_dependency *dep = regdeps[i].dependency;
10112 if (qp_regno != 0
10113 && regdeps[i].qp_regno != qp_regno)
10115 ++i;
10116 continue;
10119 if (save_current
10120 && CURR_SLOT.src_file == regdeps[i].file
10121 && CURR_SLOT.src_line == regdeps[i].line)
10123 ++i;
10124 continue;
10127 /* clear dependencies which are automatically cleared by a stop, or
10128 those that have reached the appropriate state of insn serialization */
10129 if (dep->semantics == IA64_DVS_IMPLIED
10130 || dep->semantics == IA64_DVS_IMPLIEDF
10131 || regdeps[i].insn_srlz == STATE_SRLZ)
10133 print_dependency ("Removing", i);
10134 regdeps[i] = regdeps[--regdepslen];
10136 else
10138 if (dep->semantics == IA64_DVS_DATA
10139 || dep->semantics == IA64_DVS_INSTR
10140 || dep->semantics == IA64_DVS_SPECIFIC)
10142 if (regdeps[i].insn_srlz == STATE_NONE)
10143 regdeps[i].insn_srlz = STATE_STOP;
10144 if (regdeps[i].data_srlz == STATE_NONE)
10145 regdeps[i].data_srlz = STATE_STOP;
10147 ++i;
10152 /* Add the given resource usage spec to the list of active dependencies. */
10154 static void
10155 mark_resource (struct ia64_opcode *idesc ATTRIBUTE_UNUSED,
10156 const struct ia64_dependency *dep ATTRIBUTE_UNUSED,
10157 struct rsrc *spec,
10158 int depind,
10159 int path)
10161 if (regdepslen == regdepstotlen)
10163 regdepstotlen += 20;
10164 regdeps = XRESIZEVEC (struct rsrc, regdeps, regdepstotlen);
10167 regdeps[regdepslen] = *spec;
10168 regdeps[regdepslen].depind = depind;
10169 regdeps[regdepslen].path = path;
10170 regdeps[regdepslen].file = CURR_SLOT.src_file;
10171 regdeps[regdepslen].line = CURR_SLOT.src_line;
10173 print_dependency ("Adding", regdepslen);
10175 ++regdepslen;
10178 static void
10179 print_dependency (const char *action, int depind)
10181 if (md.debug_dv)
10183 fprintf (stderr, " %s %s '%s'",
10184 action, dv_mode[(regdeps[depind].dependency)->mode],
10185 (regdeps[depind].dependency)->name);
10186 if (regdeps[depind].specific && regdeps[depind].index >= 0)
10187 fprintf (stderr, " (%d)", regdeps[depind].index);
10188 if (regdeps[depind].mem_offset.hint)
10189 fprintf (stderr, " %" PRIx64 "+%" PRIx64,
10190 regdeps[depind].mem_offset.base,
10191 regdeps[depind].mem_offset.offset);
10192 fprintf (stderr, "\n");
10196 static void
10197 instruction_serialization (void)
10199 int i;
10200 if (md.debug_dv)
10201 fprintf (stderr, " Instruction serialization\n");
10202 for (i = 0; i < regdepslen; i++)
10203 if (regdeps[i].insn_srlz == STATE_STOP)
10204 regdeps[i].insn_srlz = STATE_SRLZ;
10207 static void
10208 data_serialization (void)
10210 int i = 0;
10211 if (md.debug_dv)
10212 fprintf (stderr, " Data serialization\n");
10213 while (i < regdepslen)
10215 if (regdeps[i].data_srlz == STATE_STOP
10216 /* Note: as of 991210, all "other" dependencies are cleared by a
10217 data serialization. This might change with new tables */
10218 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
10220 print_dependency ("Removing", i);
10221 regdeps[i] = regdeps[--regdepslen];
10223 else
10224 ++i;
10228 /* Insert stops and serializations as needed to avoid DVs. */
10230 static void
10231 remove_marked_resource (struct rsrc *rs)
10233 switch (rs->dependency->semantics)
10235 case IA64_DVS_SPECIFIC:
10236 if (md.debug_dv)
10237 fprintf (stderr, "Implementation-specific, assume worst case...\n");
10238 /* Fall through. */
10239 case IA64_DVS_INSTR:
10240 if (md.debug_dv)
10241 fprintf (stderr, "Inserting instr serialization\n");
10242 if (rs->insn_srlz < STATE_STOP)
10243 insn_group_break (1, 0, 0);
10244 if (rs->insn_srlz < STATE_SRLZ)
10246 struct slot oldslot = CURR_SLOT;
10247 /* Manually jam a srlz.i insn into the stream */
10248 memset (&CURR_SLOT, 0, sizeof (CURR_SLOT));
10249 CURR_SLOT.user_template = -1;
10250 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
10251 instruction_serialization ();
10252 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10253 if (++md.num_slots_in_use >= NUM_SLOTS)
10254 emit_one_bundle ();
10255 CURR_SLOT = oldslot;
10257 insn_group_break (1, 0, 0);
10258 break;
10259 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
10260 "other" types of DV are eliminated
10261 by a data serialization */
10262 case IA64_DVS_DATA:
10263 if (md.debug_dv)
10264 fprintf (stderr, "Inserting data serialization\n");
10265 if (rs->data_srlz < STATE_STOP)
10266 insn_group_break (1, 0, 0);
10268 struct slot oldslot = CURR_SLOT;
10269 /* Manually jam a srlz.d insn into the stream */
10270 memset (&CURR_SLOT, 0, sizeof (CURR_SLOT));
10271 CURR_SLOT.user_template = -1;
10272 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
10273 data_serialization ();
10274 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10275 if (++md.num_slots_in_use >= NUM_SLOTS)
10276 emit_one_bundle ();
10277 CURR_SLOT = oldslot;
10279 break;
10280 case IA64_DVS_IMPLIED:
10281 case IA64_DVS_IMPLIEDF:
10282 if (md.debug_dv)
10283 fprintf (stderr, "Inserting stop\n");
10284 insn_group_break (1, 0, 0);
10285 break;
10286 default:
10287 break;
10291 /* Check the resources used by the given opcode against the current dependency
10292 list.
10294 The check is run once for each execution path encountered. In this case,
10295 a unique execution path is the sequence of instructions following a code
10296 entry point, e.g. the following has three execution paths, one starting
10297 at L0, one at L1, and one at L2.
10299 L0: nop
10300 L1: add
10301 L2: add
10302 br.ret
10305 static void
10306 check_dependencies (struct ia64_opcode *idesc)
10308 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
10309 int path;
10310 int i;
10312 /* Note that the number of marked resources may change within the
10313 loop if in auto mode. */
10314 i = 0;
10315 while (i < regdepslen)
10317 struct rsrc *rs = &regdeps[i];
10318 const struct ia64_dependency *dep = rs->dependency;
10319 int chkind;
10320 int note;
10321 int start_over = 0;
10323 if (dep->semantics == IA64_DVS_NONE
10324 || (chkind = depends_on (rs->depind, idesc)) == -1)
10326 ++i;
10327 continue;
10330 note = NOTE (opdeps->chks[chkind]);
10332 /* Check this resource against each execution path seen thus far. */
10333 for (path = 0; path <= md.path; path++)
10335 int matchtype;
10337 /* If the dependency wasn't on the path being checked, ignore it. */
10338 if (rs->path < path)
10339 continue;
10341 /* If the QP for this insn implies a QP which has branched, don't
10342 bother checking. Ed. NOTE: I don't think this check is terribly
10343 useful; what's the point of generating code which will only be
10344 reached if its QP is zero?
10345 This code was specifically inserted to handle the following code,
10346 based on notes from Intel's DV checking code, where p1 implies p2.
10348 mov r4 = 2
10349 (p2) br.cond L
10350 (p1) mov r4 = 7
10352 if (CURR_SLOT.qp_regno != 0)
10354 int skip = 0;
10355 int implies;
10356 for (implies = 0; implies < qp_implieslen; implies++)
10358 if (qp_implies[implies].path >= path
10359 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
10360 && qp_implies[implies].p2_branched)
10362 skip = 1;
10363 break;
10366 if (skip)
10367 continue;
10370 if ((matchtype = resources_match (rs, idesc, note,
10371 CURR_SLOT.qp_regno, path)) != 0)
10373 char msg[1024];
10374 char pathmsg[256] = "";
10375 char indexmsg[256] = "";
10376 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
10378 if (path != 0)
10379 snprintf (pathmsg, sizeof (pathmsg),
10380 " when entry is at label '%s'",
10381 md.entry_labels[path - 1]);
10382 if (matchtype == 1 && rs->index >= 0)
10383 snprintf (indexmsg, sizeof (indexmsg),
10384 ", specific resource number is %d",
10385 rs->index);
10386 snprintf (msg, sizeof (msg),
10387 "Use of '%s' %s %s dependency '%s' (%s)%s%s",
10388 idesc->name,
10389 (certain ? "violates" : "may violate"),
10390 dv_mode[dep->mode], dep->name,
10391 dv_sem[dep->semantics],
10392 pathmsg, indexmsg);
10394 if (md.explicit_mode)
10396 as_warn ("%s", msg);
10397 if (path < md.path)
10398 as_warn (_("Only the first path encountering the conflict is reported"));
10399 as_warn_where (rs->file, rs->line,
10400 _("This is the location of the conflicting usage"));
10401 /* Don't bother checking other paths, to avoid duplicating
10402 the same warning */
10403 break;
10405 else
10407 if (md.debug_dv)
10408 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
10410 remove_marked_resource (rs);
10412 /* since the set of dependencies has changed, start over */
10413 /* FIXME -- since we're removing dvs as we go, we
10414 probably don't really need to start over... */
10415 start_over = 1;
10416 break;
10420 if (start_over)
10421 i = 0;
10422 else
10423 ++i;
10427 /* Register new dependencies based on the given opcode. */
10429 static void
10430 mark_resources (struct ia64_opcode *idesc)
10432 int i;
10433 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
10434 int add_only_qp_reads = 0;
10436 /* A conditional branch only uses its resources if it is taken; if it is
10437 taken, we stop following that path. The other branch types effectively
10438 *always* write their resources. If it's not taken, register only QP
10439 reads. */
10440 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
10442 add_only_qp_reads = 1;
10445 if (md.debug_dv)
10446 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
10448 for (i = 0; i < opdeps->nregs; i++)
10450 const struct ia64_dependency *dep;
10451 struct rsrc specs[MAX_SPECS];
10452 int note;
10453 int path;
10454 int count;
10456 dep = ia64_find_dependency (opdeps->regs[i]);
10457 note = NOTE (opdeps->regs[i]);
10459 if (add_only_qp_reads
10460 && !(dep->mode == IA64_DV_WAR
10461 && (dep->specifier == IA64_RS_PR
10462 || dep->specifier == IA64_RS_PRr
10463 || dep->specifier == IA64_RS_PR63)))
10464 continue;
10466 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
10468 while (count-- > 0)
10470 mark_resource (idesc, dep, &specs[count],
10471 DEP (opdeps->regs[i]), md.path);
10474 /* The execution path may affect register values, which may in turn
10475 affect which indirect-access resources are accessed. */
10476 switch (dep->specifier)
10478 default:
10479 break;
10480 case IA64_RS_CPUID:
10481 case IA64_RS_DBR:
10482 case IA64_RS_IBR:
10483 case IA64_RS_MSR:
10484 case IA64_RS_PKR:
10485 case IA64_RS_PMC:
10486 case IA64_RS_PMD:
10487 case IA64_RS_RR:
10488 for (path = 0; path < md.path; path++)
10490 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
10491 while (count-- > 0)
10492 mark_resource (idesc, dep, &specs[count],
10493 DEP (opdeps->regs[i]), path);
10495 break;
10500 /* Remove dependencies when they no longer apply. */
10502 static void
10503 update_dependencies (struct ia64_opcode *idesc)
10505 int i;
10507 if (strcmp (idesc->name, "srlz.i") == 0)
10509 instruction_serialization ();
10511 else if (strcmp (idesc->name, "srlz.d") == 0)
10513 data_serialization ();
10515 else if (is_interruption_or_rfi (idesc)
10516 || is_taken_branch (idesc))
10518 /* Although technically the taken branch doesn't clear dependencies
10519 which require a srlz.[id], we don't follow the branch; the next
10520 instruction is assumed to start with a clean slate. */
10521 regdepslen = 0;
10522 md.path = 0;
10524 else if (is_conditional_branch (idesc)
10525 && CURR_SLOT.qp_regno != 0)
10527 int is_call = strstr (idesc->name, ".call") != NULL;
10529 for (i = 0; i < qp_implieslen; i++)
10531 /* If the conditional branch's predicate is implied by the predicate
10532 in an existing dependency, remove that dependency. */
10533 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
10535 int depind = 0;
10536 /* Note that this implied predicate takes a branch so that if
10537 a later insn generates a DV but its predicate implies this
10538 one, we can avoid the false DV warning. */
10539 qp_implies[i].p2_branched = 1;
10540 while (depind < regdepslen)
10542 if (regdeps[depind].qp_regno == qp_implies[i].p1)
10544 print_dependency ("Removing", depind);
10545 regdeps[depind] = regdeps[--regdepslen];
10547 else
10548 ++depind;
10552 /* Any marked resources which have this same predicate should be
10553 cleared, provided that the QP hasn't been modified between the
10554 marking instruction and the branch. */
10555 if (is_call)
10557 insn_group_break (0, CURR_SLOT.qp_regno, 1);
10559 else
10561 i = 0;
10562 while (i < regdepslen)
10564 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
10565 && regdeps[i].link_to_qp_branch
10566 && (regdeps[i].file != CURR_SLOT.src_file
10567 || regdeps[i].line != CURR_SLOT.src_line))
10569 /* Treat like a taken branch */
10570 print_dependency ("Removing", i);
10571 regdeps[i] = regdeps[--regdepslen];
10573 else
10574 ++i;
10580 /* Examine the current instruction for dependency violations. */
10582 static int
10583 check_dv (struct ia64_opcode *idesc)
10585 if (md.debug_dv)
10587 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
10588 idesc->name, CURR_SLOT.src_line,
10589 idesc->dependencies->nchks,
10590 idesc->dependencies->nregs);
10593 /* Look through the list of currently marked resources; if the current
10594 instruction has the dependency in its chks list which uses that resource,
10595 check against the specific resources used. */
10596 check_dependencies (idesc);
10598 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
10599 then add them to the list of marked resources. */
10600 mark_resources (idesc);
10602 /* There are several types of dependency semantics, and each has its own
10603 requirements for being cleared
10605 Instruction serialization (insns separated by interruption, rfi, or
10606 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
10608 Data serialization (instruction serialization, or writer + srlz.d +
10609 reader, where writer and srlz.d are in separate groups) clears
10610 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
10611 always be the case).
10613 Instruction group break (groups separated by stop, taken branch,
10614 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
10616 update_dependencies (idesc);
10618 /* Sometimes, knowing a register value allows us to avoid giving a false DV
10619 warning. Keep track of as many as possible that are useful. */
10620 note_register_values (idesc);
10622 /* We don't need or want this anymore. */
10623 md.mem_offset.hint = 0;
10625 return 0;
10628 /* Translate one line of assembly. Pseudo ops and labels do not show
10629 here. */
10630 void
10631 md_assemble (char *str)
10633 char *saved_input_line_pointer, *temp;
10634 const char *mnemonic;
10635 const struct pseudo_opcode *pdesc;
10636 struct ia64_opcode *idesc;
10637 unsigned char qp_regno;
10638 unsigned int flags;
10639 int ch;
10641 saved_input_line_pointer = input_line_pointer;
10642 input_line_pointer = str;
10644 /* extract the opcode (mnemonic): */
10646 ch = get_symbol_name (&temp);
10647 mnemonic = temp;
10648 pdesc = (struct pseudo_opcode *) str_hash_find (md.pseudo_hash, mnemonic);
10649 if (pdesc)
10651 (void) restore_line_pointer (ch);
10652 (*pdesc->handler) (pdesc->arg);
10653 goto done;
10656 /* Find the instruction descriptor matching the arguments. */
10658 idesc = ia64_find_opcode (mnemonic);
10659 (void) restore_line_pointer (ch);
10660 if (!idesc)
10662 as_bad (_("Unknown opcode `%s'"), mnemonic);
10663 goto done;
10666 idesc = parse_operands (idesc);
10667 if (!idesc)
10668 goto done;
10670 /* Handle the dynamic ops we can handle now: */
10671 if (idesc->type == IA64_TYPE_DYN)
10673 if (strcmp (idesc->name, "add") == 0)
10675 if (CURR_SLOT.opnd[2].X_op == O_register
10676 && CURR_SLOT.opnd[2].X_add_number < 4)
10677 mnemonic = "addl";
10678 else
10679 mnemonic = "adds";
10680 ia64_free_opcode (idesc);
10681 idesc = ia64_find_opcode (mnemonic);
10683 else if (strcmp (idesc->name, "mov") == 0)
10685 enum ia64_opnd opnd1, opnd2;
10686 int rop;
10688 opnd1 = idesc->operands[0];
10689 opnd2 = idesc->operands[1];
10690 if (opnd1 == IA64_OPND_AR3)
10691 rop = 0;
10692 else if (opnd2 == IA64_OPND_AR3)
10693 rop = 1;
10694 else
10695 abort ();
10696 if (CURR_SLOT.opnd[rop].X_op == O_register)
10698 if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10699 mnemonic = "mov.i";
10700 else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number))
10701 mnemonic = "mov.m";
10702 else
10703 rop = -1;
10705 else
10706 abort ();
10707 if (rop >= 0)
10709 ia64_free_opcode (idesc);
10710 idesc = ia64_find_opcode (mnemonic);
10711 while (idesc != NULL
10712 && (idesc->operands[0] != opnd1
10713 || idesc->operands[1] != opnd2))
10714 idesc = get_next_opcode (idesc);
10718 else if (strcmp (idesc->name, "mov.i") == 0
10719 || strcmp (idesc->name, "mov.m") == 0)
10721 enum ia64_opnd opnd1, opnd2;
10722 int rop;
10724 opnd1 = idesc->operands[0];
10725 opnd2 = idesc->operands[1];
10726 if (opnd1 == IA64_OPND_AR3)
10727 rop = 0;
10728 else if (opnd2 == IA64_OPND_AR3)
10729 rop = 1;
10730 else
10731 abort ();
10732 if (CURR_SLOT.opnd[rop].X_op == O_register)
10734 char unit = 'a';
10735 if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10736 unit = 'i';
10737 else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number))
10738 unit = 'm';
10739 if (unit != 'a' && unit != idesc->name [4])
10740 as_bad (_("AR %d can only be accessed by %c-unit"),
10741 (int) (CURR_SLOT.opnd[rop].X_add_number - REG_AR),
10742 TOUPPER (unit));
10745 else if (strcmp (idesc->name, "hint.b") == 0)
10747 switch (md.hint_b)
10749 case hint_b_ok:
10750 break;
10751 case hint_b_warning:
10752 as_warn (_("hint.b may be treated as nop"));
10753 break;
10754 case hint_b_error:
10755 as_bad (_("hint.b shouldn't be used"));
10756 break;
10760 qp_regno = 0;
10761 if (md.qp.X_op == O_register)
10763 qp_regno = md.qp.X_add_number - REG_P;
10764 md.qp.X_op = O_absent;
10767 flags = idesc->flags;
10769 if ((flags & IA64_OPCODE_FIRST) != 0)
10771 /* The alignment frag has to end with a stop bit only if the
10772 next instruction after the alignment directive has to be
10773 the first instruction in an instruction group. */
10774 if (align_frag)
10776 while (align_frag->fr_type != rs_align_code)
10778 align_frag = align_frag->fr_next;
10779 if (!align_frag)
10780 break;
10782 /* align_frag can be NULL if there are directives in
10783 between. */
10784 if (align_frag && align_frag->fr_next == frag_now)
10785 align_frag->tc_frag_data = 1;
10788 insn_group_break (1, 0, 0);
10790 align_frag = NULL;
10792 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
10794 as_bad (_("`%s' cannot be predicated"), idesc->name);
10795 goto done;
10798 /* Build the instruction. */
10799 CURR_SLOT.qp_regno = qp_regno;
10800 CURR_SLOT.idesc = idesc;
10801 CURR_SLOT.src_file = as_where (&CURR_SLOT.src_line);
10802 dwarf2_where (&CURR_SLOT.debug_line);
10803 dwarf2_consume_line_info ();
10805 /* Add unwind entries, if there are any. */
10806 if (unwind.current_entry)
10808 CURR_SLOT.unwind_record = unwind.current_entry;
10809 unwind.current_entry = NULL;
10811 if (unwind.pending_saves)
10813 if (unwind.pending_saves->next)
10815 /* Attach the next pending save to the next slot so that its
10816 slot number will get set correctly. */
10817 add_unwind_entry (unwind.pending_saves->next, NOT_A_CHAR);
10818 unwind.pending_saves = &unwind.pending_saves->next->r.record.p;
10820 else
10821 unwind.pending_saves = NULL;
10823 if (unwind.proc_pending.sym && S_IS_DEFINED (unwind.proc_pending.sym))
10824 unwind.insn = 1;
10826 /* Check for dependency violations. */
10827 if (md.detect_dv)
10828 check_dv (idesc);
10830 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10831 if (++md.num_slots_in_use >= NUM_SLOTS)
10832 emit_one_bundle ();
10834 if ((flags & IA64_OPCODE_LAST) != 0)
10835 insn_group_break (1, 0, 0);
10837 md.last_text_seg = now_seg;
10838 md.last_text_subseg = now_subseg;
10840 done:
10841 input_line_pointer = saved_input_line_pointer;
10844 /* Called when symbol NAME cannot be found in the symbol table.
10845 Should be used for dynamic valued symbols only. */
10847 symbolS *
10848 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
10850 return 0;
10853 /* Called for any expression that can not be recognized. When the
10854 function is called, `input_line_pointer' will point to the start of
10855 the expression. */
10857 void
10858 md_operand (expressionS *e)
10860 switch (*input_line_pointer)
10862 case '[':
10863 ++input_line_pointer;
10864 expression_and_evaluate (e);
10865 if (*input_line_pointer != ']')
10867 as_bad (_("Closing bracket missing"));
10868 goto err;
10870 else
10872 if (e->X_op != O_register
10873 || e->X_add_number < REG_GR
10874 || e->X_add_number > REG_GR + 127)
10876 as_bad (_("Index must be a general register"));
10877 e->X_add_number = REG_GR;
10880 ++input_line_pointer;
10881 e->X_op = O_index;
10883 break;
10885 default:
10886 break;
10888 return;
10890 err:
10891 ignore_rest_of_line ();
10894 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
10895 a section symbol plus some offset. For relocs involving @fptr(),
10896 directives we don't want such adjustments since we need to have the
10897 original symbol's name in the reloc. */
10899 ia64_fix_adjustable (fixS *fix)
10901 /* Prevent all adjustments to global symbols */
10902 if (S_IS_EXTERNAL (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
10903 return 0;
10905 switch (fix->fx_r_type)
10907 case BFD_RELOC_IA64_FPTR64I:
10908 case BFD_RELOC_IA64_FPTR32MSB:
10909 case BFD_RELOC_IA64_FPTR32LSB:
10910 case BFD_RELOC_IA64_FPTR64MSB:
10911 case BFD_RELOC_IA64_FPTR64LSB:
10912 case BFD_RELOC_IA64_LTOFF_FPTR22:
10913 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10914 return 0;
10915 default:
10916 break;
10919 return 1;
10923 ia64_force_relocation (fixS *fix)
10925 switch (fix->fx_r_type)
10927 case BFD_RELOC_IA64_FPTR64I:
10928 case BFD_RELOC_IA64_FPTR32MSB:
10929 case BFD_RELOC_IA64_FPTR32LSB:
10930 case BFD_RELOC_IA64_FPTR64MSB:
10931 case BFD_RELOC_IA64_FPTR64LSB:
10933 case BFD_RELOC_IA64_LTOFF22:
10934 case BFD_RELOC_IA64_LTOFF64I:
10935 case BFD_RELOC_IA64_LTOFF_FPTR22:
10936 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10937 case BFD_RELOC_IA64_PLTOFF22:
10938 case BFD_RELOC_IA64_PLTOFF64I:
10939 case BFD_RELOC_IA64_PLTOFF64MSB:
10940 case BFD_RELOC_IA64_PLTOFF64LSB:
10942 case BFD_RELOC_IA64_LTOFF22X:
10943 case BFD_RELOC_IA64_LDXMOV:
10944 return 1;
10946 default:
10947 break;
10950 return generic_force_reloc (fix);
10953 /* Decide from what point a pc-relative relocation is relative to,
10954 relative to the pc-relative fixup. Er, relatively speaking. */
10955 long
10956 ia64_pcrel_from_section (fixS *fix, segT sec)
10958 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10960 if (bfd_section_flags (sec) & SEC_CODE)
10961 off &= ~0xfUL;
10963 return off;
10967 /* Used to emit section-relative relocs for the dwarf2 debug data. */
10968 void
10969 ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
10971 expressionS exp;
10973 exp.X_op = O_pseudo_fixup;
10974 exp.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
10975 exp.X_add_number = 0;
10976 exp.X_add_symbol = symbol;
10977 emit_expr (&exp, size);
10980 /* This is called whenever some data item (not an instruction) needs a
10981 fixup. We pick the right reloc code depending on the byteorder
10982 currently in effect. */
10983 void
10984 ia64_cons_fix_new (fragS *f, int where, int nbytes, expressionS *exp,
10985 bfd_reloc_code_real_type code)
10987 fixS *fix;
10989 switch (nbytes)
10991 /* There are no reloc for 8 and 16 bit quantities, but we allow
10992 them here since they will work fine as long as the expression
10993 is fully defined at the end of the pass over the source file. */
10994 case 1: code = BFD_RELOC_8; break;
10995 case 2: code = BFD_RELOC_16; break;
10996 case 4:
10997 if (target_big_endian)
10998 code = BFD_RELOC_IA64_DIR32MSB;
10999 else
11000 code = BFD_RELOC_IA64_DIR32LSB;
11001 break;
11003 case 8:
11004 /* In 32-bit mode, data8 could mean function descriptors too. */
11005 if (exp->X_op == O_pseudo_fixup
11006 && exp->X_op_symbol
11007 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
11008 && !(md.flags & EF_IA_64_ABI64))
11010 if (target_big_endian)
11011 code = BFD_RELOC_IA64_IPLTMSB;
11012 else
11013 code = BFD_RELOC_IA64_IPLTLSB;
11014 exp->X_op = O_symbol;
11015 break;
11017 else
11019 if (target_big_endian)
11020 code = BFD_RELOC_IA64_DIR64MSB;
11021 else
11022 code = BFD_RELOC_IA64_DIR64LSB;
11023 break;
11026 case 16:
11027 if (exp->X_op == O_pseudo_fixup
11028 && exp->X_op_symbol
11029 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
11031 if (target_big_endian)
11032 code = BFD_RELOC_IA64_IPLTMSB;
11033 else
11034 code = BFD_RELOC_IA64_IPLTLSB;
11035 exp->X_op = O_symbol;
11036 break;
11038 /* FALLTHRU */
11040 default:
11041 as_bad (_("Unsupported fixup size %d"), nbytes);
11042 ignore_rest_of_line ();
11043 return;
11046 if (exp->X_op == O_pseudo_fixup)
11048 exp->X_op = O_symbol;
11049 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
11050 /* ??? If code unchanged, unsupported. */
11053 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
11054 /* We need to store the byte order in effect in case we're going
11055 to fix an 8 or 16 bit relocation (for which there no real
11056 relocs available). See md_apply_fix(). */
11057 fix->tc_fix_data.bigendian = target_big_endian;
11060 /* Return the actual relocation we wish to associate with the pseudo
11061 reloc described by SYM and R_TYPE. SYM should be one of the
11062 symbols in the pseudo_func array, or NULL. */
11064 static bfd_reloc_code_real_type
11065 ia64_gen_real_reloc_type (struct symbol *sym, bfd_reloc_code_real_type r_type)
11067 bfd_reloc_code_real_type newr = 0;
11068 const char *type = NULL, *suffix = "";
11070 if (sym == NULL)
11072 return r_type;
11075 switch (S_GET_VALUE (sym))
11077 case FUNC_FPTR_RELATIVE:
11078 switch (r_type)
11080 case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_FPTR64I; break;
11081 case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_FPTR32MSB; break;
11082 case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_FPTR32LSB; break;
11083 case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_FPTR64MSB; break;
11084 case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_FPTR64LSB; break;
11085 default: type = "FPTR"; break;
11087 break;
11089 case FUNC_GP_RELATIVE:
11090 switch (r_type)
11092 case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_GPREL22; break;
11093 case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_GPREL64I; break;
11094 case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_GPREL32MSB; break;
11095 case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_GPREL32LSB; break;
11096 case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_GPREL64MSB; break;
11097 case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_GPREL64LSB; break;
11098 default: type = "GPREL"; break;
11100 break;
11102 case FUNC_LT_RELATIVE:
11103 switch (r_type)
11105 case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_LTOFF22; break;
11106 case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_LTOFF64I; break;
11107 default: type = "LTOFF"; break;
11109 break;
11111 case FUNC_LT_RELATIVE_X:
11112 switch (r_type)
11114 case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_LTOFF22X; break;
11115 default: type = "LTOFF"; suffix = "X"; break;
11117 break;
11119 case FUNC_PC_RELATIVE:
11120 switch (r_type)
11122 case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_PCREL22; break;
11123 case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_PCREL64I; break;
11124 case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_PCREL32MSB; break;
11125 case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_PCREL32LSB; break;
11126 case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_PCREL64MSB; break;
11127 case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_PCREL64LSB; break;
11128 default: type = "PCREL"; break;
11130 break;
11132 case FUNC_PLT_RELATIVE:
11133 switch (r_type)
11135 case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_PLTOFF22; break;
11136 case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_PLTOFF64I; break;
11137 case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_PLTOFF64MSB;break;
11138 case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_PLTOFF64LSB;break;
11139 default: type = "PLTOFF"; break;
11141 break;
11143 case FUNC_SEC_RELATIVE:
11144 switch (r_type)
11146 case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_SECREL32MSB;break;
11147 case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_SECREL32LSB;break;
11148 case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_SECREL64MSB;break;
11149 case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_SECREL64LSB;break;
11150 default: type = "SECREL"; break;
11152 break;
11154 case FUNC_SEG_RELATIVE:
11155 switch (r_type)
11157 case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_SEGREL32MSB;break;
11158 case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_SEGREL32LSB;break;
11159 case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_SEGREL64MSB;break;
11160 case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_SEGREL64LSB;break;
11161 default: type = "SEGREL"; break;
11163 break;
11165 case FUNC_LTV_RELATIVE:
11166 switch (r_type)
11168 case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_LTV32MSB; break;
11169 case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_LTV32LSB; break;
11170 case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_LTV64MSB; break;
11171 case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_LTV64LSB; break;
11172 default: type = "LTV"; break;
11174 break;
11176 case FUNC_LT_FPTR_RELATIVE:
11177 switch (r_type)
11179 case BFD_RELOC_IA64_IMM22:
11180 newr = BFD_RELOC_IA64_LTOFF_FPTR22; break;
11181 case BFD_RELOC_IA64_IMM64:
11182 newr = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
11183 case BFD_RELOC_IA64_DIR32MSB:
11184 newr = BFD_RELOC_IA64_LTOFF_FPTR32MSB; break;
11185 case BFD_RELOC_IA64_DIR32LSB:
11186 newr = BFD_RELOC_IA64_LTOFF_FPTR32LSB; break;
11187 case BFD_RELOC_IA64_DIR64MSB:
11188 newr = BFD_RELOC_IA64_LTOFF_FPTR64MSB; break;
11189 case BFD_RELOC_IA64_DIR64LSB:
11190 newr = BFD_RELOC_IA64_LTOFF_FPTR64LSB; break;
11191 default:
11192 type = "LTOFF_FPTR"; break;
11194 break;
11196 case FUNC_TP_RELATIVE:
11197 switch (r_type)
11199 case BFD_RELOC_IA64_IMM14: newr = BFD_RELOC_IA64_TPREL14; break;
11200 case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_TPREL22; break;
11201 case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_TPREL64I; break;
11202 case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_TPREL64MSB; break;
11203 case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_TPREL64LSB; break;
11204 default: type = "TPREL"; break;
11206 break;
11208 case FUNC_LT_TP_RELATIVE:
11209 switch (r_type)
11211 case BFD_RELOC_IA64_IMM22:
11212 newr = BFD_RELOC_IA64_LTOFF_TPREL22; break;
11213 default:
11214 type = "LTOFF_TPREL"; break;
11216 break;
11218 case FUNC_DTP_MODULE:
11219 switch (r_type)
11221 case BFD_RELOC_IA64_DIR64MSB:
11222 newr = BFD_RELOC_IA64_DTPMOD64MSB; break;
11223 case BFD_RELOC_IA64_DIR64LSB:
11224 newr = BFD_RELOC_IA64_DTPMOD64LSB; break;
11225 default:
11226 type = "DTPMOD"; break;
11228 break;
11230 case FUNC_LT_DTP_MODULE:
11231 switch (r_type)
11233 case BFD_RELOC_IA64_IMM22:
11234 newr = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
11235 default:
11236 type = "LTOFF_DTPMOD"; break;
11238 break;
11240 case FUNC_DTP_RELATIVE:
11241 switch (r_type)
11243 case BFD_RELOC_IA64_DIR32MSB:
11244 newr = BFD_RELOC_IA64_DTPREL32MSB; break;
11245 case BFD_RELOC_IA64_DIR32LSB:
11246 newr = BFD_RELOC_IA64_DTPREL32LSB; break;
11247 case BFD_RELOC_IA64_DIR64MSB:
11248 newr = BFD_RELOC_IA64_DTPREL64MSB; break;
11249 case BFD_RELOC_IA64_DIR64LSB:
11250 newr = BFD_RELOC_IA64_DTPREL64LSB; break;
11251 case BFD_RELOC_IA64_IMM14:
11252 newr = BFD_RELOC_IA64_DTPREL14; break;
11253 case BFD_RELOC_IA64_IMM22:
11254 newr = BFD_RELOC_IA64_DTPREL22; break;
11255 case BFD_RELOC_IA64_IMM64:
11256 newr = BFD_RELOC_IA64_DTPREL64I; break;
11257 default:
11258 type = "DTPREL"; break;
11260 break;
11262 case FUNC_LT_DTP_RELATIVE:
11263 switch (r_type)
11265 case BFD_RELOC_IA64_IMM22:
11266 newr = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
11267 default:
11268 type = "LTOFF_DTPREL"; break;
11270 break;
11272 case FUNC_IPLT_RELOC:
11273 switch (r_type)
11275 case BFD_RELOC_IA64_IPLTMSB: return r_type;
11276 case BFD_RELOC_IA64_IPLTLSB: return r_type;
11277 default: type = "IPLT"; break;
11279 break;
11281 #ifdef TE_VMS
11282 case FUNC_SLOTCOUNT_RELOC:
11283 return DUMMY_RELOC_IA64_SLOTCOUNT;
11284 #endif
11286 default:
11287 abort ();
11290 if (newr)
11291 return newr;
11292 else
11294 int width;
11296 if (!type)
11297 abort ();
11298 switch (r_type)
11300 case BFD_RELOC_IA64_DIR32MSB: width = 32; suffix = "MSB"; break;
11301 case BFD_RELOC_IA64_DIR32LSB: width = 32; suffix = "LSB"; break;
11302 case BFD_RELOC_IA64_DIR64MSB: width = 64; suffix = "MSB"; break;
11303 case BFD_RELOC_IA64_DIR64LSB: width = 64; suffix = "LSB"; break;
11304 case BFD_RELOC_UNUSED: width = 13; break;
11305 case BFD_RELOC_IA64_IMM14: width = 14; break;
11306 case BFD_RELOC_IA64_IMM22: width = 22; break;
11307 case BFD_RELOC_IA64_IMM64: width = 64; suffix = "I"; break;
11308 default: abort ();
11311 /* This should be an error, but since previously there wasn't any
11312 diagnostic here, don't make it fail because of this for now. */
11313 as_warn (_("Cannot express %s%d%s relocation"), type, width, suffix);
11314 return r_type;
11318 /* Here is where generate the appropriate reloc for pseudo relocation
11319 functions. */
11320 void
11321 ia64_validate_fix (fixS *fix)
11323 switch (fix->fx_r_type)
11325 case BFD_RELOC_IA64_FPTR64I:
11326 case BFD_RELOC_IA64_FPTR32MSB:
11327 case BFD_RELOC_IA64_FPTR64LSB:
11328 case BFD_RELOC_IA64_LTOFF_FPTR22:
11329 case BFD_RELOC_IA64_LTOFF_FPTR64I:
11330 if (fix->fx_offset != 0)
11331 as_bad_where (fix->fx_file, fix->fx_line,
11332 _("No addend allowed in @fptr() relocation"));
11333 break;
11334 default:
11335 break;
11339 static void
11340 fix_insn (fixS *fix, const struct ia64_operand *odesc, valueT value)
11342 bfd_vma insn[3], t0, t1, control_bits;
11343 const char *err;
11344 char *fixpos;
11345 long slot;
11347 slot = fix->fx_where & 0x3;
11348 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
11350 /* Bundles are always in little-endian byte order */
11351 t0 = bfd_getl64 (fixpos);
11352 t1 = bfd_getl64 (fixpos + 8);
11353 control_bits = t0 & 0x1f;
11354 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
11355 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
11356 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
11358 err = NULL;
11359 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
11361 insn[1] = (value >> 22) & 0x1ffffffffffLL;
11362 insn[2] |= (((value & 0x7f) << 13)
11363 | (((value >> 7) & 0x1ff) << 27)
11364 | (((value >> 16) & 0x1f) << 22)
11365 | (((value >> 21) & 0x1) << 21)
11366 | (((value >> 63) & 0x1) << 36));
11368 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
11370 if (value & ~0x3fffffffffffffffULL)
11371 err = _("integer operand out of range");
11372 insn[1] = (value >> 21) & 0x1ffffffffffLL;
11373 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
11375 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
11377 value >>= 4;
11378 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
11379 insn[2] |= ((((value >> 59) & 0x1) << 36)
11380 | (((value >> 0) & 0xfffff) << 13));
11382 else
11383 err = (*odesc->insert) (odesc, value, insn + slot);
11385 if (err)
11386 as_bad_where (fix->fx_file, fix->fx_line, "%s", err);
11388 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
11389 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
11390 number_to_chars_littleendian (fixpos + 0, t0, 8);
11391 number_to_chars_littleendian (fixpos + 8, t1, 8);
11394 /* Attempt to simplify or even eliminate a fixup. The return value is
11395 ignored; perhaps it was once meaningful, but now it is historical.
11396 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
11398 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
11399 (if possible). */
11401 void
11402 md_apply_fix (fixS *fix, valueT *valP, segT seg ATTRIBUTE_UNUSED)
11404 char *fixpos;
11405 valueT value = *valP;
11407 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
11409 if (fix->fx_pcrel)
11411 switch (fix->fx_r_type)
11413 case BFD_RELOC_IA64_PCREL21B: break;
11414 case BFD_RELOC_IA64_PCREL21BI: break;
11415 case BFD_RELOC_IA64_PCREL21F: break;
11416 case BFD_RELOC_IA64_PCREL21M: break;
11417 case BFD_RELOC_IA64_PCREL60B: break;
11418 case BFD_RELOC_IA64_PCREL22: break;
11419 case BFD_RELOC_IA64_PCREL64I: break;
11420 case BFD_RELOC_IA64_PCREL32MSB: break;
11421 case BFD_RELOC_IA64_PCREL32LSB: break;
11422 case BFD_RELOC_IA64_PCREL64MSB: break;
11423 case BFD_RELOC_IA64_PCREL64LSB: break;
11424 default:
11425 fix->fx_r_type = ia64_gen_real_reloc_type (pseudo_func[FUNC_PC_RELATIVE].u.sym,
11426 fix->fx_r_type);
11427 break;
11430 if (fix->fx_addsy)
11432 switch ((unsigned) fix->fx_r_type)
11434 case BFD_RELOC_UNUSED:
11435 /* This must be a TAG13 or TAG13b operand. There are no external
11436 relocs defined for them, so we must give an error. */
11437 as_bad_where (fix->fx_file, fix->fx_line,
11438 _("%s must have a constant value"),
11439 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
11440 fix->fx_done = 1;
11441 return;
11443 case BFD_RELOC_IA64_TPREL14:
11444 case BFD_RELOC_IA64_TPREL22:
11445 case BFD_RELOC_IA64_TPREL64I:
11446 case BFD_RELOC_IA64_LTOFF_TPREL22:
11447 case BFD_RELOC_IA64_LTOFF_DTPMOD22:
11448 case BFD_RELOC_IA64_DTPREL14:
11449 case BFD_RELOC_IA64_DTPREL22:
11450 case BFD_RELOC_IA64_DTPREL64I:
11451 case BFD_RELOC_IA64_LTOFF_DTPREL22:
11452 S_SET_THREAD_LOCAL (fix->fx_addsy);
11453 break;
11455 #ifdef TE_VMS
11456 case DUMMY_RELOC_IA64_SLOTCOUNT:
11457 as_bad_where (fix->fx_file, fix->fx_line,
11458 _("cannot resolve @slotcount parameter"));
11459 fix->fx_done = 1;
11460 return;
11461 #endif
11463 default:
11464 break;
11467 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
11469 #ifdef TE_VMS
11470 if (fix->fx_r_type == DUMMY_RELOC_IA64_SLOTCOUNT)
11472 /* For @slotcount, convert an addresses difference to a slots
11473 difference. */
11474 valueT v;
11476 v = (value >> 4) * 3;
11477 switch (value & 0x0f)
11479 case 0:
11480 case 1:
11481 case 2:
11482 v += value & 0x0f;
11483 break;
11484 case 0x0f:
11485 v += 2;
11486 break;
11487 case 0x0e:
11488 v += 1;
11489 break;
11490 default:
11491 as_bad (_("invalid @slotcount value"));
11493 value = v;
11495 #endif
11497 if (fix->tc_fix_data.bigendian)
11498 number_to_chars_bigendian (fixpos, value, fix->fx_size);
11499 else
11500 number_to_chars_littleendian (fixpos, value, fix->fx_size);
11501 fix->fx_done = 1;
11503 else
11505 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
11506 fix->fx_done = 1;
11510 /* Generate the BFD reloc to be stuck in the object file from the
11511 fixup used internally in the assembler. */
11513 arelent *
11514 tc_gen_reloc (asection *sec ATTRIBUTE_UNUSED, fixS *fixp)
11516 arelent *reloc;
11518 reloc = notes_alloc (sizeof (arelent));
11519 reloc->sym_ptr_ptr = notes_alloc (sizeof (asymbol *));
11520 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11521 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
11522 reloc->addend = fixp->fx_offset;
11523 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
11525 if (!reloc->howto)
11527 as_bad_where (fixp->fx_file, fixp->fx_line,
11528 _("Cannot represent %s relocation in object file"),
11529 bfd_get_reloc_code_name (fixp->fx_r_type));
11530 return NULL;
11532 return reloc;
11535 /* Turn a string in input_line_pointer into a floating point constant
11536 of type TYPE, and store the appropriate bytes in *LIT. The number
11537 of LITTLENUMS emitted is stored in *SIZE. An error message is
11538 returned, or NULL on OK. */
11540 const char *
11541 md_atof (int type, char *lit, int *size)
11543 LITTLENUM_TYPE words[MAX_LITTLENUMS];
11544 char *t;
11545 int prec;
11547 switch (type)
11549 /* IEEE floats */
11550 case 'f':
11551 case 'F':
11552 case 's':
11553 case 'S':
11554 prec = 2;
11555 break;
11557 case 'd':
11558 case 'D':
11559 case 'r':
11560 case 'R':
11561 prec = 4;
11562 break;
11564 case 'x':
11565 case 'X':
11566 case 'p':
11567 case 'P':
11568 prec = 5;
11569 break;
11571 default:
11572 *size = 0;
11573 return _("Unrecognized or unsupported floating point constant");
11575 t = atof_ieee (input_line_pointer, type, words);
11576 if (t)
11577 input_line_pointer = t;
11579 (*ia64_float_to_chars) (lit, words, prec);
11581 if (type == 'X')
11583 /* It is 10 byte floating point with 6 byte padding. */
11584 memset (&lit [10], 0, 6);
11585 *size = 8 * sizeof (LITTLENUM_TYPE);
11587 else
11588 *size = prec * sizeof (LITTLENUM_TYPE);
11590 return NULL;
11593 /* Handle ia64 specific semantics of the align directive. */
11595 void
11596 ia64_md_do_align (int n ATTRIBUTE_UNUSED,
11597 const char *fill ATTRIBUTE_UNUSED,
11598 int len ATTRIBUTE_UNUSED,
11599 int max ATTRIBUTE_UNUSED)
11601 if (subseg_text_p (now_seg))
11602 ia64_flush_insns ();
11605 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
11606 of an rs_align_code fragment. */
11608 void
11609 ia64_handle_align (fragS *fragp)
11611 int bytes;
11612 char *p;
11613 const unsigned char *nop_type;
11615 if (fragp->fr_type != rs_align_code)
11616 return;
11618 /* Check if this frag has to end with a stop bit. */
11619 nop_type = fragp->tc_frag_data ? le_nop_stop : le_nop;
11621 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
11622 p = fragp->fr_literal + fragp->fr_fix;
11624 /* If no paddings are needed, we check if we need a stop bit. */
11625 if (!bytes && fragp->tc_frag_data)
11627 if (fragp->fr_fix < 16)
11628 #if 1
11629 /* FIXME: It won't work with
11630 .align 16
11631 alloc r32=ar.pfs,1,2,4,0
11634 #else
11635 as_bad_where (fragp->fr_file, fragp->fr_line,
11636 _("Can't add stop bit to mark end of instruction group"));
11637 #endif
11638 else
11639 /* Bundles are always in little-endian byte order. Make sure
11640 the previous bundle has the stop bit. */
11641 *(p - 16) |= 1;
11644 /* Make sure we are on a 16-byte boundary, in case someone has been
11645 putting data into a text section. */
11646 if (bytes & 15)
11648 int fix = bytes & 15;
11649 memset (p, 0, fix);
11650 p += fix;
11651 bytes -= fix;
11652 fragp->fr_fix += fix;
11655 /* Instruction bundles are always little-endian. */
11656 memcpy (p, nop_type, 16);
11657 fragp->fr_var = 16;
11660 static void
11661 ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words,
11662 int prec)
11664 while (prec--)
11666 number_to_chars_bigendian (lit, (long) (*words++),
11667 sizeof (LITTLENUM_TYPE));
11668 lit += sizeof (LITTLENUM_TYPE);
11672 static void
11673 ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words,
11674 int prec)
11676 while (prec--)
11678 number_to_chars_littleendian (lit, (long) (words[prec]),
11679 sizeof (LITTLENUM_TYPE));
11680 lit += sizeof (LITTLENUM_TYPE);
11684 void
11685 ia64_elf_section_change_hook (void)
11687 if (elf_section_type (now_seg) == SHT_IA_64_UNWIND
11688 && elf_linked_to_section (now_seg) == NULL)
11689 elf_linked_to_section (now_seg) = text_section;
11690 dot_byteorder (-1);
11693 /* Check if a label should be made global. */
11694 void
11695 ia64_check_label (symbolS *label)
11697 if (*input_line_pointer == ':')
11699 S_SET_EXTERNAL (label);
11700 input_line_pointer++;
11704 /* Used to remember where .alias and .secalias directives are seen. We
11705 will rename symbol and section names when we are about to output
11706 the relocatable file. */
11707 struct alias
11709 const char *file; /* The file where the directive is seen. */
11710 unsigned int line; /* The line number the directive is at. */
11711 const char *name; /* The original name of the symbol. */
11714 /* Called for .alias and .secalias directives. If SECTION is 1, it is
11715 .secalias. Otherwise, it is .alias. */
11716 static void
11717 dot_alias (int section)
11719 char *name, *alias;
11720 char delim;
11721 char *end_name;
11722 int len;
11723 struct alias *h;
11724 const char *a;
11725 htab_t ahash, nhash;
11726 const char *kind;
11728 delim = get_symbol_name (&name);
11729 end_name = input_line_pointer;
11730 restore_line_pointer (delim);
11732 if (name == end_name)
11734 as_bad (_("expected symbol name"));
11735 ignore_rest_of_line ();
11736 return;
11739 SKIP_WHITESPACE ();
11741 if (*input_line_pointer != ',')
11743 *end_name = 0;
11744 as_bad (_("expected comma after \"%s\""), name);
11745 *end_name = delim;
11746 ignore_rest_of_line ();
11747 return;
11750 input_line_pointer++;
11751 *end_name = 0;
11752 ia64_canonicalize_symbol_name (name);
11754 /* We call demand_copy_C_string to check if alias string is valid.
11755 There should be a closing `"' and no `\0' in the string. */
11756 alias = demand_copy_C_string (&len);
11757 if (alias == NULL)
11759 ignore_rest_of_line ();
11760 return;
11763 /* Make a copy of name string. */
11764 name = notes_strdup (name);
11766 if (section)
11768 kind = "section";
11769 ahash = secalias_hash;
11770 nhash = secalias_name_hash;
11772 else
11774 kind = "symbol";
11775 ahash = alias_hash;
11776 nhash = alias_name_hash;
11779 /* Check if alias has been used before. */
11781 h = (struct alias *) str_hash_find (ahash, alias);
11782 if (h)
11784 if (strcmp (h->name, name))
11785 as_bad (_("`%s' is already the alias of %s `%s'"),
11786 alias, kind, h->name);
11787 notes_free (alias);
11788 goto out;
11791 /* Check if name already has an alias. */
11792 a = (const char *) str_hash_find (nhash, name);
11793 if (a)
11795 if (strcmp (a, alias))
11796 as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a);
11797 notes_free (alias);
11798 goto out;
11801 h = notes_alloc (sizeof (*h));
11802 h->file = as_where (&h->line);
11803 h->name = name;
11805 str_hash_insert (ahash, alias, h, 0);
11806 str_hash_insert (nhash, name, alias, 0);
11808 out:
11809 demand_empty_rest_of_line ();
11812 /* It renames the original symbol name to its alias. */
11813 static int
11814 do_alias (void **slot, void *arg ATTRIBUTE_UNUSED)
11816 string_tuple_t *tuple = *((string_tuple_t **) slot);
11817 struct alias *h = (struct alias *) tuple->value;
11818 symbolS *sym = symbol_find (h->name);
11820 if (sym == NULL)
11822 #ifdef TE_VMS
11823 /* Uses .alias extensively to alias CRTL functions to same with
11824 decc$ prefix. Sometimes function gets optimized away and a
11825 warning results, which should be suppressed. */
11826 if (!startswith (tuple->key, "decc$"))
11827 #endif
11828 as_warn_where (h->file, h->line,
11829 _("symbol `%s' aliased to `%s' is not used"),
11830 h->name, tuple->key);
11832 else
11833 S_SET_NAME (sym, (char *) tuple->key);
11835 return 1;
11838 /* Called from write_object_file. */
11839 void
11840 ia64_adjust_symtab (void)
11842 htab_traverse_noresize (alias_hash, do_alias, NULL);
11845 /* It renames the original section name to its alias. */
11846 static int
11847 do_secalias (void **slot, void *arg ATTRIBUTE_UNUSED)
11849 string_tuple_t *tuple = *((string_tuple_t **) slot);
11850 struct alias *h = (struct alias *) tuple->value;
11851 segT sec = bfd_get_section_by_name (stdoutput, h->name);
11853 if (sec == NULL)
11854 as_warn_where (h->file, h->line,
11855 _("section `%s' aliased to `%s' is not used"),
11856 h->name, tuple->key);
11857 else
11858 sec->name = tuple->key;
11860 return 1;
11863 /* Called from write_object_file. */
11864 void
11865 ia64_frob_file (void)
11867 htab_traverse_noresize (secalias_hash, do_secalias, NULL);
11870 #ifdef TE_VMS
11871 #define NT_VMS_MHD 1
11872 #define NT_VMS_LNM 2
11874 /* Integrity VMS 8.x identifies it's ELF modules with a standard ELF
11875 .note section. */
11877 /* Manufacture a VMS-like time string. */
11878 static void
11879 get_vms_time (char *Now)
11881 char *pnt;
11882 time_t timeb;
11884 time (&timeb);
11885 pnt = ctime (&timeb);
11886 pnt[3] = 0;
11887 pnt[7] = 0;
11888 pnt[10] = 0;
11889 pnt[16] = 0;
11890 pnt[24] = 0;
11891 sprintf (Now, "%2s-%3s-%s %s", pnt + 8, pnt + 4, pnt + 20, pnt + 11);
11894 void
11895 ia64_vms_note (void)
11897 char *p;
11898 asection *seg = now_seg;
11899 subsegT subseg = now_subseg;
11900 asection *secp = NULL;
11901 char *bname;
11902 char buf [256];
11903 symbolS *sym;
11905 /* Create the .note section. */
11907 secp = subseg_new (".note", 0);
11908 bfd_set_section_flags (secp, SEC_HAS_CONTENTS | SEC_READONLY);
11910 /* Module header note (MHD). */
11911 bname = xstrdup (lbasename (out_file_name));
11912 if ((p = strrchr (bname, '.')))
11913 *p = '\0';
11915 /* VMS note header is 24 bytes long. */
11916 p = frag_more (8 + 8 + 8);
11917 number_to_chars_littleendian (p + 0, 8, 8);
11918 number_to_chars_littleendian (p + 8, 40 + strlen (bname), 8);
11919 number_to_chars_littleendian (p + 16, NT_VMS_MHD, 8);
11921 p = frag_more (8);
11922 strcpy (p, "IPF/VMS");
11924 p = frag_more (17 + 17 + strlen (bname) + 1 + 5);
11925 get_vms_time (p);
11926 strcpy (p + 17, "24-FEB-2005 15:00");
11927 p += 17 + 17;
11928 strcpy (p, bname);
11929 p += strlen (bname) + 1;
11930 free (bname);
11931 strcpy (p, "V1.0");
11933 frag_align (3, 0, 0);
11935 /* Language processor name note. */
11936 sprintf (buf, "GNU assembler version %s (%s) using BFD version %s",
11937 VERSION, TARGET_ALIAS, BFD_VERSION_STRING);
11939 p = frag_more (8 + 8 + 8);
11940 number_to_chars_littleendian (p + 0, 8, 8);
11941 number_to_chars_littleendian (p + 8, strlen (buf) + 1, 8);
11942 number_to_chars_littleendian (p + 16, NT_VMS_LNM, 8);
11944 p = frag_more (8);
11945 strcpy (p, "IPF/VMS");
11947 p = frag_more (strlen (buf) + 1);
11948 strcpy (p, buf);
11950 frag_align (3, 0, 0);
11952 secp = subseg_new (".vms_display_name_info", 0);
11953 bfd_set_section_flags (secp, SEC_HAS_CONTENTS | SEC_READONLY);
11955 /* This symbol should be passed on the command line and be variable
11956 according to language. */
11957 sym = symbol_new ("__gnat_vms_display_name@gnat_demangler_rtl",
11958 absolute_section, &zero_address_frag, 0);
11959 symbol_table_insert (sym);
11960 symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING | BSF_DYNAMIC;
11962 p = frag_more (4);
11963 /* Format 3 of VMS demangler Spec. */
11964 number_to_chars_littleendian (p, 3, 4);
11966 p = frag_more (4);
11967 /* Place holder for symbol table index of above symbol. */
11968 number_to_chars_littleendian (p, -1, 4);
11970 frag_align (3, 0, 0);
11972 /* We probably can't restore the current segment, for there likely
11973 isn't one yet... */
11974 if (seg && subseg)
11975 subseg_set (seg, subseg);
11978 #endif /* TE_VMS */