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