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