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