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