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