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