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