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