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