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