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