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