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