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