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