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