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