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