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