Update the address and phone number of the FSF
[binutils.git] / gas / config / tc-ia64.c
blob31adc3d36f558f2a2a063e15bc7c3037a84c750d
1 /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture.
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
4 Contributed by David Mosberger-Tang <davidm@hpl.hp.com>
6 This file is part of GAS, the GNU Assembler.
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.
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.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to
20 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
21 Boston, MA 02110-1301, USA. */
24 TODO:
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)
45 #include "as.h"
46 #include "safe-ctype.h"
47 #include "dwarf2dbg.h"
48 #include "subsegs.h"
50 #include "opcode/ia64.h"
52 #include "elf/ia64.h"
54 #ifdef HAVE_LIMITS_H
55 #include <limits.h>
56 #endif
58 #define NELEMS(a) ((int) (sizeof (a)/sizeof ((a)[0])))
59 #define MIN(a,b) ((a) < (b) ? (a) : (b))
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]
65 #define O_pseudo_fixup (O_max + 1)
67 enum special_section
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,
82 enum reloc_func
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,
103 enum reg_symbol
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
136 enum dynreg_type
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
144 enum operand_match_result
146 OPERAND_MATCH,
147 OPERAND_OUT_OF_RANGE,
148 OPERAND_MISMATCH
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
157 struct label_fix *next;
158 struct symbol *sym;
161 /* This is the endianness of the current section. */
162 extern int target_big_endian;
164 /* This is the default endianness. */
165 static int default_big_endian = TARGET_BYTES_BIG_ENDIAN;
167 void (*ia64_number_to_chars) PARAMS ((char *, valueT, int));
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));
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;
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[] = "@?";
185 /* Characters which always start a comment. */
186 const char comment_chars[] = "";
188 /* Characters which start a comment at the beginning of a line. */
189 const char line_comment_chars[] = "#";
191 /* Characters which may be used to separate multiple commands on a
192 single line. */
193 const char line_separator_chars[] = ";";
195 /* Characters which are used to indicate an exponent in a floating
196 point number. */
197 const char EXP_CHARS[] = "eE";
199 /* Characters which mean that a number is a floating point constant,
200 as in 0d1.0. */
201 const char FLT_CHARS[] = "rRsSfFdDxXpP";
203 /* ia64-specific option processing: */
205 const char *md_shortopts = "m:N:x::";
207 struct option md_longopts[] =
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}
215 size_t md_longopts_size = sizeof (md_longopts);
217 static struct
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 */
225 symbolS *regsym[REG_NUM];
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;
232 /* Optimize for which CPU. */
233 enum
235 itanium1,
236 itanium2
237 } tune;
239 /* What to do when hint.b is used. */
240 enum
242 hint_b_error,
243 hint_b_warning,
244 hint_b_ok
245 } hint_b;
247 unsigned int
248 manual_bundling : 1,
249 debug_dv: 1,
250 detect_dv: 1,
251 explicit_mode : 1, /* which mode we're in */
252 default_explicit_mode : 1, /* which mode is the default */
253 mode_explicitly_set : 1, /* was the current mode explicitly set? */
254 auto_align : 1,
255 keep_pending_output : 1;
257 /* What to do when something is wrong with unwind directives. */
258 enum
260 unwind_check_warning,
261 unwind_check_error
262 } unwind_check;
264 /* Each bundle consists of up to three instructions. We keep
265 track of four most recent instructions so we can correctly set
266 the end_of_insn_group for the last instruction in a bundle. */
267 int curr_slot;
268 int num_slots_in_use;
269 struct slot
271 unsigned int
272 end_of_insn_group : 1,
273 manual_bundling_on : 1,
274 manual_bundling_off : 1,
275 loc_directive_seen : 1;
276 signed char user_template; /* user-selected template, if any */
277 unsigned char qp_regno; /* qualifying predicate */
278 /* This duplicates a good fraction of "struct fix" but we
279 can't use a "struct fix" instead since we can't call
280 fix_new_exp() until we know the address of the instruction. */
281 int num_fixups;
282 struct insn_fix
284 bfd_reloc_code_real_type code;
285 enum ia64_opnd opnd; /* type of operand in need of fix */
286 unsigned int is_pcrel : 1; /* is operand pc-relative? */
287 expressionS expr; /* the value to be inserted */
289 fixup[2]; /* at most two fixups per insn */
290 struct ia64_opcode *idesc;
291 struct label_fix *label_fixups;
292 struct label_fix *tag_fixups;
293 struct unw_rec_list *unwind_record; /* Unwind directive. */
294 expressionS opnd[6];
295 char *src_file;
296 unsigned int src_line;
297 struct dwarf2_line_info debug_line;
299 slot[NUM_SLOTS];
301 segT last_text_seg;
303 struct dynreg
305 struct dynreg *next; /* next dynamic register */
306 const char *name;
307 unsigned short base; /* the base register number */
308 unsigned short num_regs; /* # of registers in this set */
310 *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot;
312 flagword flags; /* ELF-header flags */
314 struct mem_offset {
315 unsigned hint:1; /* is this hint currently valid? */
316 bfd_vma offset; /* mem.offset offset */
317 bfd_vma base; /* mem.offset base */
318 } mem_offset;
320 int path; /* number of alt. entry points seen */
321 const char **entry_labels; /* labels of all alternate paths in
322 the current DV-checking block. */
323 int maxpaths; /* size currently allocated for
324 entry_labels */
326 int pointer_size; /* size in bytes of a pointer */
327 int pointer_size_shift; /* shift size of a pointer for alignment */
331 /* These are not const, because they are modified to MMI for non-itanium1
332 targets below. */
333 /* MFI bundle of nops. */
334 static unsigned char le_nop[16] =
336 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
337 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00
339 /* MFI bundle of nops with stop-bit. */
340 static unsigned char le_nop_stop[16] =
342 0x0d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
343 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00
346 /* application registers: */
348 #define AR_K0 0
349 #define AR_K7 7
350 #define AR_RSC 16
351 #define AR_BSP 17
352 #define AR_BSPSTORE 18
353 #define AR_RNAT 19
354 #define AR_UNAT 36
355 #define AR_FPSR 40
356 #define AR_ITC 44
357 #define AR_PFS 64
358 #define AR_LC 65
360 static const struct
362 const char *name;
363 int regnum;
365 ar[] =
367 {"ar.k0", 0}, {"ar.k1", 1}, {"ar.k2", 2}, {"ar.k3", 3},
368 {"ar.k4", 4}, {"ar.k5", 5}, {"ar.k6", 6}, {"ar.k7", 7},
369 {"ar.rsc", 16}, {"ar.bsp", 17},
370 {"ar.bspstore", 18}, {"ar.rnat", 19},
371 {"ar.fcr", 21}, {"ar.eflag", 24},
372 {"ar.csd", 25}, {"ar.ssd", 26},
373 {"ar.cflg", 27}, {"ar.fsr", 28},
374 {"ar.fir", 29}, {"ar.fdr", 30},
375 {"ar.ccv", 32}, {"ar.unat", 36},
376 {"ar.fpsr", 40}, {"ar.itc", 44},
377 {"ar.pfs", 64}, {"ar.lc", 65},
378 {"ar.ec", 66},
381 #define CR_IPSR 16
382 #define CR_ISR 17
383 #define CR_IIP 19
384 #define CR_IFA 20
385 #define CR_ITIR 21
386 #define CR_IIPA 22
387 #define CR_IFS 23
388 #define CR_IIM 24
389 #define CR_IHA 25
390 #define CR_IVR 65
391 #define CR_TPR 66
392 #define CR_EOI 67
393 #define CR_IRR0 68
394 #define CR_IRR3 71
395 #define CR_LRR0 80
396 #define CR_LRR1 81
398 /* control registers: */
399 static const struct
401 const char *name;
402 int regnum;
404 cr[] =
406 {"cr.dcr", 0},
407 {"cr.itm", 1},
408 {"cr.iva", 2},
409 {"cr.pta", 8},
410 {"cr.gpta", 9},
411 {"cr.ipsr", 16},
412 {"cr.isr", 17},
413 {"cr.iip", 19},
414 {"cr.ifa", 20},
415 {"cr.itir", 21},
416 {"cr.iipa", 22},
417 {"cr.ifs", 23},
418 {"cr.iim", 24},
419 {"cr.iha", 25},
420 {"cr.lid", 64},
421 {"cr.ivr", 65},
422 {"cr.tpr", 66},
423 {"cr.eoi", 67},
424 {"cr.irr0", 68},
425 {"cr.irr1", 69},
426 {"cr.irr2", 70},
427 {"cr.irr3", 71},
428 {"cr.itv", 72},
429 {"cr.pmv", 73},
430 {"cr.cmcv", 74},
431 {"cr.lrr0", 80},
432 {"cr.lrr1", 81}
435 #define PSR_MFL 4
436 #define PSR_IC 13
437 #define PSR_DFL 18
438 #define PSR_CPL 32
440 static const struct const_desc
442 const char *name;
443 valueT value;
445 const_bits[] =
447 /* PSR constant masks: */
449 /* 0: reserved */
450 {"psr.be", ((valueT) 1) << 1},
451 {"psr.up", ((valueT) 1) << 2},
452 {"psr.ac", ((valueT) 1) << 3},
453 {"psr.mfl", ((valueT) 1) << 4},
454 {"psr.mfh", ((valueT) 1) << 5},
455 /* 6-12: reserved */
456 {"psr.ic", ((valueT) 1) << 13},
457 {"psr.i", ((valueT) 1) << 14},
458 {"psr.pk", ((valueT) 1) << 15},
459 /* 16: reserved */
460 {"psr.dt", ((valueT) 1) << 17},
461 {"psr.dfl", ((valueT) 1) << 18},
462 {"psr.dfh", ((valueT) 1) << 19},
463 {"psr.sp", ((valueT) 1) << 20},
464 {"psr.pp", ((valueT) 1) << 21},
465 {"psr.di", ((valueT) 1) << 22},
466 {"psr.si", ((valueT) 1) << 23},
467 {"psr.db", ((valueT) 1) << 24},
468 {"psr.lp", ((valueT) 1) << 25},
469 {"psr.tb", ((valueT) 1) << 26},
470 {"psr.rt", ((valueT) 1) << 27},
471 /* 28-31: reserved */
472 /* 32-33: cpl (current privilege level) */
473 {"psr.is", ((valueT) 1) << 34},
474 {"psr.mc", ((valueT) 1) << 35},
475 {"psr.it", ((valueT) 1) << 36},
476 {"psr.id", ((valueT) 1) << 37},
477 {"psr.da", ((valueT) 1) << 38},
478 {"psr.dd", ((valueT) 1) << 39},
479 {"psr.ss", ((valueT) 1) << 40},
480 /* 41-42: ri (restart instruction) */
481 {"psr.ed", ((valueT) 1) << 43},
482 {"psr.bn", ((valueT) 1) << 44},
485 /* indirect register-sets/memory: */
487 static const struct
489 const char *name;
490 int regnum;
492 indirect_reg[] =
494 { "CPUID", IND_CPUID },
495 { "cpuid", IND_CPUID },
496 { "dbr", IND_DBR },
497 { "dtr", IND_DTR },
498 { "itr", IND_ITR },
499 { "ibr", IND_IBR },
500 { "msr", IND_MSR },
501 { "pkr", IND_PKR },
502 { "pmc", IND_PMC },
503 { "pmd", IND_PMD },
504 { "rr", IND_RR },
507 /* Pseudo functions used to indicate relocation types (these functions
508 start with an at sign (@). */
509 static struct
511 const char *name;
512 enum pseudo_type
514 PSEUDO_FUNC_NONE,
515 PSEUDO_FUNC_RELOC,
516 PSEUDO_FUNC_CONST,
517 PSEUDO_FUNC_REG,
518 PSEUDO_FUNC_FLOAT
520 type;
521 union
523 unsigned long ival;
524 symbolS *sym;
528 pseudo_func[] =
530 /* reloc pseudo functions (these must come first!): */
531 { "dtpmod", PSEUDO_FUNC_RELOC, { 0 } },
532 { "dtprel", PSEUDO_FUNC_RELOC, { 0 } },
533 { "fptr", PSEUDO_FUNC_RELOC, { 0 } },
534 { "gprel", PSEUDO_FUNC_RELOC, { 0 } },
535 { "ltoff", PSEUDO_FUNC_RELOC, { 0 } },
536 { "ltoffx", PSEUDO_FUNC_RELOC, { 0 } },
537 { "pcrel", PSEUDO_FUNC_RELOC, { 0 } },
538 { "pltoff", PSEUDO_FUNC_RELOC, { 0 } },
539 { "secrel", PSEUDO_FUNC_RELOC, { 0 } },
540 { "segrel", PSEUDO_FUNC_RELOC, { 0 } },
541 { "tprel", PSEUDO_FUNC_RELOC, { 0 } },
542 { "ltv", PSEUDO_FUNC_RELOC, { 0 } },
543 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */
544 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_DTP_MODULE */
545 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_DTP_RELATIVE */
546 { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_TP_RELATIVE */
547 { "iplt", PSEUDO_FUNC_RELOC, { 0 } },
549 /* mbtype4 constants: */
550 { "alt", PSEUDO_FUNC_CONST, { 0xa } },
551 { "brcst", PSEUDO_FUNC_CONST, { 0x0 } },
552 { "mix", PSEUDO_FUNC_CONST, { 0x8 } },
553 { "rev", PSEUDO_FUNC_CONST, { 0xb } },
554 { "shuf", PSEUDO_FUNC_CONST, { 0x9 } },
556 /* fclass constants: */
557 { "nat", PSEUDO_FUNC_CONST, { 0x100 } },
558 { "qnan", PSEUDO_FUNC_CONST, { 0x080 } },
559 { "snan", PSEUDO_FUNC_CONST, { 0x040 } },
560 { "pos", PSEUDO_FUNC_CONST, { 0x001 } },
561 { "neg", PSEUDO_FUNC_CONST, { 0x002 } },
562 { "zero", PSEUDO_FUNC_CONST, { 0x004 } },
563 { "unorm", PSEUDO_FUNC_CONST, { 0x008 } },
564 { "norm", PSEUDO_FUNC_CONST, { 0x010 } },
565 { "inf", PSEUDO_FUNC_CONST, { 0x020 } },
567 { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */
569 /* hint constants: */
570 { "pause", PSEUDO_FUNC_CONST, { 0x0 } },
572 /* unwind-related constants: */
573 { "svr4", PSEUDO_FUNC_CONST, { ELFOSABI_NONE } },
574 { "hpux", PSEUDO_FUNC_CONST, { ELFOSABI_HPUX } },
575 { "nt", PSEUDO_FUNC_CONST, { 2 } }, /* conflicts w/ELFOSABI_NETBSD */
576 { "linux", PSEUDO_FUNC_CONST, { ELFOSABI_LINUX } },
577 { "freebsd", PSEUDO_FUNC_CONST, { ELFOSABI_FREEBSD } },
578 { "openvms", PSEUDO_FUNC_CONST, { ELFOSABI_OPENVMS } },
579 { "nsk", PSEUDO_FUNC_CONST, { ELFOSABI_NSK } },
581 /* unwind-related registers: */
582 { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } }
585 /* 41-bit nop opcodes (one per unit): */
586 static const bfd_vma nop[IA64_NUM_UNITS] =
588 0x0000000000LL, /* NIL => break 0 */
589 0x0008000000LL, /* I-unit nop */
590 0x0008000000LL, /* M-unit nop */
591 0x4000000000LL, /* B-unit nop */
592 0x0008000000LL, /* F-unit nop */
593 0x0008000000LL, /* L-"unit" nop */
594 0x0008000000LL, /* X-unit nop */
597 /* Can't be `const' as it's passed to input routines (which have the
598 habit of setting temporary sentinels. */
599 static char special_section_name[][20] =
601 {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"},
602 {".IA_64.unwind"}, {".IA_64.unwind_info"},
603 {".init_array"}, {".fini_array"}
606 /* The best template for a particular sequence of up to three
607 instructions: */
608 #define N IA64_NUM_TYPES
609 static unsigned char best_template[N][N][N];
610 #undef N
612 /* Resource dependencies currently in effect */
613 static struct rsrc {
614 int depind; /* dependency index */
615 const struct ia64_dependency *dependency; /* actual dependency */
616 unsigned specific:1, /* is this a specific bit/regno? */
617 link_to_qp_branch:1; /* will a branch on the same QP clear it?*/
618 int index; /* specific regno/bit within dependency */
619 int note; /* optional qualifying note (0 if none) */
620 #define STATE_NONE 0
621 #define STATE_STOP 1
622 #define STATE_SRLZ 2
623 int insn_srlz; /* current insn serialization state */
624 int data_srlz; /* current data serialization state */
625 int qp_regno; /* qualifying predicate for this usage */
626 char *file; /* what file marked this dependency */
627 unsigned int line; /* what line marked this dependency */
628 struct mem_offset mem_offset; /* optional memory offset hint */
629 enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */
630 int path; /* corresponding code entry index */
631 } *regdeps = NULL;
632 static int regdepslen = 0;
633 static int regdepstotlen = 0;
634 static const char *dv_mode[] = { "RAW", "WAW", "WAR" };
635 static const char *dv_sem[] = { "none", "implied", "impliedf",
636 "data", "instr", "specific", "stop", "other" };
637 static const char *dv_cmp_type[] = { "none", "OR", "AND" };
639 /* Current state of PR mutexation */
640 static struct qpmutex {
641 valueT prmask;
642 int path;
643 } *qp_mutexes = NULL; /* QP mutex bitmasks */
644 static int qp_mutexeslen = 0;
645 static int qp_mutexestotlen = 0;
646 static valueT qp_safe_across_calls = 0;
648 /* Current state of PR implications */
649 static struct qp_imply {
650 unsigned p1:6;
651 unsigned p2:6;
652 unsigned p2_branched:1;
653 int path;
654 } *qp_implies = NULL;
655 static int qp_implieslen = 0;
656 static int qp_impliestotlen = 0;
658 /* Keep track of static GR values so that indirect register usage can
659 sometimes be tracked. */
660 static struct gr {
661 unsigned known:1;
662 int path;
663 valueT value;
664 } gr_values[128] = {
667 #ifdef INT_MAX
668 INT_MAX,
669 #else
670 (((1 << (8 * sizeof(gr_values->path) - 2)) - 1) << 1) + 1,
671 #endif
676 /* Remember the alignment frag. */
677 static fragS *align_frag;
679 /* These are the routines required to output the various types of
680 unwind records. */
682 /* A slot_number is a frag address plus the slot index (0-2). We use the
683 frag address here so that if there is a section switch in the middle of
684 a function, then instructions emitted to a different section are not
685 counted. Since there may be more than one frag for a function, this
686 means we also need to keep track of which frag this address belongs to
687 so we can compute inter-frag distances. This also nicely solves the
688 problem with nops emitted for align directives, which can't easily be
689 counted, but can easily be derived from frag sizes. */
691 typedef struct unw_rec_list {
692 unwind_record r;
693 unsigned long slot_number;
694 fragS *slot_frag;
695 unsigned long next_slot_number;
696 fragS *next_slot_frag;
697 struct unw_rec_list *next;
698 } unw_rec_list;
700 #define SLOT_NUM_NOT_SET (unsigned)-1
702 /* Linked list of saved prologue counts. A very poor
703 implementation of a map from label numbers to prologue counts. */
704 typedef struct label_prologue_count
706 struct label_prologue_count *next;
707 unsigned long label_number;
708 unsigned int prologue_count;
709 } label_prologue_count;
711 static struct
713 /* Maintain a list of unwind entries for the current function. */
714 unw_rec_list *list;
715 unw_rec_list *tail;
717 /* Any unwind entires that should be attached to the current slot
718 that an insn is being constructed for. */
719 unw_rec_list *current_entry;
721 /* These are used to create the unwind table entry for this function. */
722 symbolS *proc_start;
723 symbolS *info; /* pointer to unwind info */
724 symbolS *personality_routine;
725 segT saved_text_seg;
726 subsegT saved_text_subseg;
727 unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */
729 /* TRUE if processing unwind directives in a prologue region. */
730 unsigned int prologue : 1;
731 unsigned int prologue_mask : 4;
732 unsigned int body : 1;
733 unsigned int insn : 1;
734 unsigned int prologue_count; /* number of .prologues seen so far */
735 /* Prologue counts at previous .label_state directives. */
736 struct label_prologue_count * saved_prologue_counts;
737 } unwind;
739 /* The input value is a negated offset from psp, and specifies an address
740 psp - offset. The encoded value is psp + 16 - (4 * offset). Thus we
741 must add 16 and divide by 4 to get the encoded value. */
743 #define ENCODED_PSP_OFFSET(OFFSET) (((OFFSET) + 16) / 4)
745 typedef void (*vbyte_func) PARAMS ((int, char *, char *));
747 /* Forward declarations: */
748 static void set_section PARAMS ((char *name));
749 static unsigned int set_regstack PARAMS ((unsigned int, unsigned int,
750 unsigned int, unsigned int));
751 static void dot_align (int);
752 static void dot_radix PARAMS ((int));
753 static void dot_special_section PARAMS ((int));
754 static void dot_proc PARAMS ((int));
755 static void dot_fframe PARAMS ((int));
756 static void dot_vframe PARAMS ((int));
757 static void dot_vframesp PARAMS ((int));
758 static void dot_vframepsp PARAMS ((int));
759 static void dot_save PARAMS ((int));
760 static void dot_restore PARAMS ((int));
761 static void dot_restorereg PARAMS ((int));
762 static void dot_restorereg_p PARAMS ((int));
763 static void dot_handlerdata PARAMS ((int));
764 static void dot_unwentry PARAMS ((int));
765 static void dot_altrp PARAMS ((int));
766 static void dot_savemem PARAMS ((int));
767 static void dot_saveg PARAMS ((int));
768 static void dot_savef PARAMS ((int));
769 static void dot_saveb PARAMS ((int));
770 static void dot_savegf PARAMS ((int));
771 static void dot_spill PARAMS ((int));
772 static void dot_spillreg PARAMS ((int));
773 static void dot_spillmem PARAMS ((int));
774 static void dot_spillreg_p PARAMS ((int));
775 static void dot_spillmem_p PARAMS ((int));
776 static void dot_label_state PARAMS ((int));
777 static void dot_copy_state PARAMS ((int));
778 static void dot_unwabi PARAMS ((int));
779 static void dot_personality PARAMS ((int));
780 static void dot_body PARAMS ((int));
781 static void dot_prologue PARAMS ((int));
782 static void dot_endp PARAMS ((int));
783 static void dot_template PARAMS ((int));
784 static void dot_regstk PARAMS ((int));
785 static void dot_rot PARAMS ((int));
786 static void dot_byteorder PARAMS ((int));
787 static void dot_psr PARAMS ((int));
788 static void dot_alias PARAMS ((int));
789 static void dot_ln PARAMS ((int));
790 static void cross_section PARAMS ((int ref, void (*cons) PARAMS((int)), int ua));
791 static void dot_xdata PARAMS ((int));
792 static void stmt_float_cons PARAMS ((int));
793 static void stmt_cons_ua PARAMS ((int));
794 static void dot_xfloat_cons PARAMS ((int));
795 static void dot_xstringer PARAMS ((int));
796 static void dot_xdata_ua PARAMS ((int));
797 static void dot_xfloat_cons_ua PARAMS ((int));
798 static void print_prmask PARAMS ((valueT mask));
799 static void dot_pred_rel PARAMS ((int));
800 static void dot_reg_val PARAMS ((int));
801 static void dot_serialize PARAMS ((int));
802 static void dot_dv_mode PARAMS ((int));
803 static void dot_entry PARAMS ((int));
804 static void dot_mem_offset PARAMS ((int));
805 static void add_unwind_entry PARAMS((unw_rec_list *ptr));
806 static symbolS *declare_register PARAMS ((const char *name, int regnum));
807 static void declare_register_set PARAMS ((const char *, int, int));
808 static unsigned int operand_width PARAMS ((enum ia64_opnd));
809 static enum operand_match_result operand_match PARAMS ((const struct ia64_opcode *idesc,
810 int index,
811 expressionS *e));
812 static int parse_operand PARAMS ((expressionS *e));
813 static struct ia64_opcode * parse_operands PARAMS ((struct ia64_opcode *));
814 static void build_insn PARAMS ((struct slot *, bfd_vma *));
815 static void emit_one_bundle PARAMS ((void));
816 static void fix_insn PARAMS ((fixS *, const struct ia64_operand *, valueT));
817 static bfd_reloc_code_real_type ia64_gen_real_reloc_type PARAMS ((struct symbol *sym,
818 bfd_reloc_code_real_type r_type));
819 static void insn_group_break PARAMS ((int, int, int));
820 static void mark_resource PARAMS ((struct ia64_opcode *, const struct ia64_dependency *,
821 struct rsrc *, int depind, int path));
822 static void add_qp_mutex PARAMS((valueT mask));
823 static void add_qp_imply PARAMS((int p1, int p2));
824 static void clear_qp_branch_flag PARAMS((valueT mask));
825 static void clear_qp_mutex PARAMS((valueT mask));
826 static void clear_qp_implies PARAMS((valueT p1_mask, valueT p2_mask));
827 static int has_suffix_p PARAMS((const char *, const char *));
828 static void clear_register_values PARAMS ((void));
829 static void print_dependency PARAMS ((const char *action, int depind));
830 static void instruction_serialization PARAMS ((void));
831 static void data_serialization PARAMS ((void));
832 static void remove_marked_resource PARAMS ((struct rsrc *));
833 static int is_conditional_branch PARAMS ((struct ia64_opcode *));
834 static int is_taken_branch PARAMS ((struct ia64_opcode *));
835 static int is_interruption_or_rfi PARAMS ((struct ia64_opcode *));
836 static int depends_on PARAMS ((int, struct ia64_opcode *));
837 static int specify_resource PARAMS ((const struct ia64_dependency *,
838 struct ia64_opcode *, int, struct rsrc [], int, int));
839 static int check_dv PARAMS((struct ia64_opcode *idesc));
840 static void check_dependencies PARAMS((struct ia64_opcode *));
841 static void mark_resources PARAMS((struct ia64_opcode *));
842 static void update_dependencies PARAMS((struct ia64_opcode *));
843 static void note_register_values PARAMS((struct ia64_opcode *));
844 static int qp_mutex PARAMS ((int, int, int));
845 static int resources_match PARAMS ((struct rsrc *, struct ia64_opcode *, int, int, int));
846 static void output_vbyte_mem PARAMS ((int, char *, char *));
847 static void count_output PARAMS ((int, char *, char *));
848 static void output_R1_format PARAMS ((vbyte_func, unw_record_type, int));
849 static void output_R2_format PARAMS ((vbyte_func, int, int, unsigned long));
850 static void output_R3_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
851 static void output_P1_format PARAMS ((vbyte_func, int));
852 static void output_P2_format PARAMS ((vbyte_func, int, int));
853 static void output_P3_format PARAMS ((vbyte_func, unw_record_type, int));
854 static void output_P4_format PARAMS ((vbyte_func, unsigned char *, unsigned long));
855 static void output_P5_format PARAMS ((vbyte_func, int, unsigned long));
856 static void output_P6_format PARAMS ((vbyte_func, unw_record_type, int));
857 static void output_P7_format PARAMS ((vbyte_func, unw_record_type, unsigned long, unsigned long));
858 static void output_P8_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
859 static void output_P9_format PARAMS ((vbyte_func, int, int));
860 static void output_P10_format PARAMS ((vbyte_func, int, int));
861 static void output_B1_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
862 static void output_B2_format PARAMS ((vbyte_func, unsigned long, unsigned long));
863 static void output_B3_format PARAMS ((vbyte_func, unsigned long, unsigned long));
864 static void output_B4_format PARAMS ((vbyte_func, unw_record_type, unsigned long));
865 static char format_ab_reg PARAMS ((int, int));
866 static void output_X1_format PARAMS ((vbyte_func, unw_record_type, int, int, unsigned long,
867 unsigned long));
868 static void output_X2_format PARAMS ((vbyte_func, int, int, int, int, int, unsigned long));
869 static void output_X3_format PARAMS ((vbyte_func, unw_record_type, int, int, int, unsigned long,
870 unsigned long));
871 static void output_X4_format PARAMS ((vbyte_func, int, int, int, int, int, int, unsigned long));
872 static unw_rec_list *output_endp PARAMS ((void));
873 static unw_rec_list *output_prologue PARAMS ((void));
874 static unw_rec_list *output_prologue_gr PARAMS ((unsigned int, unsigned int));
875 static unw_rec_list *output_body PARAMS ((void));
876 static unw_rec_list *output_mem_stack_f PARAMS ((unsigned int));
877 static unw_rec_list *output_mem_stack_v PARAMS ((void));
878 static unw_rec_list *output_psp_gr PARAMS ((unsigned int));
879 static unw_rec_list *output_psp_sprel PARAMS ((unsigned int));
880 static unw_rec_list *output_rp_when PARAMS ((void));
881 static unw_rec_list *output_rp_gr PARAMS ((unsigned int));
882 static unw_rec_list *output_rp_br PARAMS ((unsigned int));
883 static unw_rec_list *output_rp_psprel PARAMS ((unsigned int));
884 static unw_rec_list *output_rp_sprel PARAMS ((unsigned int));
885 static unw_rec_list *output_pfs_when PARAMS ((void));
886 static unw_rec_list *output_pfs_gr PARAMS ((unsigned int));
887 static unw_rec_list *output_pfs_psprel PARAMS ((unsigned int));
888 static unw_rec_list *output_pfs_sprel PARAMS ((unsigned int));
889 static unw_rec_list *output_preds_when PARAMS ((void));
890 static unw_rec_list *output_preds_gr PARAMS ((unsigned int));
891 static unw_rec_list *output_preds_psprel PARAMS ((unsigned int));
892 static unw_rec_list *output_preds_sprel PARAMS ((unsigned int));
893 static unw_rec_list *output_fr_mem PARAMS ((unsigned int));
894 static unw_rec_list *output_frgr_mem PARAMS ((unsigned int, unsigned int));
895 static unw_rec_list *output_gr_gr PARAMS ((unsigned int, unsigned int));
896 static unw_rec_list *output_gr_mem PARAMS ((unsigned int));
897 static unw_rec_list *output_br_mem PARAMS ((unsigned int));
898 static unw_rec_list *output_br_gr PARAMS ((unsigned int, unsigned int));
899 static unw_rec_list *output_spill_base PARAMS ((unsigned int));
900 static unw_rec_list *output_unat_when PARAMS ((void));
901 static unw_rec_list *output_unat_gr PARAMS ((unsigned int));
902 static unw_rec_list *output_unat_psprel PARAMS ((unsigned int));
903 static unw_rec_list *output_unat_sprel PARAMS ((unsigned int));
904 static unw_rec_list *output_lc_when PARAMS ((void));
905 static unw_rec_list *output_lc_gr PARAMS ((unsigned int));
906 static unw_rec_list *output_lc_psprel PARAMS ((unsigned int));
907 static unw_rec_list *output_lc_sprel PARAMS ((unsigned int));
908 static unw_rec_list *output_fpsr_when PARAMS ((void));
909 static unw_rec_list *output_fpsr_gr PARAMS ((unsigned int));
910 static unw_rec_list *output_fpsr_psprel PARAMS ((unsigned int));
911 static unw_rec_list *output_fpsr_sprel PARAMS ((unsigned int));
912 static unw_rec_list *output_priunat_when_gr PARAMS ((void));
913 static unw_rec_list *output_priunat_when_mem PARAMS ((void));
914 static unw_rec_list *output_priunat_gr PARAMS ((unsigned int));
915 static unw_rec_list *output_priunat_psprel PARAMS ((unsigned int));
916 static unw_rec_list *output_priunat_sprel PARAMS ((unsigned int));
917 static unw_rec_list *output_bsp_when PARAMS ((void));
918 static unw_rec_list *output_bsp_gr PARAMS ((unsigned int));
919 static unw_rec_list *output_bsp_psprel PARAMS ((unsigned int));
920 static unw_rec_list *output_bsp_sprel PARAMS ((unsigned int));
921 static unw_rec_list *output_bspstore_when PARAMS ((void));
922 static unw_rec_list *output_bspstore_gr PARAMS ((unsigned int));
923 static unw_rec_list *output_bspstore_psprel PARAMS ((unsigned int));
924 static unw_rec_list *output_bspstore_sprel PARAMS ((unsigned int));
925 static unw_rec_list *output_rnat_when PARAMS ((void));
926 static unw_rec_list *output_rnat_gr PARAMS ((unsigned int));
927 static unw_rec_list *output_rnat_psprel PARAMS ((unsigned int));
928 static unw_rec_list *output_rnat_sprel PARAMS ((unsigned int));
929 static unw_rec_list *output_unwabi PARAMS ((unsigned long, unsigned long));
930 static unw_rec_list *output_epilogue PARAMS ((unsigned long));
931 static unw_rec_list *output_label_state PARAMS ((unsigned long));
932 static unw_rec_list *output_copy_state PARAMS ((unsigned long));
933 static unw_rec_list *output_spill_psprel PARAMS ((unsigned int, unsigned int, unsigned int));
934 static unw_rec_list *output_spill_sprel PARAMS ((unsigned int, unsigned int, unsigned int));
935 static unw_rec_list *output_spill_psprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
936 unsigned int));
937 static unw_rec_list *output_spill_sprel_p PARAMS ((unsigned int, unsigned int, unsigned int,
938 unsigned int));
939 static unw_rec_list *output_spill_reg PARAMS ((unsigned int, unsigned int, unsigned int,
940 unsigned int));
941 static unw_rec_list *output_spill_reg_p PARAMS ((unsigned int, unsigned int, unsigned int,
942 unsigned int, unsigned int));
943 static void process_one_record PARAMS ((unw_rec_list *, vbyte_func));
944 static void process_unw_records PARAMS ((unw_rec_list *, vbyte_func));
945 static int calc_record_size PARAMS ((unw_rec_list *));
946 static void set_imask PARAMS ((unw_rec_list *, unsigned long, unsigned long, unsigned int));
947 static unsigned long slot_index PARAMS ((unsigned long, fragS *,
948 unsigned long, fragS *,
949 int));
950 static unw_rec_list *optimize_unw_records PARAMS ((unw_rec_list *));
951 static void fixup_unw_records PARAMS ((unw_rec_list *, int));
952 static int convert_expr_to_ab_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
953 static int convert_expr_to_xy_reg PARAMS ((expressionS *, unsigned int *, unsigned int *));
954 static unsigned int get_saved_prologue_count PARAMS ((unsigned long));
955 static void save_prologue_count PARAMS ((unsigned long, unsigned int));
956 static void free_saved_prologue_counts PARAMS ((void));
958 /* Determine if application register REGNUM resides only in the integer
959 unit (as opposed to the memory unit). */
960 static int
961 ar_is_only_in_integer_unit (int reg)
963 reg -= REG_AR;
964 return reg >= 64 && reg <= 111;
967 /* Determine if application register REGNUM resides only in the memory
968 unit (as opposed to the integer unit). */
969 static int
970 ar_is_only_in_memory_unit (int reg)
972 reg -= REG_AR;
973 return reg >= 0 && reg <= 47;
976 /* Switch to section NAME and create section if necessary. It's
977 rather ugly that we have to manipulate input_line_pointer but I
978 don't see any other way to accomplish the same thing without
979 changing obj-elf.c (which may be the Right Thing, in the end). */
980 static void
981 set_section (name)
982 char *name;
984 char *saved_input_line_pointer;
986 saved_input_line_pointer = input_line_pointer;
987 input_line_pointer = name;
988 obj_elf_section (0);
989 input_line_pointer = saved_input_line_pointer;
992 /* Map 's' to SHF_IA_64_SHORT. */
995 ia64_elf_section_letter (letter, ptr_msg)
996 int letter;
997 char **ptr_msg;
999 if (letter == 's')
1000 return SHF_IA_64_SHORT;
1001 else if (letter == 'o')
1002 return SHF_LINK_ORDER;
1004 *ptr_msg = _("Bad .section directive: want a,o,s,w,x,M,S,G,T in string");
1005 return -1;
1008 /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */
1010 flagword
1011 ia64_elf_section_flags (flags, attr, type)
1012 flagword flags;
1013 int attr, type ATTRIBUTE_UNUSED;
1015 if (attr & SHF_IA_64_SHORT)
1016 flags |= SEC_SMALL_DATA;
1017 return flags;
1021 ia64_elf_section_type (str, len)
1022 const char *str;
1023 size_t len;
1025 #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0))
1027 if (STREQ (ELF_STRING_ia64_unwind_info))
1028 return SHT_PROGBITS;
1030 if (STREQ (ELF_STRING_ia64_unwind_info_once))
1031 return SHT_PROGBITS;
1033 if (STREQ (ELF_STRING_ia64_unwind))
1034 return SHT_IA_64_UNWIND;
1036 if (STREQ (ELF_STRING_ia64_unwind_once))
1037 return SHT_IA_64_UNWIND;
1039 if (STREQ ("unwind"))
1040 return SHT_IA_64_UNWIND;
1042 return -1;
1043 #undef STREQ
1046 static unsigned int
1047 set_regstack (ins, locs, outs, rots)
1048 unsigned int ins, locs, outs, rots;
1050 /* Size of frame. */
1051 unsigned int sof;
1053 sof = ins + locs + outs;
1054 if (sof > 96)
1056 as_bad ("Size of frame exceeds maximum of 96 registers");
1057 return 0;
1059 if (rots > sof)
1061 as_warn ("Size of rotating registers exceeds frame size");
1062 return 0;
1064 md.in.base = REG_GR + 32;
1065 md.loc.base = md.in.base + ins;
1066 md.out.base = md.loc.base + locs;
1068 md.in.num_regs = ins;
1069 md.loc.num_regs = locs;
1070 md.out.num_regs = outs;
1071 md.rot.num_regs = rots;
1072 return sof;
1075 void
1076 ia64_flush_insns ()
1078 struct label_fix *lfix;
1079 segT saved_seg;
1080 subsegT saved_subseg;
1081 unw_rec_list *ptr;
1083 if (!md.last_text_seg)
1084 return;
1086 saved_seg = now_seg;
1087 saved_subseg = now_subseg;
1089 subseg_set (md.last_text_seg, 0);
1091 while (md.num_slots_in_use > 0)
1092 emit_one_bundle (); /* force out queued instructions */
1094 /* In case there are labels following the last instruction, resolve
1095 those now: */
1096 for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next)
1098 S_SET_VALUE (lfix->sym, frag_now_fix ());
1099 symbol_set_frag (lfix->sym, frag_now);
1101 CURR_SLOT.label_fixups = 0;
1102 for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next)
1104 S_SET_VALUE (lfix->sym, frag_now_fix ());
1105 symbol_set_frag (lfix->sym, frag_now);
1107 CURR_SLOT.tag_fixups = 0;
1109 /* In case there are unwind directives following the last instruction,
1110 resolve those now. We only handle prologue, body, and endp directives
1111 here. Give an error for others. */
1112 for (ptr = unwind.current_entry; ptr; ptr = ptr->next)
1114 switch (ptr->r.type)
1116 case prologue:
1117 case prologue_gr:
1118 case body:
1119 case endp:
1120 ptr->slot_number = (unsigned long) frag_more (0);
1121 ptr->slot_frag = frag_now;
1122 break;
1124 /* Allow any record which doesn't have a "t" field (i.e.,
1125 doesn't relate to a particular instruction). */
1126 case unwabi:
1127 case br_gr:
1128 case copy_state:
1129 case fr_mem:
1130 case frgr_mem:
1131 case gr_gr:
1132 case gr_mem:
1133 case label_state:
1134 case rp_br:
1135 case spill_base:
1136 case spill_mask:
1137 /* nothing */
1138 break;
1140 default:
1141 as_bad (_("Unwind directive not followed by an instruction."));
1142 break;
1145 unwind.current_entry = NULL;
1147 subseg_set (saved_seg, saved_subseg);
1149 if (md.qp.X_op == O_register)
1150 as_bad ("qualifying predicate not followed by instruction");
1153 static void
1154 ia64_do_align (int nbytes)
1156 char *saved_input_line_pointer = input_line_pointer;
1158 input_line_pointer = "";
1159 s_align_bytes (nbytes);
1160 input_line_pointer = saved_input_line_pointer;
1163 void
1164 ia64_cons_align (nbytes)
1165 int nbytes;
1167 if (md.auto_align)
1169 char *saved_input_line_pointer = input_line_pointer;
1170 input_line_pointer = "";
1171 s_align_bytes (nbytes);
1172 input_line_pointer = saved_input_line_pointer;
1176 /* Output COUNT bytes to a memory location. */
1177 static char *vbyte_mem_ptr = NULL;
1179 void
1180 output_vbyte_mem (count, ptr, comment)
1181 int count;
1182 char *ptr;
1183 char *comment ATTRIBUTE_UNUSED;
1185 int x;
1186 if (vbyte_mem_ptr == NULL)
1187 abort ();
1189 if (count == 0)
1190 return;
1191 for (x = 0; x < count; x++)
1192 *(vbyte_mem_ptr++) = ptr[x];
1195 /* Count the number of bytes required for records. */
1196 static int vbyte_count = 0;
1197 void
1198 count_output (count, ptr, comment)
1199 int count;
1200 char *ptr ATTRIBUTE_UNUSED;
1201 char *comment ATTRIBUTE_UNUSED;
1203 vbyte_count += count;
1206 static void
1207 output_R1_format (f, rtype, rlen)
1208 vbyte_func f;
1209 unw_record_type rtype;
1210 int rlen;
1212 int r = 0;
1213 char byte;
1214 if (rlen > 0x1f)
1216 output_R3_format (f, rtype, rlen);
1217 return;
1220 if (rtype == body)
1221 r = 1;
1222 else if (rtype != prologue)
1223 as_bad ("record type is not valid");
1225 byte = UNW_R1 | (r << 5) | (rlen & 0x1f);
1226 (*f) (1, &byte, NULL);
1229 static void
1230 output_R2_format (f, mask, grsave, rlen)
1231 vbyte_func f;
1232 int mask, grsave;
1233 unsigned long rlen;
1235 char bytes[20];
1236 int count = 2;
1237 mask = (mask & 0x0f);
1238 grsave = (grsave & 0x7f);
1240 bytes[0] = (UNW_R2 | (mask >> 1));
1241 bytes[1] = (((mask & 0x01) << 7) | grsave);
1242 count += output_leb128 (bytes + 2, rlen, 0);
1243 (*f) (count, bytes, NULL);
1246 static void
1247 output_R3_format (f, rtype, rlen)
1248 vbyte_func f;
1249 unw_record_type rtype;
1250 unsigned long rlen;
1252 int r = 0, count;
1253 char bytes[20];
1254 if (rlen <= 0x1f)
1256 output_R1_format (f, rtype, rlen);
1257 return;
1260 if (rtype == body)
1261 r = 1;
1262 else if (rtype != prologue)
1263 as_bad ("record type is not valid");
1264 bytes[0] = (UNW_R3 | r);
1265 count = output_leb128 (bytes + 1, rlen, 0);
1266 (*f) (count + 1, bytes, NULL);
1269 static void
1270 output_P1_format (f, brmask)
1271 vbyte_func f;
1272 int brmask;
1274 char byte;
1275 byte = UNW_P1 | (brmask & 0x1f);
1276 (*f) (1, &byte, NULL);
1279 static void
1280 output_P2_format (f, brmask, gr)
1281 vbyte_func f;
1282 int brmask;
1283 int gr;
1285 char bytes[2];
1286 brmask = (brmask & 0x1f);
1287 bytes[0] = UNW_P2 | (brmask >> 1);
1288 bytes[1] = (((brmask & 1) << 7) | gr);
1289 (*f) (2, bytes, NULL);
1292 static void
1293 output_P3_format (f, rtype, reg)
1294 vbyte_func f;
1295 unw_record_type rtype;
1296 int reg;
1298 char bytes[2];
1299 int r = 0;
1300 reg = (reg & 0x7f);
1301 switch (rtype)
1303 case psp_gr:
1304 r = 0;
1305 break;
1306 case rp_gr:
1307 r = 1;
1308 break;
1309 case pfs_gr:
1310 r = 2;
1311 break;
1312 case preds_gr:
1313 r = 3;
1314 break;
1315 case unat_gr:
1316 r = 4;
1317 break;
1318 case lc_gr:
1319 r = 5;
1320 break;
1321 case rp_br:
1322 r = 6;
1323 break;
1324 case rnat_gr:
1325 r = 7;
1326 break;
1327 case bsp_gr:
1328 r = 8;
1329 break;
1330 case bspstore_gr:
1331 r = 9;
1332 break;
1333 case fpsr_gr:
1334 r = 10;
1335 break;
1336 case priunat_gr:
1337 r = 11;
1338 break;
1339 default:
1340 as_bad ("Invalid record type for P3 format.");
1342 bytes[0] = (UNW_P3 | (r >> 1));
1343 bytes[1] = (((r & 1) << 7) | reg);
1344 (*f) (2, bytes, NULL);
1347 static void
1348 output_P4_format (f, imask, imask_size)
1349 vbyte_func f;
1350 unsigned char *imask;
1351 unsigned long imask_size;
1353 imask[0] = UNW_P4;
1354 (*f) (imask_size, (char *) imask, NULL);
1357 static void
1358 output_P5_format (f, grmask, frmask)
1359 vbyte_func f;
1360 int grmask;
1361 unsigned long frmask;
1363 char bytes[4];
1364 grmask = (grmask & 0x0f);
1366 bytes[0] = UNW_P5;
1367 bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16));
1368 bytes[2] = ((frmask & 0x0000ff00) >> 8);
1369 bytes[3] = (frmask & 0x000000ff);
1370 (*f) (4, bytes, NULL);
1373 static void
1374 output_P6_format (f, rtype, rmask)
1375 vbyte_func f;
1376 unw_record_type rtype;
1377 int rmask;
1379 char byte;
1380 int r = 0;
1382 if (rtype == gr_mem)
1383 r = 1;
1384 else if (rtype != fr_mem)
1385 as_bad ("Invalid record type for format P6");
1386 byte = (UNW_P6 | (r << 4) | (rmask & 0x0f));
1387 (*f) (1, &byte, NULL);
1390 static void
1391 output_P7_format (f, rtype, w1, w2)
1392 vbyte_func f;
1393 unw_record_type rtype;
1394 unsigned long w1;
1395 unsigned long w2;
1397 char bytes[20];
1398 int count = 1;
1399 int r = 0;
1400 count += output_leb128 (bytes + 1, w1, 0);
1401 switch (rtype)
1403 case mem_stack_f:
1404 r = 0;
1405 count += output_leb128 (bytes + count, w2 >> 4, 0);
1406 break;
1407 case mem_stack_v:
1408 r = 1;
1409 break;
1410 case spill_base:
1411 r = 2;
1412 break;
1413 case psp_sprel:
1414 r = 3;
1415 break;
1416 case rp_when:
1417 r = 4;
1418 break;
1419 case rp_psprel:
1420 r = 5;
1421 break;
1422 case pfs_when:
1423 r = 6;
1424 break;
1425 case pfs_psprel:
1426 r = 7;
1427 break;
1428 case preds_when:
1429 r = 8;
1430 break;
1431 case preds_psprel:
1432 r = 9;
1433 break;
1434 case lc_when:
1435 r = 10;
1436 break;
1437 case lc_psprel:
1438 r = 11;
1439 break;
1440 case unat_when:
1441 r = 12;
1442 break;
1443 case unat_psprel:
1444 r = 13;
1445 break;
1446 case fpsr_when:
1447 r = 14;
1448 break;
1449 case fpsr_psprel:
1450 r = 15;
1451 break;
1452 default:
1453 break;
1455 bytes[0] = (UNW_P7 | r);
1456 (*f) (count, bytes, NULL);
1459 static void
1460 output_P8_format (f, rtype, t)
1461 vbyte_func f;
1462 unw_record_type rtype;
1463 unsigned long t;
1465 char bytes[20];
1466 int r = 0;
1467 int count = 2;
1468 bytes[0] = UNW_P8;
1469 switch (rtype)
1471 case rp_sprel:
1472 r = 1;
1473 break;
1474 case pfs_sprel:
1475 r = 2;
1476 break;
1477 case preds_sprel:
1478 r = 3;
1479 break;
1480 case lc_sprel:
1481 r = 4;
1482 break;
1483 case unat_sprel:
1484 r = 5;
1485 break;
1486 case fpsr_sprel:
1487 r = 6;
1488 break;
1489 case bsp_when:
1490 r = 7;
1491 break;
1492 case bsp_psprel:
1493 r = 8;
1494 break;
1495 case bsp_sprel:
1496 r = 9;
1497 break;
1498 case bspstore_when:
1499 r = 10;
1500 break;
1501 case bspstore_psprel:
1502 r = 11;
1503 break;
1504 case bspstore_sprel:
1505 r = 12;
1506 break;
1507 case rnat_when:
1508 r = 13;
1509 break;
1510 case rnat_psprel:
1511 r = 14;
1512 break;
1513 case rnat_sprel:
1514 r = 15;
1515 break;
1516 case priunat_when_gr:
1517 r = 16;
1518 break;
1519 case priunat_psprel:
1520 r = 17;
1521 break;
1522 case priunat_sprel:
1523 r = 18;
1524 break;
1525 case priunat_when_mem:
1526 r = 19;
1527 break;
1528 default:
1529 break;
1531 bytes[1] = r;
1532 count += output_leb128 (bytes + 2, t, 0);
1533 (*f) (count, bytes, NULL);
1536 static void
1537 output_P9_format (f, grmask, gr)
1538 vbyte_func f;
1539 int grmask;
1540 int gr;
1542 char bytes[3];
1543 bytes[0] = UNW_P9;
1544 bytes[1] = (grmask & 0x0f);
1545 bytes[2] = (gr & 0x7f);
1546 (*f) (3, bytes, NULL);
1549 static void
1550 output_P10_format (f, abi, context)
1551 vbyte_func f;
1552 int abi;
1553 int context;
1555 char bytes[3];
1556 bytes[0] = UNW_P10;
1557 bytes[1] = (abi & 0xff);
1558 bytes[2] = (context & 0xff);
1559 (*f) (3, bytes, NULL);
1562 static void
1563 output_B1_format (f, rtype, label)
1564 vbyte_func f;
1565 unw_record_type rtype;
1566 unsigned long label;
1568 char byte;
1569 int r = 0;
1570 if (label > 0x1f)
1572 output_B4_format (f, rtype, label);
1573 return;
1575 if (rtype == copy_state)
1576 r = 1;
1577 else if (rtype != label_state)
1578 as_bad ("Invalid record type for format B1");
1580 byte = (UNW_B1 | (r << 5) | (label & 0x1f));
1581 (*f) (1, &byte, NULL);
1584 static void
1585 output_B2_format (f, ecount, t)
1586 vbyte_func f;
1587 unsigned long ecount;
1588 unsigned long t;
1590 char bytes[20];
1591 int count = 1;
1592 if (ecount > 0x1f)
1594 output_B3_format (f, ecount, t);
1595 return;
1597 bytes[0] = (UNW_B2 | (ecount & 0x1f));
1598 count += output_leb128 (bytes + 1, t, 0);
1599 (*f) (count, bytes, NULL);
1602 static void
1603 output_B3_format (f, ecount, t)
1604 vbyte_func f;
1605 unsigned long ecount;
1606 unsigned long t;
1608 char bytes[20];
1609 int count = 1;
1610 if (ecount <= 0x1f)
1612 output_B2_format (f, ecount, t);
1613 return;
1615 bytes[0] = UNW_B3;
1616 count += output_leb128 (bytes + 1, t, 0);
1617 count += output_leb128 (bytes + count, ecount, 0);
1618 (*f) (count, bytes, NULL);
1621 static void
1622 output_B4_format (f, rtype, label)
1623 vbyte_func f;
1624 unw_record_type rtype;
1625 unsigned long label;
1627 char bytes[20];
1628 int r = 0;
1629 int count = 1;
1630 if (label <= 0x1f)
1632 output_B1_format (f, rtype, label);
1633 return;
1636 if (rtype == copy_state)
1637 r = 1;
1638 else if (rtype != label_state)
1639 as_bad ("Invalid record type for format B1");
1641 bytes[0] = (UNW_B4 | (r << 3));
1642 count += output_leb128 (bytes + 1, label, 0);
1643 (*f) (count, bytes, NULL);
1646 static char
1647 format_ab_reg (ab, reg)
1648 int ab;
1649 int reg;
1651 int ret;
1652 ab = (ab & 3);
1653 reg = (reg & 0x1f);
1654 ret = (ab << 5) | reg;
1655 return ret;
1658 static void
1659 output_X1_format (f, rtype, ab, reg, t, w1)
1660 vbyte_func f;
1661 unw_record_type rtype;
1662 int ab, reg;
1663 unsigned long t;
1664 unsigned long w1;
1666 char bytes[20];
1667 int r = 0;
1668 int count = 2;
1669 bytes[0] = UNW_X1;
1671 if (rtype == spill_sprel)
1672 r = 1;
1673 else if (rtype != spill_psprel)
1674 as_bad ("Invalid record type for format X1");
1675 bytes[1] = ((r << 7) | format_ab_reg (ab, reg));
1676 count += output_leb128 (bytes + 2, t, 0);
1677 count += output_leb128 (bytes + count, w1, 0);
1678 (*f) (count, bytes, NULL);
1681 static void
1682 output_X2_format (f, ab, reg, x, y, treg, t)
1683 vbyte_func f;
1684 int ab, reg;
1685 int x, y, treg;
1686 unsigned long t;
1688 char bytes[20];
1689 int count = 3;
1690 bytes[0] = UNW_X2;
1691 bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1692 bytes[2] = (((y & 1) << 7) | (treg & 0x7f));
1693 count += output_leb128 (bytes + 3, t, 0);
1694 (*f) (count, bytes, NULL);
1697 static void
1698 output_X3_format (f, rtype, qp, ab, reg, t, w1)
1699 vbyte_func f;
1700 unw_record_type rtype;
1701 int qp;
1702 int ab, reg;
1703 unsigned long t;
1704 unsigned long w1;
1706 char bytes[20];
1707 int r = 0;
1708 int count = 3;
1709 bytes[0] = UNW_X3;
1711 if (rtype == spill_sprel_p)
1712 r = 1;
1713 else if (rtype != spill_psprel_p)
1714 as_bad ("Invalid record type for format X3");
1715 bytes[1] = ((r << 7) | (qp & 0x3f));
1716 bytes[2] = format_ab_reg (ab, reg);
1717 count += output_leb128 (bytes + 3, t, 0);
1718 count += output_leb128 (bytes + count, w1, 0);
1719 (*f) (count, bytes, NULL);
1722 static void
1723 output_X4_format (f, qp, ab, reg, x, y, treg, t)
1724 vbyte_func f;
1725 int qp;
1726 int ab, reg;
1727 int x, y, treg;
1728 unsigned long t;
1730 char bytes[20];
1731 int count = 4;
1732 bytes[0] = UNW_X4;
1733 bytes[1] = (qp & 0x3f);
1734 bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg));
1735 bytes[3] = (((y & 1) << 7) | (treg & 0x7f));
1736 count += output_leb128 (bytes + 4, t, 0);
1737 (*f) (count, bytes, NULL);
1740 /* This function allocates a record list structure, and initializes fields. */
1742 static unw_rec_list *
1743 alloc_record (unw_record_type t)
1745 unw_rec_list *ptr;
1746 ptr = xmalloc (sizeof (*ptr));
1747 ptr->next = NULL;
1748 ptr->slot_number = SLOT_NUM_NOT_SET;
1749 ptr->r.type = t;
1750 ptr->next_slot_number = 0;
1751 ptr->next_slot_frag = 0;
1752 return ptr;
1755 /* Dummy unwind record used for calculating the length of the last prologue or
1756 body region. */
1758 static unw_rec_list *
1759 output_endp ()
1761 unw_rec_list *ptr = alloc_record (endp);
1762 return ptr;
1765 static unw_rec_list *
1766 output_prologue ()
1768 unw_rec_list *ptr = alloc_record (prologue);
1769 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1770 return ptr;
1773 static unw_rec_list *
1774 output_prologue_gr (saved_mask, reg)
1775 unsigned int saved_mask;
1776 unsigned int reg;
1778 unw_rec_list *ptr = alloc_record (prologue_gr);
1779 memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask));
1780 ptr->r.record.r.grmask = saved_mask;
1781 ptr->r.record.r.grsave = reg;
1782 return ptr;
1785 static unw_rec_list *
1786 output_body ()
1788 unw_rec_list *ptr = alloc_record (body);
1789 return ptr;
1792 static unw_rec_list *
1793 output_mem_stack_f (size)
1794 unsigned int size;
1796 unw_rec_list *ptr = alloc_record (mem_stack_f);
1797 ptr->r.record.p.size = size;
1798 return ptr;
1801 static unw_rec_list *
1802 output_mem_stack_v ()
1804 unw_rec_list *ptr = alloc_record (mem_stack_v);
1805 return ptr;
1808 static unw_rec_list *
1809 output_psp_gr (gr)
1810 unsigned int gr;
1812 unw_rec_list *ptr = alloc_record (psp_gr);
1813 ptr->r.record.p.gr = gr;
1814 return ptr;
1817 static unw_rec_list *
1818 output_psp_sprel (offset)
1819 unsigned int offset;
1821 unw_rec_list *ptr = alloc_record (psp_sprel);
1822 ptr->r.record.p.spoff = offset / 4;
1823 return ptr;
1826 static unw_rec_list *
1827 output_rp_when ()
1829 unw_rec_list *ptr = alloc_record (rp_when);
1830 return ptr;
1833 static unw_rec_list *
1834 output_rp_gr (gr)
1835 unsigned int gr;
1837 unw_rec_list *ptr = alloc_record (rp_gr);
1838 ptr->r.record.p.gr = gr;
1839 return ptr;
1842 static unw_rec_list *
1843 output_rp_br (br)
1844 unsigned int br;
1846 unw_rec_list *ptr = alloc_record (rp_br);
1847 ptr->r.record.p.br = br;
1848 return ptr;
1851 static unw_rec_list *
1852 output_rp_psprel (offset)
1853 unsigned int offset;
1855 unw_rec_list *ptr = alloc_record (rp_psprel);
1856 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1857 return ptr;
1860 static unw_rec_list *
1861 output_rp_sprel (offset)
1862 unsigned int offset;
1864 unw_rec_list *ptr = alloc_record (rp_sprel);
1865 ptr->r.record.p.spoff = offset / 4;
1866 return ptr;
1869 static unw_rec_list *
1870 output_pfs_when ()
1872 unw_rec_list *ptr = alloc_record (pfs_when);
1873 return ptr;
1876 static unw_rec_list *
1877 output_pfs_gr (gr)
1878 unsigned int gr;
1880 unw_rec_list *ptr = alloc_record (pfs_gr);
1881 ptr->r.record.p.gr = gr;
1882 return ptr;
1885 static unw_rec_list *
1886 output_pfs_psprel (offset)
1887 unsigned int offset;
1889 unw_rec_list *ptr = alloc_record (pfs_psprel);
1890 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1891 return ptr;
1894 static unw_rec_list *
1895 output_pfs_sprel (offset)
1896 unsigned int offset;
1898 unw_rec_list *ptr = alloc_record (pfs_sprel);
1899 ptr->r.record.p.spoff = offset / 4;
1900 return ptr;
1903 static unw_rec_list *
1904 output_preds_when ()
1906 unw_rec_list *ptr = alloc_record (preds_when);
1907 return ptr;
1910 static unw_rec_list *
1911 output_preds_gr (gr)
1912 unsigned int gr;
1914 unw_rec_list *ptr = alloc_record (preds_gr);
1915 ptr->r.record.p.gr = gr;
1916 return ptr;
1919 static unw_rec_list *
1920 output_preds_psprel (offset)
1921 unsigned int offset;
1923 unw_rec_list *ptr = alloc_record (preds_psprel);
1924 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
1925 return ptr;
1928 static unw_rec_list *
1929 output_preds_sprel (offset)
1930 unsigned int offset;
1932 unw_rec_list *ptr = alloc_record (preds_sprel);
1933 ptr->r.record.p.spoff = offset / 4;
1934 return ptr;
1937 static unw_rec_list *
1938 output_fr_mem (mask)
1939 unsigned int mask;
1941 unw_rec_list *ptr = alloc_record (fr_mem);
1942 ptr->r.record.p.rmask = mask;
1943 return ptr;
1946 static unw_rec_list *
1947 output_frgr_mem (gr_mask, fr_mask)
1948 unsigned int gr_mask;
1949 unsigned int fr_mask;
1951 unw_rec_list *ptr = alloc_record (frgr_mem);
1952 ptr->r.record.p.grmask = gr_mask;
1953 ptr->r.record.p.frmask = fr_mask;
1954 return ptr;
1957 static unw_rec_list *
1958 output_gr_gr (mask, reg)
1959 unsigned int mask;
1960 unsigned int reg;
1962 unw_rec_list *ptr = alloc_record (gr_gr);
1963 ptr->r.record.p.grmask = mask;
1964 ptr->r.record.p.gr = reg;
1965 return ptr;
1968 static unw_rec_list *
1969 output_gr_mem (mask)
1970 unsigned int mask;
1972 unw_rec_list *ptr = alloc_record (gr_mem);
1973 ptr->r.record.p.rmask = mask;
1974 return ptr;
1977 static unw_rec_list *
1978 output_br_mem (unsigned int mask)
1980 unw_rec_list *ptr = alloc_record (br_mem);
1981 ptr->r.record.p.brmask = mask;
1982 return ptr;
1985 static unw_rec_list *
1986 output_br_gr (save_mask, reg)
1987 unsigned int save_mask;
1988 unsigned int reg;
1990 unw_rec_list *ptr = alloc_record (br_gr);
1991 ptr->r.record.p.brmask = save_mask;
1992 ptr->r.record.p.gr = reg;
1993 return ptr;
1996 static unw_rec_list *
1997 output_spill_base (offset)
1998 unsigned int offset;
2000 unw_rec_list *ptr = alloc_record (spill_base);
2001 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2002 return ptr;
2005 static unw_rec_list *
2006 output_unat_when ()
2008 unw_rec_list *ptr = alloc_record (unat_when);
2009 return ptr;
2012 static unw_rec_list *
2013 output_unat_gr (gr)
2014 unsigned int gr;
2016 unw_rec_list *ptr = alloc_record (unat_gr);
2017 ptr->r.record.p.gr = gr;
2018 return ptr;
2021 static unw_rec_list *
2022 output_unat_psprel (offset)
2023 unsigned int offset;
2025 unw_rec_list *ptr = alloc_record (unat_psprel);
2026 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2027 return ptr;
2030 static unw_rec_list *
2031 output_unat_sprel (offset)
2032 unsigned int offset;
2034 unw_rec_list *ptr = alloc_record (unat_sprel);
2035 ptr->r.record.p.spoff = offset / 4;
2036 return ptr;
2039 static unw_rec_list *
2040 output_lc_when ()
2042 unw_rec_list *ptr = alloc_record (lc_when);
2043 return ptr;
2046 static unw_rec_list *
2047 output_lc_gr (gr)
2048 unsigned int gr;
2050 unw_rec_list *ptr = alloc_record (lc_gr);
2051 ptr->r.record.p.gr = gr;
2052 return ptr;
2055 static unw_rec_list *
2056 output_lc_psprel (offset)
2057 unsigned int offset;
2059 unw_rec_list *ptr = alloc_record (lc_psprel);
2060 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2061 return ptr;
2064 static unw_rec_list *
2065 output_lc_sprel (offset)
2066 unsigned int offset;
2068 unw_rec_list *ptr = alloc_record (lc_sprel);
2069 ptr->r.record.p.spoff = offset / 4;
2070 return ptr;
2073 static unw_rec_list *
2074 output_fpsr_when ()
2076 unw_rec_list *ptr = alloc_record (fpsr_when);
2077 return ptr;
2080 static unw_rec_list *
2081 output_fpsr_gr (gr)
2082 unsigned int gr;
2084 unw_rec_list *ptr = alloc_record (fpsr_gr);
2085 ptr->r.record.p.gr = gr;
2086 return ptr;
2089 static unw_rec_list *
2090 output_fpsr_psprel (offset)
2091 unsigned int offset;
2093 unw_rec_list *ptr = alloc_record (fpsr_psprel);
2094 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2095 return ptr;
2098 static unw_rec_list *
2099 output_fpsr_sprel (offset)
2100 unsigned int offset;
2102 unw_rec_list *ptr = alloc_record (fpsr_sprel);
2103 ptr->r.record.p.spoff = offset / 4;
2104 return ptr;
2107 static unw_rec_list *
2108 output_priunat_when_gr ()
2110 unw_rec_list *ptr = alloc_record (priunat_when_gr);
2111 return ptr;
2114 static unw_rec_list *
2115 output_priunat_when_mem ()
2117 unw_rec_list *ptr = alloc_record (priunat_when_mem);
2118 return ptr;
2121 static unw_rec_list *
2122 output_priunat_gr (gr)
2123 unsigned int gr;
2125 unw_rec_list *ptr = alloc_record (priunat_gr);
2126 ptr->r.record.p.gr = gr;
2127 return ptr;
2130 static unw_rec_list *
2131 output_priunat_psprel (offset)
2132 unsigned int offset;
2134 unw_rec_list *ptr = alloc_record (priunat_psprel);
2135 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2136 return ptr;
2139 static unw_rec_list *
2140 output_priunat_sprel (offset)
2141 unsigned int offset;
2143 unw_rec_list *ptr = alloc_record (priunat_sprel);
2144 ptr->r.record.p.spoff = offset / 4;
2145 return ptr;
2148 static unw_rec_list *
2149 output_bsp_when ()
2151 unw_rec_list *ptr = alloc_record (bsp_when);
2152 return ptr;
2155 static unw_rec_list *
2156 output_bsp_gr (gr)
2157 unsigned int gr;
2159 unw_rec_list *ptr = alloc_record (bsp_gr);
2160 ptr->r.record.p.gr = gr;
2161 return ptr;
2164 static unw_rec_list *
2165 output_bsp_psprel (offset)
2166 unsigned int offset;
2168 unw_rec_list *ptr = alloc_record (bsp_psprel);
2169 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2170 return ptr;
2173 static unw_rec_list *
2174 output_bsp_sprel (offset)
2175 unsigned int offset;
2177 unw_rec_list *ptr = alloc_record (bsp_sprel);
2178 ptr->r.record.p.spoff = offset / 4;
2179 return ptr;
2182 static unw_rec_list *
2183 output_bspstore_when ()
2185 unw_rec_list *ptr = alloc_record (bspstore_when);
2186 return ptr;
2189 static unw_rec_list *
2190 output_bspstore_gr (gr)
2191 unsigned int gr;
2193 unw_rec_list *ptr = alloc_record (bspstore_gr);
2194 ptr->r.record.p.gr = gr;
2195 return ptr;
2198 static unw_rec_list *
2199 output_bspstore_psprel (offset)
2200 unsigned int offset;
2202 unw_rec_list *ptr = alloc_record (bspstore_psprel);
2203 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2204 return ptr;
2207 static unw_rec_list *
2208 output_bspstore_sprel (offset)
2209 unsigned int offset;
2211 unw_rec_list *ptr = alloc_record (bspstore_sprel);
2212 ptr->r.record.p.spoff = offset / 4;
2213 return ptr;
2216 static unw_rec_list *
2217 output_rnat_when ()
2219 unw_rec_list *ptr = alloc_record (rnat_when);
2220 return ptr;
2223 static unw_rec_list *
2224 output_rnat_gr (gr)
2225 unsigned int gr;
2227 unw_rec_list *ptr = alloc_record (rnat_gr);
2228 ptr->r.record.p.gr = gr;
2229 return ptr;
2232 static unw_rec_list *
2233 output_rnat_psprel (offset)
2234 unsigned int offset;
2236 unw_rec_list *ptr = alloc_record (rnat_psprel);
2237 ptr->r.record.p.pspoff = ENCODED_PSP_OFFSET (offset);
2238 return ptr;
2241 static unw_rec_list *
2242 output_rnat_sprel (offset)
2243 unsigned int offset;
2245 unw_rec_list *ptr = alloc_record (rnat_sprel);
2246 ptr->r.record.p.spoff = offset / 4;
2247 return ptr;
2250 static unw_rec_list *
2251 output_unwabi (abi, context)
2252 unsigned long abi;
2253 unsigned long context;
2255 unw_rec_list *ptr = alloc_record (unwabi);
2256 ptr->r.record.p.abi = abi;
2257 ptr->r.record.p.context = context;
2258 return ptr;
2261 static unw_rec_list *
2262 output_epilogue (unsigned long ecount)
2264 unw_rec_list *ptr = alloc_record (epilogue);
2265 ptr->r.record.b.ecount = ecount;
2266 return ptr;
2269 static unw_rec_list *
2270 output_label_state (unsigned long label)
2272 unw_rec_list *ptr = alloc_record (label_state);
2273 ptr->r.record.b.label = label;
2274 return ptr;
2277 static unw_rec_list *
2278 output_copy_state (unsigned long label)
2280 unw_rec_list *ptr = alloc_record (copy_state);
2281 ptr->r.record.b.label = label;
2282 return ptr;
2285 static unw_rec_list *
2286 output_spill_psprel (ab, reg, offset)
2287 unsigned int ab;
2288 unsigned int reg;
2289 unsigned int offset;
2291 unw_rec_list *ptr = alloc_record (spill_psprel);
2292 ptr->r.record.x.ab = ab;
2293 ptr->r.record.x.reg = reg;
2294 ptr->r.record.x.pspoff = ENCODED_PSP_OFFSET (offset);
2295 return ptr;
2298 static unw_rec_list *
2299 output_spill_sprel (ab, reg, offset)
2300 unsigned int ab;
2301 unsigned int reg;
2302 unsigned int offset;
2304 unw_rec_list *ptr = alloc_record (spill_sprel);
2305 ptr->r.record.x.ab = ab;
2306 ptr->r.record.x.reg = reg;
2307 ptr->r.record.x.spoff = offset / 4;
2308 return ptr;
2311 static unw_rec_list *
2312 output_spill_psprel_p (ab, reg, offset, predicate)
2313 unsigned int ab;
2314 unsigned int reg;
2315 unsigned int offset;
2316 unsigned int predicate;
2318 unw_rec_list *ptr = alloc_record (spill_psprel_p);
2319 ptr->r.record.x.ab = ab;
2320 ptr->r.record.x.reg = reg;
2321 ptr->r.record.x.pspoff = ENCODED_PSP_OFFSET (offset);
2322 ptr->r.record.x.qp = predicate;
2323 return ptr;
2326 static unw_rec_list *
2327 output_spill_sprel_p (ab, reg, offset, predicate)
2328 unsigned int ab;
2329 unsigned int reg;
2330 unsigned int offset;
2331 unsigned int predicate;
2333 unw_rec_list *ptr = alloc_record (spill_sprel_p);
2334 ptr->r.record.x.ab = ab;
2335 ptr->r.record.x.reg = reg;
2336 ptr->r.record.x.spoff = offset / 4;
2337 ptr->r.record.x.qp = predicate;
2338 return ptr;
2341 static unw_rec_list *
2342 output_spill_reg (ab, reg, targ_reg, xy)
2343 unsigned int ab;
2344 unsigned int reg;
2345 unsigned int targ_reg;
2346 unsigned int xy;
2348 unw_rec_list *ptr = alloc_record (spill_reg);
2349 ptr->r.record.x.ab = ab;
2350 ptr->r.record.x.reg = reg;
2351 ptr->r.record.x.treg = targ_reg;
2352 ptr->r.record.x.xy = xy;
2353 return ptr;
2356 static unw_rec_list *
2357 output_spill_reg_p (ab, reg, targ_reg, xy, predicate)
2358 unsigned int ab;
2359 unsigned int reg;
2360 unsigned int targ_reg;
2361 unsigned int xy;
2362 unsigned int predicate;
2364 unw_rec_list *ptr = alloc_record (spill_reg_p);
2365 ptr->r.record.x.ab = ab;
2366 ptr->r.record.x.reg = reg;
2367 ptr->r.record.x.treg = targ_reg;
2368 ptr->r.record.x.xy = xy;
2369 ptr->r.record.x.qp = predicate;
2370 return ptr;
2373 /* Given a unw_rec_list process the correct format with the
2374 specified function. */
2376 static void
2377 process_one_record (ptr, f)
2378 unw_rec_list *ptr;
2379 vbyte_func f;
2381 unsigned long fr_mask, gr_mask;
2383 switch (ptr->r.type)
2385 /* This is a dummy record that takes up no space in the output. */
2386 case endp:
2387 break;
2389 case gr_mem:
2390 case fr_mem:
2391 case br_mem:
2392 case frgr_mem:
2393 /* These are taken care of by prologue/prologue_gr. */
2394 break;
2396 case prologue_gr:
2397 case prologue:
2398 if (ptr->r.type == prologue_gr)
2399 output_R2_format (f, ptr->r.record.r.grmask,
2400 ptr->r.record.r.grsave, ptr->r.record.r.rlen);
2401 else
2402 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2404 /* Output descriptor(s) for union of register spills (if any). */
2405 gr_mask = ptr->r.record.r.mask.gr_mem;
2406 fr_mask = ptr->r.record.r.mask.fr_mem;
2407 if (fr_mask)
2409 if ((fr_mask & ~0xfUL) == 0)
2410 output_P6_format (f, fr_mem, fr_mask);
2411 else
2413 output_P5_format (f, gr_mask, fr_mask);
2414 gr_mask = 0;
2417 if (gr_mask)
2418 output_P6_format (f, gr_mem, gr_mask);
2419 if (ptr->r.record.r.mask.br_mem)
2420 output_P1_format (f, ptr->r.record.r.mask.br_mem);
2422 /* output imask descriptor if necessary: */
2423 if (ptr->r.record.r.mask.i)
2424 output_P4_format (f, ptr->r.record.r.mask.i,
2425 ptr->r.record.r.imask_size);
2426 break;
2428 case body:
2429 output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen);
2430 break;
2431 case mem_stack_f:
2432 case mem_stack_v:
2433 output_P7_format (f, ptr->r.type, ptr->r.record.p.t,
2434 ptr->r.record.p.size);
2435 break;
2436 case psp_gr:
2437 case rp_gr:
2438 case pfs_gr:
2439 case preds_gr:
2440 case unat_gr:
2441 case lc_gr:
2442 case fpsr_gr:
2443 case priunat_gr:
2444 case bsp_gr:
2445 case bspstore_gr:
2446 case rnat_gr:
2447 output_P3_format (f, ptr->r.type, ptr->r.record.p.gr);
2448 break;
2449 case rp_br:
2450 output_P3_format (f, rp_br, ptr->r.record.p.br);
2451 break;
2452 case psp_sprel:
2453 output_P7_format (f, psp_sprel, ptr->r.record.p.spoff, 0);
2454 break;
2455 case rp_when:
2456 case pfs_when:
2457 case preds_when:
2458 case unat_when:
2459 case lc_when:
2460 case fpsr_when:
2461 output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0);
2462 break;
2463 case rp_psprel:
2464 case pfs_psprel:
2465 case preds_psprel:
2466 case unat_psprel:
2467 case lc_psprel:
2468 case fpsr_psprel:
2469 case spill_base:
2470 output_P7_format (f, ptr->r.type, ptr->r.record.p.pspoff, 0);
2471 break;
2472 case rp_sprel:
2473 case pfs_sprel:
2474 case preds_sprel:
2475 case unat_sprel:
2476 case lc_sprel:
2477 case fpsr_sprel:
2478 case priunat_sprel:
2479 case bsp_sprel:
2480 case bspstore_sprel:
2481 case rnat_sprel:
2482 output_P8_format (f, ptr->r.type, ptr->r.record.p.spoff);
2483 break;
2484 case gr_gr:
2485 output_P9_format (f, ptr->r.record.p.grmask, ptr->r.record.p.gr);
2486 break;
2487 case br_gr:
2488 output_P2_format (f, ptr->r.record.p.brmask, ptr->r.record.p.gr);
2489 break;
2490 case spill_mask:
2491 as_bad ("spill_mask record unimplemented.");
2492 break;
2493 case priunat_when_gr:
2494 case priunat_when_mem:
2495 case bsp_when:
2496 case bspstore_when:
2497 case rnat_when:
2498 output_P8_format (f, ptr->r.type, ptr->r.record.p.t);
2499 break;
2500 case priunat_psprel:
2501 case bsp_psprel:
2502 case bspstore_psprel:
2503 case rnat_psprel:
2504 output_P8_format (f, ptr->r.type, ptr->r.record.p.pspoff);
2505 break;
2506 case unwabi:
2507 output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context);
2508 break;
2509 case epilogue:
2510 output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t);
2511 break;
2512 case label_state:
2513 case copy_state:
2514 output_B4_format (f, ptr->r.type, ptr->r.record.b.label);
2515 break;
2516 case spill_psprel:
2517 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2518 ptr->r.record.x.reg, ptr->r.record.x.t,
2519 ptr->r.record.x.pspoff);
2520 break;
2521 case spill_sprel:
2522 output_X1_format (f, ptr->r.type, ptr->r.record.x.ab,
2523 ptr->r.record.x.reg, ptr->r.record.x.t,
2524 ptr->r.record.x.spoff);
2525 break;
2526 case spill_reg:
2527 output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg,
2528 ptr->r.record.x.xy >> 1, ptr->r.record.x.xy,
2529 ptr->r.record.x.treg, ptr->r.record.x.t);
2530 break;
2531 case spill_psprel_p:
2532 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2533 ptr->r.record.x.ab, ptr->r.record.x.reg,
2534 ptr->r.record.x.t, ptr->r.record.x.pspoff);
2535 break;
2536 case spill_sprel_p:
2537 output_X3_format (f, ptr->r.type, ptr->r.record.x.qp,
2538 ptr->r.record.x.ab, ptr->r.record.x.reg,
2539 ptr->r.record.x.t, ptr->r.record.x.spoff);
2540 break;
2541 case spill_reg_p:
2542 output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab,
2543 ptr->r.record.x.reg, ptr->r.record.x.xy >> 1,
2544 ptr->r.record.x.xy, ptr->r.record.x.treg,
2545 ptr->r.record.x.t);
2546 break;
2547 default:
2548 as_bad ("record_type_not_valid");
2549 break;
2553 /* Given a unw_rec_list list, process all the records with
2554 the specified function. */
2555 static void
2556 process_unw_records (list, f)
2557 unw_rec_list *list;
2558 vbyte_func f;
2560 unw_rec_list *ptr;
2561 for (ptr = list; ptr; ptr = ptr->next)
2562 process_one_record (ptr, f);
2565 /* Determine the size of a record list in bytes. */
2566 static int
2567 calc_record_size (list)
2568 unw_rec_list *list;
2570 vbyte_count = 0;
2571 process_unw_records (list, count_output);
2572 return vbyte_count;
2575 /* Update IMASK bitmask to reflect the fact that one or more registers
2576 of type TYPE are saved starting at instruction with index T. If N
2577 bits are set in REGMASK, it is assumed that instructions T through
2578 T+N-1 save these registers.
2580 TYPE values:
2581 0: no save
2582 1: instruction saves next fp reg
2583 2: instruction saves next general reg
2584 3: instruction saves next branch reg */
2585 static void
2586 set_imask (region, regmask, t, type)
2587 unw_rec_list *region;
2588 unsigned long regmask;
2589 unsigned long t;
2590 unsigned int type;
2592 unsigned char *imask;
2593 unsigned long imask_size;
2594 unsigned int i;
2595 int pos;
2597 imask = region->r.record.r.mask.i;
2598 imask_size = region->r.record.r.imask_size;
2599 if (!imask)
2601 imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1;
2602 imask = xmalloc (imask_size);
2603 memset (imask, 0, imask_size);
2605 region->r.record.r.imask_size = imask_size;
2606 region->r.record.r.mask.i = imask;
2609 i = (t / 4) + 1;
2610 pos = 2 * (3 - t % 4);
2611 while (regmask)
2613 if (i >= imask_size)
2615 as_bad ("Ignoring attempt to spill beyond end of region");
2616 return;
2619 imask[i] |= (type & 0x3) << pos;
2621 regmask &= (regmask - 1);
2622 pos -= 2;
2623 if (pos < 0)
2625 pos = 0;
2626 ++i;
2631 /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR.
2632 SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag
2633 containing FIRST_ADDR. If BEFORE_RELAX, then we use worst-case estimates
2634 for frag sizes. */
2636 unsigned long
2637 slot_index (slot_addr, slot_frag, first_addr, first_frag, before_relax)
2638 unsigned long slot_addr;
2639 fragS *slot_frag;
2640 unsigned long first_addr;
2641 fragS *first_frag;
2642 int before_relax;
2644 unsigned long index = 0;
2646 /* First time we are called, the initial address and frag are invalid. */
2647 if (first_addr == 0)
2648 return 0;
2650 /* If the two addresses are in different frags, then we need to add in
2651 the remaining size of this frag, and then the entire size of intermediate
2652 frags. */
2653 while (slot_frag != first_frag)
2655 unsigned long start_addr = (unsigned long) &first_frag->fr_literal;
2657 if (! before_relax)
2659 /* We can get the final addresses only during and after
2660 relaxation. */
2661 if (first_frag->fr_next && first_frag->fr_next->fr_address)
2662 index += 3 * ((first_frag->fr_next->fr_address
2663 - first_frag->fr_address
2664 - first_frag->fr_fix) >> 4);
2666 else
2667 /* We don't know what the final addresses will be. We try our
2668 best to estimate. */
2669 switch (first_frag->fr_type)
2671 default:
2672 break;
2674 case rs_space:
2675 as_fatal ("only constant space allocation is supported");
2676 break;
2678 case rs_align:
2679 case rs_align_code:
2680 case rs_align_test:
2681 /* Take alignment into account. Assume the worst case
2682 before relaxation. */
2683 index += 3 * ((1 << first_frag->fr_offset) >> 4);
2684 break;
2686 case rs_org:
2687 if (first_frag->fr_symbol)
2689 as_fatal ("only constant offsets are supported");
2690 break;
2692 case rs_fill:
2693 index += 3 * (first_frag->fr_offset >> 4);
2694 break;
2697 /* Add in the full size of the frag converted to instruction slots. */
2698 index += 3 * (first_frag->fr_fix >> 4);
2699 /* Subtract away the initial part before first_addr. */
2700 index -= (3 * ((first_addr >> 4) - (start_addr >> 4))
2701 + ((first_addr & 0x3) - (start_addr & 0x3)));
2703 /* Move to the beginning of the next frag. */
2704 first_frag = first_frag->fr_next;
2705 first_addr = (unsigned long) &first_frag->fr_literal;
2708 /* Add in the used part of the last frag. */
2709 index += (3 * ((slot_addr >> 4) - (first_addr >> 4))
2710 + ((slot_addr & 0x3) - (first_addr & 0x3)));
2711 return index;
2714 /* Optimize unwind record directives. */
2716 static unw_rec_list *
2717 optimize_unw_records (list)
2718 unw_rec_list *list;
2720 if (!list)
2721 return NULL;
2723 /* If the only unwind record is ".prologue" or ".prologue" followed
2724 by ".body", then we can optimize the unwind directives away. */
2725 if (list->r.type == prologue
2726 && (list->next->r.type == endp
2727 || (list->next->r.type == body && list->next->next->r.type == endp)))
2728 return NULL;
2730 return list;
2733 /* Given a complete record list, process any records which have
2734 unresolved fields, (ie length counts for a prologue). After
2735 this has been run, all necessary information should be available
2736 within each record to generate an image. */
2738 static void
2739 fixup_unw_records (list, before_relax)
2740 unw_rec_list *list;
2741 int before_relax;
2743 unw_rec_list *ptr, *region = 0;
2744 unsigned long first_addr = 0, rlen = 0, t;
2745 fragS *first_frag = 0;
2747 for (ptr = list; ptr; ptr = ptr->next)
2749 if (ptr->slot_number == SLOT_NUM_NOT_SET)
2750 as_bad (" Insn slot not set in unwind record.");
2751 t = slot_index (ptr->slot_number, ptr->slot_frag,
2752 first_addr, first_frag, before_relax);
2753 switch (ptr->r.type)
2755 case prologue:
2756 case prologue_gr:
2757 case body:
2759 unw_rec_list *last;
2760 int size;
2761 unsigned long last_addr = 0;
2762 fragS *last_frag = NULL;
2764 first_addr = ptr->slot_number;
2765 first_frag = ptr->slot_frag;
2766 /* Find either the next body/prologue start, or the end of
2767 the function, and determine the size of the region. */
2768 for (last = ptr->next; last != NULL; last = last->next)
2769 if (last->r.type == prologue || last->r.type == prologue_gr
2770 || last->r.type == body || last->r.type == endp)
2772 last_addr = last->slot_number;
2773 last_frag = last->slot_frag;
2774 break;
2776 size = slot_index (last_addr, last_frag, first_addr, first_frag,
2777 before_relax);
2778 rlen = ptr->r.record.r.rlen = size;
2779 if (ptr->r.type == body)
2780 /* End of region. */
2781 region = 0;
2782 else
2783 region = ptr;
2784 break;
2786 case epilogue:
2787 if (t < rlen)
2788 ptr->r.record.b.t = rlen - 1 - t;
2789 else
2790 /* This happens when a memory-stack-less procedure uses a
2791 ".restore sp" directive at the end of a region to pop
2792 the frame state. */
2793 ptr->r.record.b.t = 0;
2794 break;
2796 case mem_stack_f:
2797 case mem_stack_v:
2798 case rp_when:
2799 case pfs_when:
2800 case preds_when:
2801 case unat_when:
2802 case lc_when:
2803 case fpsr_when:
2804 case priunat_when_gr:
2805 case priunat_when_mem:
2806 case bsp_when:
2807 case bspstore_when:
2808 case rnat_when:
2809 ptr->r.record.p.t = t;
2810 break;
2812 case spill_reg:
2813 case spill_sprel:
2814 case spill_psprel:
2815 case spill_reg_p:
2816 case spill_sprel_p:
2817 case spill_psprel_p:
2818 ptr->r.record.x.t = t;
2819 break;
2821 case frgr_mem:
2822 if (!region)
2824 as_bad ("frgr_mem record before region record!");
2825 return;
2827 region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask;
2828 region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask;
2829 set_imask (region, ptr->r.record.p.frmask, t, 1);
2830 set_imask (region, ptr->r.record.p.grmask, t, 2);
2831 break;
2832 case fr_mem:
2833 if (!region)
2835 as_bad ("fr_mem record before region record!");
2836 return;
2838 region->r.record.r.mask.fr_mem |= ptr->r.record.p.rmask;
2839 set_imask (region, ptr->r.record.p.rmask, t, 1);
2840 break;
2841 case gr_mem:
2842 if (!region)
2844 as_bad ("gr_mem record before region record!");
2845 return;
2847 region->r.record.r.mask.gr_mem |= ptr->r.record.p.rmask;
2848 set_imask (region, ptr->r.record.p.rmask, t, 2);
2849 break;
2850 case br_mem:
2851 if (!region)
2853 as_bad ("br_mem record before region record!");
2854 return;
2856 region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask;
2857 set_imask (region, ptr->r.record.p.brmask, t, 3);
2858 break;
2860 case gr_gr:
2861 if (!region)
2863 as_bad ("gr_gr record before region record!");
2864 return;
2866 set_imask (region, ptr->r.record.p.grmask, t, 2);
2867 break;
2868 case br_gr:
2869 if (!region)
2871 as_bad ("br_gr record before region record!");
2872 return;
2874 set_imask (region, ptr->r.record.p.brmask, t, 3);
2875 break;
2877 default:
2878 break;
2883 /* Estimate the size of a frag before relaxing. We only have one type of frag
2884 to handle here, which is the unwind info frag. */
2887 ia64_estimate_size_before_relax (fragS *frag,
2888 asection *segtype ATTRIBUTE_UNUSED)
2890 unw_rec_list *list;
2891 int len, size, pad;
2893 /* ??? This code is identical to the first part of ia64_convert_frag. */
2894 list = (unw_rec_list *) frag->fr_opcode;
2895 fixup_unw_records (list, 0);
2897 len = calc_record_size (list);
2898 /* pad to pointer-size boundary. */
2899 pad = len % md.pointer_size;
2900 if (pad != 0)
2901 len += md.pointer_size - pad;
2902 /* Add 8 for the header. */
2903 size = len + 8;
2904 /* Add a pointer for the personality offset. */
2905 if (frag->fr_offset)
2906 size += md.pointer_size;
2908 /* fr_var carries the max_chars that we created the fragment with.
2909 We must, of course, have allocated enough memory earlier. */
2910 assert (frag->fr_var >= size);
2912 return frag->fr_fix + size;
2915 /* This function converts a rs_machine_dependent variant frag into a
2916 normal fill frag with the unwind image from the the record list. */
2917 void
2918 ia64_convert_frag (fragS *frag)
2920 unw_rec_list *list;
2921 int len, size, pad;
2922 valueT flag_value;
2924 /* ??? This code is identical to ia64_estimate_size_before_relax. */
2925 list = (unw_rec_list *) frag->fr_opcode;
2926 fixup_unw_records (list, 0);
2928 len = calc_record_size (list);
2929 /* pad to pointer-size boundary. */
2930 pad = len % md.pointer_size;
2931 if (pad != 0)
2932 len += md.pointer_size - pad;
2933 /* Add 8 for the header. */
2934 size = len + 8;
2935 /* Add a pointer for the personality offset. */
2936 if (frag->fr_offset)
2937 size += md.pointer_size;
2939 /* fr_var carries the max_chars that we created the fragment with.
2940 We must, of course, have allocated enough memory earlier. */
2941 assert (frag->fr_var >= size);
2943 /* Initialize the header area. fr_offset is initialized with
2944 unwind.personality_routine. */
2945 if (frag->fr_offset)
2947 if (md.flags & EF_IA_64_ABI64)
2948 flag_value = (bfd_vma) 3 << 32;
2949 else
2950 /* 32-bit unwind info block. */
2951 flag_value = (bfd_vma) 0x1003 << 32;
2953 else
2954 flag_value = 0;
2956 md_number_to_chars (frag->fr_literal,
2957 (((bfd_vma) 1 << 48) /* Version. */
2958 | flag_value /* U & E handler flags. */
2959 | (len / md.pointer_size)), /* Length. */
2962 /* Skip the header. */
2963 vbyte_mem_ptr = frag->fr_literal + 8;
2964 process_unw_records (list, output_vbyte_mem);
2966 /* Fill the padding bytes with zeros. */
2967 if (pad != 0)
2968 md_number_to_chars (frag->fr_literal + len + 8 - md.pointer_size + pad, 0,
2969 md.pointer_size - pad);
2971 frag->fr_fix += size;
2972 frag->fr_type = rs_fill;
2973 frag->fr_var = 0;
2974 frag->fr_offset = 0;
2977 static int
2978 convert_expr_to_ab_reg (e, ab, regp)
2979 expressionS *e;
2980 unsigned int *ab;
2981 unsigned int *regp;
2983 unsigned int reg;
2985 if (e->X_op != O_register)
2986 return 0;
2988 reg = e->X_add_number;
2989 if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7))
2991 *ab = 0;
2992 *regp = reg - REG_GR;
2994 else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5))
2995 || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31)))
2997 *ab = 1;
2998 *regp = reg - REG_FR;
3000 else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5))
3002 *ab = 2;
3003 *regp = reg - REG_BR;
3005 else
3007 *ab = 3;
3008 switch (reg)
3010 case REG_PR: *regp = 0; break;
3011 case REG_PSP: *regp = 1; break;
3012 case REG_PRIUNAT: *regp = 2; break;
3013 case REG_BR + 0: *regp = 3; break;
3014 case REG_AR + AR_BSP: *regp = 4; break;
3015 case REG_AR + AR_BSPSTORE: *regp = 5; break;
3016 case REG_AR + AR_RNAT: *regp = 6; break;
3017 case REG_AR + AR_UNAT: *regp = 7; break;
3018 case REG_AR + AR_FPSR: *regp = 8; break;
3019 case REG_AR + AR_PFS: *regp = 9; break;
3020 case REG_AR + AR_LC: *regp = 10; break;
3022 default:
3023 return 0;
3026 return 1;
3029 static int
3030 convert_expr_to_xy_reg (e, xy, regp)
3031 expressionS *e;
3032 unsigned int *xy;
3033 unsigned int *regp;
3035 unsigned int reg;
3037 if (e->X_op != O_register)
3038 return 0;
3040 reg = e->X_add_number;
3042 if (/* reg >= REG_GR && */ reg <= (REG_GR + 127))
3044 *xy = 0;
3045 *regp = reg - REG_GR;
3047 else if (reg >= REG_FR && reg <= (REG_FR + 127))
3049 *xy = 1;
3050 *regp = reg - REG_FR;
3052 else if (reg >= REG_BR && reg <= (REG_BR + 7))
3054 *xy = 2;
3055 *regp = reg - REG_BR;
3057 else
3058 return -1;
3059 return 1;
3062 static void
3063 dot_align (int arg)
3065 /* The current frag is an alignment frag. */
3066 align_frag = frag_now;
3067 s_align_bytes (arg);
3070 static void
3071 dot_radix (dummy)
3072 int dummy ATTRIBUTE_UNUSED;
3074 int radix;
3076 SKIP_WHITESPACE ();
3077 radix = *input_line_pointer++;
3079 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
3081 as_bad ("Radix `%c' unsupported", *input_line_pointer);
3082 ignore_rest_of_line ();
3083 return;
3087 /* Helper function for .loc directives. If the assembler is not generating
3088 line number info, then we need to remember which instructions have a .loc
3089 directive, and only call dwarf2_gen_line_info for those instructions. */
3091 static void
3092 dot_loc (int x)
3094 CURR_SLOT.loc_directive_seen = 1;
3095 dwarf2_directive_loc (x);
3098 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
3099 static void
3100 dot_special_section (which)
3101 int which;
3103 set_section ((char *) special_section_name[which]);
3106 /* Return -1 for warning and 0 for error. */
3108 static int
3109 unwind_diagnostic (const char * region, const char *directive)
3111 if (md.unwind_check == unwind_check_warning)
3113 as_warn (".%s outside of %s", directive, region);
3114 return -1;
3116 else
3118 as_bad (".%s outside of %s", directive, region);
3119 ignore_rest_of_line ();
3120 return 0;
3124 /* Return 1 if a directive is in a procedure, -1 if a directive isn't in
3125 a procedure but the unwind directive check is set to warning, 0 if
3126 a directive isn't in a procedure and the unwind directive check is set
3127 to error. */
3129 static int
3130 in_procedure (const char *directive)
3132 if (unwind.proc_start
3133 && (!unwind.saved_text_seg || strcmp (directive, "endp") == 0))
3134 return 1;
3135 return unwind_diagnostic ("procedure", directive);
3138 /* Return 1 if a directive is in a prologue, -1 if a directive isn't in
3139 a prologue but the unwind directive check is set to warning, 0 if
3140 a directive isn't in a prologue and the unwind directive check is set
3141 to error. */
3143 static int
3144 in_prologue (const char *directive)
3146 int in = in_procedure (directive);
3147 if (in)
3149 /* We are in a procedure. Check if we are in a prologue. */
3150 if (unwind.prologue)
3151 return 1;
3152 /* We only want to issue one message. */
3153 if (in == 1)
3154 return unwind_diagnostic ("prologue", directive);
3155 else
3156 return -1;
3158 return 0;
3161 /* Return 1 if a directive is in a body, -1 if a directive isn't in
3162 a body but the unwind directive check is set to warning, 0 if
3163 a directive isn't in a body and the unwind directive check is set
3164 to error. */
3166 static int
3167 in_body (const char *directive)
3169 int in = in_procedure (directive);
3170 if (in)
3172 /* We are in a procedure. Check if we are in a body. */
3173 if (unwind.body)
3174 return 1;
3175 /* We only want to issue one message. */
3176 if (in == 1)
3177 return unwind_diagnostic ("body region", directive);
3178 else
3179 return -1;
3181 return 0;
3184 static void
3185 add_unwind_entry (ptr)
3186 unw_rec_list *ptr;
3188 if (unwind.tail)
3189 unwind.tail->next = ptr;
3190 else
3191 unwind.list = ptr;
3192 unwind.tail = ptr;
3194 /* The current entry can in fact be a chain of unwind entries. */
3195 if (unwind.current_entry == NULL)
3196 unwind.current_entry = ptr;
3199 static void
3200 dot_fframe (dummy)
3201 int dummy ATTRIBUTE_UNUSED;
3203 expressionS e;
3205 if (!in_prologue ("fframe"))
3206 return;
3208 parse_operand (&e);
3210 if (e.X_op != O_constant)
3211 as_bad ("Operand to .fframe must be a constant");
3212 else
3213 add_unwind_entry (output_mem_stack_f (e.X_add_number));
3216 static void
3217 dot_vframe (dummy)
3218 int dummy ATTRIBUTE_UNUSED;
3220 expressionS e;
3221 unsigned reg;
3223 if (!in_prologue ("vframe"))
3224 return;
3226 parse_operand (&e);
3227 reg = e.X_add_number - REG_GR;
3228 if (e.X_op == O_register && reg < 128)
3230 add_unwind_entry (output_mem_stack_v ());
3231 if (! (unwind.prologue_mask & 2))
3232 add_unwind_entry (output_psp_gr (reg));
3234 else
3235 as_bad ("First operand to .vframe must be a general register");
3238 static void
3239 dot_vframesp (dummy)
3240 int dummy ATTRIBUTE_UNUSED;
3242 expressionS e;
3244 if (!in_prologue ("vframesp"))
3245 return;
3247 parse_operand (&e);
3248 if (e.X_op == O_constant)
3250 add_unwind_entry (output_mem_stack_v ());
3251 add_unwind_entry (output_psp_sprel (e.X_add_number));
3253 else
3254 as_bad ("Operand to .vframesp must be a constant (sp-relative offset)");
3257 static void
3258 dot_vframepsp (dummy)
3259 int dummy ATTRIBUTE_UNUSED;
3261 expressionS e;
3263 if (!in_prologue ("vframepsp"))
3264 return;
3266 parse_operand (&e);
3267 if (e.X_op == O_constant)
3269 add_unwind_entry (output_mem_stack_v ());
3270 add_unwind_entry (output_psp_sprel (e.X_add_number));
3272 else
3273 as_bad ("Operand to .vframepsp must be a constant (psp-relative offset)");
3276 static void
3277 dot_save (dummy)
3278 int dummy ATTRIBUTE_UNUSED;
3280 expressionS e1, e2;
3281 int sep;
3282 int reg1, reg2;
3284 if (!in_prologue ("save"))
3285 return;
3287 sep = parse_operand (&e1);
3288 if (sep != ',')
3289 as_bad ("No second operand to .save");
3290 sep = parse_operand (&e2);
3292 reg1 = e1.X_add_number;
3293 reg2 = e2.X_add_number - REG_GR;
3295 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3296 if (e1.X_op == O_register)
3298 if (e2.X_op == O_register && reg2 >= 0 && reg2 < 128)
3300 switch (reg1)
3302 case REG_AR + AR_BSP:
3303 add_unwind_entry (output_bsp_when ());
3304 add_unwind_entry (output_bsp_gr (reg2));
3305 break;
3306 case REG_AR + AR_BSPSTORE:
3307 add_unwind_entry (output_bspstore_when ());
3308 add_unwind_entry (output_bspstore_gr (reg2));
3309 break;
3310 case REG_AR + AR_RNAT:
3311 add_unwind_entry (output_rnat_when ());
3312 add_unwind_entry (output_rnat_gr (reg2));
3313 break;
3314 case REG_AR + AR_UNAT:
3315 add_unwind_entry (output_unat_when ());
3316 add_unwind_entry (output_unat_gr (reg2));
3317 break;
3318 case REG_AR + AR_FPSR:
3319 add_unwind_entry (output_fpsr_when ());
3320 add_unwind_entry (output_fpsr_gr (reg2));
3321 break;
3322 case REG_AR + AR_PFS:
3323 add_unwind_entry (output_pfs_when ());
3324 if (! (unwind.prologue_mask & 4))
3325 add_unwind_entry (output_pfs_gr (reg2));
3326 break;
3327 case REG_AR + AR_LC:
3328 add_unwind_entry (output_lc_when ());
3329 add_unwind_entry (output_lc_gr (reg2));
3330 break;
3331 case REG_BR:
3332 add_unwind_entry (output_rp_when ());
3333 if (! (unwind.prologue_mask & 8))
3334 add_unwind_entry (output_rp_gr (reg2));
3335 break;
3336 case REG_PR:
3337 add_unwind_entry (output_preds_when ());
3338 if (! (unwind.prologue_mask & 1))
3339 add_unwind_entry (output_preds_gr (reg2));
3340 break;
3341 case REG_PRIUNAT:
3342 add_unwind_entry (output_priunat_when_gr ());
3343 add_unwind_entry (output_priunat_gr (reg2));
3344 break;
3345 default:
3346 as_bad ("First operand not a valid register");
3349 else
3350 as_bad (" Second operand not a valid register");
3352 else
3353 as_bad ("First operand not a register");
3356 static void
3357 dot_restore (dummy)
3358 int dummy ATTRIBUTE_UNUSED;
3360 expressionS e1, e2;
3361 unsigned long ecount; /* # of _additional_ regions to pop */
3362 int sep;
3364 if (!in_body ("restore"))
3365 return;
3367 sep = parse_operand (&e1);
3368 if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12)
3370 as_bad ("First operand to .restore must be stack pointer (sp)");
3371 return;
3374 if (sep == ',')
3376 parse_operand (&e2);
3377 if (e2.X_op != O_constant || e2.X_add_number < 0)
3379 as_bad ("Second operand to .restore must be a constant >= 0");
3380 return;
3382 ecount = e2.X_add_number;
3384 else
3385 ecount = unwind.prologue_count - 1;
3387 if (ecount >= unwind.prologue_count)
3389 as_bad ("Epilogue count of %lu exceeds number of nested prologues (%u)",
3390 ecount + 1, unwind.prologue_count);
3391 return;
3394 add_unwind_entry (output_epilogue (ecount));
3396 if (ecount < unwind.prologue_count)
3397 unwind.prologue_count -= ecount + 1;
3398 else
3399 unwind.prologue_count = 0;
3402 static void
3403 dot_restorereg (dummy)
3404 int dummy ATTRIBUTE_UNUSED;
3406 unsigned int ab, reg;
3407 expressionS e;
3409 if (!in_procedure ("restorereg"))
3410 return;
3412 parse_operand (&e);
3414 if (!convert_expr_to_ab_reg (&e, &ab, &reg))
3416 as_bad ("First operand to .restorereg must be a preserved register");
3417 return;
3419 add_unwind_entry (output_spill_reg (ab, reg, 0, 0));
3422 static void
3423 dot_restorereg_p (dummy)
3424 int dummy ATTRIBUTE_UNUSED;
3426 unsigned int qp, ab, reg;
3427 expressionS e1, e2;
3428 int sep;
3430 if (!in_procedure ("restorereg.p"))
3431 return;
3433 sep = parse_operand (&e1);
3434 if (sep != ',')
3436 as_bad ("No second operand to .restorereg.p");
3437 return;
3440 parse_operand (&e2);
3442 qp = e1.X_add_number - REG_P;
3443 if (e1.X_op != O_register || qp > 63)
3445 as_bad ("First operand to .restorereg.p must be a predicate");
3446 return;
3449 if (!convert_expr_to_ab_reg (&e2, &ab, &reg))
3451 as_bad ("Second operand to .restorereg.p must be a preserved register");
3452 return;
3454 add_unwind_entry (output_spill_reg_p (ab, reg, 0, 0, qp));
3457 static char *special_linkonce_name[] =
3459 ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi."
3462 static void
3463 start_unwind_section (const segT text_seg, int sec_index)
3466 Use a slightly ugly scheme to derive the unwind section names from
3467 the text section name:
3469 text sect. unwind table sect.
3470 name: name: comments:
3471 ---------- ----------------- --------------------------------
3472 .text .IA_64.unwind
3473 .text.foo .IA_64.unwind.text.foo
3474 .foo .IA_64.unwind.foo
3475 .gnu.linkonce.t.foo
3476 .gnu.linkonce.ia64unw.foo
3477 _info .IA_64.unwind_info gas issues error message (ditto)
3478 _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto)
3480 This mapping is done so that:
3482 (a) An object file with unwind info only in .text will use
3483 unwind section names .IA_64.unwind and .IA_64.unwind_info.
3484 This follows the letter of the ABI and also ensures backwards
3485 compatibility with older toolchains.
3487 (b) An object file with unwind info in multiple text sections
3488 will use separate unwind sections for each text section.
3489 This allows us to properly set the "sh_info" and "sh_link"
3490 fields in SHT_IA_64_UNWIND as required by the ABI and also
3491 lets GNU ld support programs with multiple segments
3492 containing unwind info (as might be the case for certain
3493 embedded applications).
3495 (c) An error is issued if there would be a name clash.
3498 const char *text_name, *sec_text_name;
3499 char *sec_name;
3500 const char *prefix = special_section_name [sec_index];
3501 const char *suffix;
3502 size_t prefix_len, suffix_len, sec_name_len;
3504 sec_text_name = segment_name (text_seg);
3505 text_name = sec_text_name;
3506 if (strncmp (text_name, "_info", 5) == 0)
3508 as_bad ("Illegal section name `%s' (causes unwind section name clash)",
3509 text_name);
3510 ignore_rest_of_line ();
3511 return;
3513 if (strcmp (text_name, ".text") == 0)
3514 text_name = "";
3516 /* Build the unwind section name by appending the (possibly stripped)
3517 text section name to the unwind prefix. */
3518 suffix = text_name;
3519 if (strncmp (text_name, ".gnu.linkonce.t.",
3520 sizeof (".gnu.linkonce.t.") - 1) == 0)
3522 prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND];
3523 suffix += sizeof (".gnu.linkonce.t.") - 1;
3526 prefix_len = strlen (prefix);
3527 suffix_len = strlen (suffix);
3528 sec_name_len = prefix_len + suffix_len;
3529 sec_name = alloca (sec_name_len + 1);
3530 memcpy (sec_name, prefix, prefix_len);
3531 memcpy (sec_name + prefix_len, suffix, suffix_len);
3532 sec_name [sec_name_len] = '\0';
3534 /* Handle COMDAT group. */
3535 if (suffix == text_name && (text_seg->flags & SEC_LINK_ONCE) != 0)
3537 char *section;
3538 size_t len, group_name_len;
3539 const char *group_name = elf_group_name (text_seg);
3541 if (group_name == NULL)
3543 as_bad ("Group section `%s' has no group signature",
3544 sec_text_name);
3545 ignore_rest_of_line ();
3546 return;
3548 /* We have to construct a fake section directive. */
3549 group_name_len = strlen (group_name);
3550 len = (sec_name_len
3551 + 16 /* ,"aG",@progbits, */
3552 + group_name_len /* ,group_name */
3553 + 7); /* ,comdat */
3555 section = alloca (len + 1);
3556 memcpy (section, sec_name, sec_name_len);
3557 memcpy (section + sec_name_len, ",\"aG\",@progbits,", 16);
3558 memcpy (section + sec_name_len + 16, group_name, group_name_len);
3559 memcpy (section + len - 7, ",comdat", 7);
3560 section [len] = '\0';
3561 set_section (section);
3563 else
3565 set_section (sec_name);
3566 bfd_set_section_flags (stdoutput, now_seg,
3567 SEC_LOAD | SEC_ALLOC | SEC_READONLY);
3570 elf_linked_to_section (now_seg) = text_seg;
3573 static void
3574 generate_unwind_image (const segT text_seg)
3576 int size, pad;
3577 unw_rec_list *list;
3579 /* Mark the end of the unwind info, so that we can compute the size of the
3580 last unwind region. */
3581 add_unwind_entry (output_endp ());
3583 /* Force out pending instructions, to make sure all unwind records have
3584 a valid slot_number field. */
3585 ia64_flush_insns ();
3587 /* Generate the unwind record. */
3588 list = optimize_unw_records (unwind.list);
3589 fixup_unw_records (list, 1);
3590 size = calc_record_size (list);
3592 if (size > 0 || unwind.force_unwind_entry)
3594 unwind.force_unwind_entry = 0;
3595 /* pad to pointer-size boundary. */
3596 pad = size % md.pointer_size;
3597 if (pad != 0)
3598 size += md.pointer_size - pad;
3599 /* Add 8 for the header. */
3600 size += 8;
3601 /* Add a pointer for the personality offset. */
3602 if (unwind.personality_routine)
3603 size += md.pointer_size;
3606 /* If there are unwind records, switch sections, and output the info. */
3607 if (size != 0)
3609 expressionS exp;
3610 bfd_reloc_code_real_type reloc;
3612 start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO);
3614 /* Make sure the section has 4 byte alignment for ILP32 and
3615 8 byte alignment for LP64. */
3616 frag_align (md.pointer_size_shift, 0, 0);
3617 record_alignment (now_seg, md.pointer_size_shift);
3619 /* Set expression which points to start of unwind descriptor area. */
3620 unwind.info = expr_build_dot ();
3622 frag_var (rs_machine_dependent, size, size, 0, 0,
3623 (offsetT) (long) unwind.personality_routine,
3624 (char *) list);
3626 /* Add the personality address to the image. */
3627 if (unwind.personality_routine != 0)
3629 exp.X_op = O_symbol;
3630 exp.X_add_symbol = unwind.personality_routine;
3631 exp.X_add_number = 0;
3633 if (md.flags & EF_IA_64_BE)
3635 if (md.flags & EF_IA_64_ABI64)
3636 reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB;
3637 else
3638 reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB;
3640 else
3642 if (md.flags & EF_IA_64_ABI64)
3643 reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB;
3644 else
3645 reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB;
3648 fix_new_exp (frag_now, frag_now_fix () - md.pointer_size,
3649 md.pointer_size, &exp, 0, reloc);
3650 unwind.personality_routine = 0;
3654 free_saved_prologue_counts ();
3655 unwind.list = unwind.tail = unwind.current_entry = NULL;
3658 static void
3659 dot_handlerdata (dummy)
3660 int dummy ATTRIBUTE_UNUSED;
3662 if (!in_procedure ("handlerdata"))
3663 return;
3664 unwind.force_unwind_entry = 1;
3666 /* Remember which segment we're in so we can switch back after .endp */
3667 unwind.saved_text_seg = now_seg;
3668 unwind.saved_text_subseg = now_subseg;
3670 /* Generate unwind info into unwind-info section and then leave that
3671 section as the currently active one so dataXX directives go into
3672 the language specific data area of the unwind info block. */
3673 generate_unwind_image (now_seg);
3674 demand_empty_rest_of_line ();
3677 static void
3678 dot_unwentry (dummy)
3679 int dummy ATTRIBUTE_UNUSED;
3681 if (!in_procedure ("unwentry"))
3682 return;
3683 unwind.force_unwind_entry = 1;
3684 demand_empty_rest_of_line ();
3687 static void
3688 dot_altrp (dummy)
3689 int dummy ATTRIBUTE_UNUSED;
3691 expressionS e;
3692 unsigned reg;
3694 if (!in_prologue ("altrp"))
3695 return;
3697 parse_operand (&e);
3698 reg = e.X_add_number - REG_BR;
3699 if (e.X_op == O_register && reg < 8)
3700 add_unwind_entry (output_rp_br (reg));
3701 else
3702 as_bad ("First operand not a valid branch register");
3705 static void
3706 dot_savemem (psprel)
3707 int psprel;
3709 expressionS e1, e2;
3710 int sep;
3711 int reg1, val;
3713 if (!in_prologue (psprel ? "savepsp" : "savesp"))
3714 return;
3716 sep = parse_operand (&e1);
3717 if (sep != ',')
3718 as_bad ("No second operand to .save%ssp", psprel ? "p" : "");
3719 sep = parse_operand (&e2);
3721 reg1 = e1.X_add_number;
3722 val = e2.X_add_number;
3724 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
3725 if (e1.X_op == O_register)
3727 if (e2.X_op == O_constant)
3729 switch (reg1)
3731 case REG_AR + AR_BSP:
3732 add_unwind_entry (output_bsp_when ());
3733 add_unwind_entry ((psprel
3734 ? output_bsp_psprel
3735 : output_bsp_sprel) (val));
3736 break;
3737 case REG_AR + AR_BSPSTORE:
3738 add_unwind_entry (output_bspstore_when ());
3739 add_unwind_entry ((psprel
3740 ? output_bspstore_psprel
3741 : output_bspstore_sprel) (val));
3742 break;
3743 case REG_AR + AR_RNAT:
3744 add_unwind_entry (output_rnat_when ());
3745 add_unwind_entry ((psprel
3746 ? output_rnat_psprel
3747 : output_rnat_sprel) (val));
3748 break;
3749 case REG_AR + AR_UNAT:
3750 add_unwind_entry (output_unat_when ());
3751 add_unwind_entry ((psprel
3752 ? output_unat_psprel
3753 : output_unat_sprel) (val));
3754 break;
3755 case REG_AR + AR_FPSR:
3756 add_unwind_entry (output_fpsr_when ());
3757 add_unwind_entry ((psprel
3758 ? output_fpsr_psprel
3759 : output_fpsr_sprel) (val));
3760 break;
3761 case REG_AR + AR_PFS:
3762 add_unwind_entry (output_pfs_when ());
3763 add_unwind_entry ((psprel
3764 ? output_pfs_psprel
3765 : output_pfs_sprel) (val));
3766 break;
3767 case REG_AR + AR_LC:
3768 add_unwind_entry (output_lc_when ());
3769 add_unwind_entry ((psprel
3770 ? output_lc_psprel
3771 : output_lc_sprel) (val));
3772 break;
3773 case REG_BR:
3774 add_unwind_entry (output_rp_when ());
3775 add_unwind_entry ((psprel
3776 ? output_rp_psprel
3777 : output_rp_sprel) (val));
3778 break;
3779 case REG_PR:
3780 add_unwind_entry (output_preds_when ());
3781 add_unwind_entry ((psprel
3782 ? output_preds_psprel
3783 : output_preds_sprel) (val));
3784 break;
3785 case REG_PRIUNAT:
3786 add_unwind_entry (output_priunat_when_mem ());
3787 add_unwind_entry ((psprel
3788 ? output_priunat_psprel
3789 : output_priunat_sprel) (val));
3790 break;
3791 default:
3792 as_bad ("First operand not a valid register");
3795 else
3796 as_bad (" Second operand not a valid constant");
3798 else
3799 as_bad ("First operand not a register");
3802 static void
3803 dot_saveg (dummy)
3804 int dummy ATTRIBUTE_UNUSED;
3806 expressionS e1, e2;
3807 int sep;
3809 if (!in_prologue ("save.g"))
3810 return;
3812 sep = parse_operand (&e1);
3813 if (sep == ',')
3814 parse_operand (&e2);
3816 if (e1.X_op != O_constant)
3817 as_bad ("First operand to .save.g must be a constant.");
3818 else
3820 int grmask = e1.X_add_number;
3821 if (sep != ',')
3822 add_unwind_entry (output_gr_mem (grmask));
3823 else
3825 int reg = e2.X_add_number - REG_GR;
3826 if (e2.X_op == O_register && reg >= 0 && reg < 128)
3827 add_unwind_entry (output_gr_gr (grmask, reg));
3828 else
3829 as_bad ("Second operand is an invalid register.");
3834 static void
3835 dot_savef (dummy)
3836 int dummy ATTRIBUTE_UNUSED;
3838 expressionS e1;
3839 int sep;
3841 if (!in_prologue ("save.f"))
3842 return;
3844 sep = parse_operand (&e1);
3846 if (e1.X_op != O_constant)
3847 as_bad ("Operand to .save.f must be a constant.");
3848 else
3849 add_unwind_entry (output_fr_mem (e1.X_add_number));
3852 static void
3853 dot_saveb (dummy)
3854 int dummy ATTRIBUTE_UNUSED;
3856 expressionS e1, e2;
3857 unsigned int reg;
3858 unsigned char sep;
3859 int brmask;
3861 if (!in_prologue ("save.b"))
3862 return;
3864 sep = parse_operand (&e1);
3865 if (e1.X_op != O_constant)
3867 as_bad ("First operand to .save.b must be a constant.");
3868 return;
3870 brmask = e1.X_add_number;
3872 if (sep == ',')
3874 sep = parse_operand (&e2);
3875 reg = e2.X_add_number - REG_GR;
3876 if (e2.X_op != O_register || reg > 127)
3878 as_bad ("Second operand to .save.b must be a general register.");
3879 return;
3881 add_unwind_entry (output_br_gr (brmask, e2.X_add_number));
3883 else
3884 add_unwind_entry (output_br_mem (brmask));
3886 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3887 demand_empty_rest_of_line ();
3890 static void
3891 dot_savegf (dummy)
3892 int dummy ATTRIBUTE_UNUSED;
3894 expressionS e1, e2;
3895 int sep;
3897 if (!in_prologue ("save.gf"))
3898 return;
3900 sep = parse_operand (&e1);
3901 if (sep == ',')
3902 parse_operand (&e2);
3904 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
3905 as_bad ("Both operands of .save.gf must be constants.");
3906 else
3908 int grmask = e1.X_add_number;
3909 int frmask = e2.X_add_number;
3910 add_unwind_entry (output_frgr_mem (grmask, frmask));
3914 static void
3915 dot_spill (dummy)
3916 int dummy ATTRIBUTE_UNUSED;
3918 expressionS e;
3919 unsigned char sep;
3921 if (!in_prologue ("spill"))
3922 return;
3924 sep = parse_operand (&e);
3925 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
3926 demand_empty_rest_of_line ();
3928 if (e.X_op != O_constant)
3929 as_bad ("Operand to .spill must be a constant");
3930 else
3931 add_unwind_entry (output_spill_base (e.X_add_number));
3934 static void
3935 dot_spillreg (dummy)
3936 int dummy ATTRIBUTE_UNUSED;
3938 int sep;
3939 unsigned int ab, xy, reg, treg;
3940 expressionS e1, e2;
3942 if (!in_procedure ("spillreg"))
3943 return;
3945 sep = parse_operand (&e1);
3946 if (sep != ',')
3948 as_bad ("No second operand to .spillreg");
3949 return;
3952 parse_operand (&e2);
3954 if (!convert_expr_to_ab_reg (&e1, &ab, &reg))
3956 as_bad ("First operand to .spillreg must be a preserved register");
3957 return;
3960 if (!convert_expr_to_xy_reg (&e2, &xy, &treg))
3962 as_bad ("Second operand to .spillreg must be a register");
3963 return;
3966 add_unwind_entry (output_spill_reg (ab, reg, treg, xy));
3969 static void
3970 dot_spillmem (psprel)
3971 int psprel;
3973 expressionS e1, e2;
3974 int sep;
3975 unsigned int ab, reg;
3977 if (!in_procedure ("spillmem"))
3978 return;
3980 sep = parse_operand (&e1);
3981 if (sep != ',')
3983 as_bad ("Second operand missing");
3984 return;
3987 parse_operand (&e2);
3989 if (!convert_expr_to_ab_reg (&e1, &ab, &reg))
3991 as_bad ("First operand to .spill%s must be a preserved register",
3992 psprel ? "psp" : "sp");
3993 return;
3996 if (e2.X_op != O_constant)
3998 as_bad ("Second operand to .spill%s must be a constant",
3999 psprel ? "psp" : "sp");
4000 return;
4003 if (psprel)
4004 add_unwind_entry (output_spill_psprel (ab, reg, e2.X_add_number));
4005 else
4006 add_unwind_entry (output_spill_sprel (ab, reg, e2.X_add_number));
4009 static void
4010 dot_spillreg_p (dummy)
4011 int dummy ATTRIBUTE_UNUSED;
4013 int sep;
4014 unsigned int ab, xy, reg, treg;
4015 expressionS e1, e2, e3;
4016 unsigned int qp;
4018 if (!in_procedure ("spillreg.p"))
4019 return;
4021 sep = parse_operand (&e1);
4022 if (sep != ',')
4024 as_bad ("No second and third operand to .spillreg.p");
4025 return;
4028 sep = parse_operand (&e2);
4029 if (sep != ',')
4031 as_bad ("No third operand to .spillreg.p");
4032 return;
4035 parse_operand (&e3);
4037 qp = e1.X_add_number - REG_P;
4039 if (e1.X_op != O_register || qp > 63)
4041 as_bad ("First operand to .spillreg.p must be a predicate");
4042 return;
4045 if (!convert_expr_to_ab_reg (&e2, &ab, &reg))
4047 as_bad ("Second operand to .spillreg.p must be a preserved register");
4048 return;
4051 if (!convert_expr_to_xy_reg (&e3, &xy, &treg))
4053 as_bad ("Third operand to .spillreg.p must be a register");
4054 return;
4057 add_unwind_entry (output_spill_reg_p (ab, reg, treg, xy, qp));
4060 static void
4061 dot_spillmem_p (psprel)
4062 int psprel;
4064 expressionS e1, e2, e3;
4065 int sep;
4066 unsigned int ab, reg;
4067 unsigned int qp;
4069 if (!in_procedure ("spillmem.p"))
4070 return;
4072 sep = parse_operand (&e1);
4073 if (sep != ',')
4075 as_bad ("Second operand missing");
4076 return;
4079 parse_operand (&e2);
4080 if (sep != ',')
4082 as_bad ("Second operand missing");
4083 return;
4086 parse_operand (&e3);
4088 qp = e1.X_add_number - REG_P;
4089 if (e1.X_op != O_register || qp > 63)
4091 as_bad ("First operand to .spill%s_p must be a predicate",
4092 psprel ? "psp" : "sp");
4093 return;
4096 if (!convert_expr_to_ab_reg (&e2, &ab, &reg))
4098 as_bad ("Second operand to .spill%s_p must be a preserved register",
4099 psprel ? "psp" : "sp");
4100 return;
4103 if (e3.X_op != O_constant)
4105 as_bad ("Third operand to .spill%s_p must be a constant",
4106 psprel ? "psp" : "sp");
4107 return;
4110 if (psprel)
4111 add_unwind_entry (output_spill_psprel_p (ab, reg, e3.X_add_number, qp));
4112 else
4113 add_unwind_entry (output_spill_sprel_p (ab, reg, e3.X_add_number, qp));
4116 static unsigned int
4117 get_saved_prologue_count (lbl)
4118 unsigned long lbl;
4120 label_prologue_count *lpc = unwind.saved_prologue_counts;
4122 while (lpc != NULL && lpc->label_number != lbl)
4123 lpc = lpc->next;
4125 if (lpc != NULL)
4126 return lpc->prologue_count;
4128 as_bad ("Missing .label_state %ld", lbl);
4129 return 1;
4132 static void
4133 save_prologue_count (lbl, count)
4134 unsigned long lbl;
4135 unsigned int count;
4137 label_prologue_count *lpc = unwind.saved_prologue_counts;
4139 while (lpc != NULL && lpc->label_number != lbl)
4140 lpc = lpc->next;
4142 if (lpc != NULL)
4143 lpc->prologue_count = count;
4144 else
4146 label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc));
4148 new_lpc->next = unwind.saved_prologue_counts;
4149 new_lpc->label_number = lbl;
4150 new_lpc->prologue_count = count;
4151 unwind.saved_prologue_counts = new_lpc;
4155 static void
4156 free_saved_prologue_counts ()
4158 label_prologue_count *lpc = unwind.saved_prologue_counts;
4159 label_prologue_count *next;
4161 while (lpc != NULL)
4163 next = lpc->next;
4164 free (lpc);
4165 lpc = next;
4168 unwind.saved_prologue_counts = NULL;
4171 static void
4172 dot_label_state (dummy)
4173 int dummy ATTRIBUTE_UNUSED;
4175 expressionS e;
4177 if (!in_body ("label_state"))
4178 return;
4180 parse_operand (&e);
4181 if (e.X_op != O_constant)
4183 as_bad ("Operand to .label_state must be a constant");
4184 return;
4186 add_unwind_entry (output_label_state (e.X_add_number));
4187 save_prologue_count (e.X_add_number, unwind.prologue_count);
4190 static void
4191 dot_copy_state (dummy)
4192 int dummy ATTRIBUTE_UNUSED;
4194 expressionS e;
4196 if (!in_body ("copy_state"))
4197 return;
4199 parse_operand (&e);
4200 if (e.X_op != O_constant)
4202 as_bad ("Operand to .copy_state must be a constant");
4203 return;
4205 add_unwind_entry (output_copy_state (e.X_add_number));
4206 unwind.prologue_count = get_saved_prologue_count (e.X_add_number);
4209 static void
4210 dot_unwabi (dummy)
4211 int dummy ATTRIBUTE_UNUSED;
4213 expressionS e1, e2;
4214 unsigned char sep;
4216 if (!in_procedure ("unwabi"))
4217 return;
4219 sep = parse_operand (&e1);
4220 if (sep != ',')
4222 as_bad ("Second operand to .unwabi missing");
4223 return;
4225 sep = parse_operand (&e2);
4226 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4227 demand_empty_rest_of_line ();
4229 if (e1.X_op != O_constant)
4231 as_bad ("First operand to .unwabi must be a constant");
4232 return;
4235 if (e2.X_op != O_constant)
4237 as_bad ("Second operand to .unwabi must be a constant");
4238 return;
4241 add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number));
4244 static void
4245 dot_personality (dummy)
4246 int dummy ATTRIBUTE_UNUSED;
4248 char *name, *p, c;
4249 if (!in_procedure ("personality"))
4250 return;
4251 SKIP_WHITESPACE ();
4252 name = input_line_pointer;
4253 c = get_symbol_end ();
4254 p = input_line_pointer;
4255 unwind.personality_routine = symbol_find_or_make (name);
4256 unwind.force_unwind_entry = 1;
4257 *p = c;
4258 SKIP_WHITESPACE ();
4259 demand_empty_rest_of_line ();
4262 static void
4263 dot_proc (dummy)
4264 int dummy ATTRIBUTE_UNUSED;
4266 char *name, *p, c;
4267 symbolS *sym;
4269 unwind.proc_start = 0;
4270 /* Parse names of main and alternate entry points and mark them as
4271 function symbols: */
4272 while (1)
4274 SKIP_WHITESPACE ();
4275 name = input_line_pointer;
4276 c = get_symbol_end ();
4277 p = input_line_pointer;
4278 if (!*name)
4279 as_bad ("Empty argument of .proc");
4280 else
4282 sym = symbol_find_or_make (name);
4283 if (S_IS_DEFINED (sym))
4284 as_bad ("`%s' was already defined", name);
4285 else if (unwind.proc_start == 0)
4287 unwind.proc_start = sym;
4289 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
4291 *p = c;
4292 SKIP_WHITESPACE ();
4293 if (*input_line_pointer != ',')
4294 break;
4295 ++input_line_pointer;
4297 if (unwind.proc_start == 0)
4298 unwind.proc_start = expr_build_dot ();
4299 demand_empty_rest_of_line ();
4300 ia64_do_align (16);
4302 unwind.prologue = 0;
4303 unwind.prologue_count = 0;
4304 unwind.body = 0;
4305 unwind.insn = 0;
4306 unwind.list = unwind.tail = unwind.current_entry = NULL;
4307 unwind.personality_routine = 0;
4310 static void
4311 dot_body (dummy)
4312 int dummy ATTRIBUTE_UNUSED;
4314 if (!in_procedure ("body"))
4315 return;
4316 if (!unwind.prologue && !unwind.body && unwind.insn)
4317 as_warn ("Initial .body should precede any instructions");
4319 unwind.prologue = 0;
4320 unwind.prologue_mask = 0;
4321 unwind.body = 1;
4323 add_unwind_entry (output_body ());
4324 demand_empty_rest_of_line ();
4327 static void
4328 dot_prologue (dummy)
4329 int dummy ATTRIBUTE_UNUSED;
4331 unsigned char sep;
4332 int mask = 0, grsave = 0;
4334 if (!in_procedure ("prologue"))
4335 return;
4336 if (unwind.prologue)
4338 as_bad (".prologue within prologue");
4339 ignore_rest_of_line ();
4340 return;
4342 if (!unwind.body && unwind.insn)
4343 as_warn ("Initial .prologue should precede any instructions");
4345 if (!is_it_end_of_statement ())
4347 expressionS e1, e2;
4348 sep = parse_operand (&e1);
4349 if (sep != ',')
4350 as_bad ("No second operand to .prologue");
4351 sep = parse_operand (&e2);
4352 if (!is_end_of_line[sep] && !is_it_end_of_statement ())
4353 demand_empty_rest_of_line ();
4355 if (e1.X_op == O_constant)
4357 mask = e1.X_add_number;
4359 if (e2.X_op == O_constant)
4360 grsave = e2.X_add_number;
4361 else if (e2.X_op == O_register
4362 && (grsave = e2.X_add_number - REG_GR) < 128)
4364 else
4365 as_bad ("Second operand not a constant or general register");
4367 add_unwind_entry (output_prologue_gr (mask, grsave));
4369 else
4370 as_bad ("First operand not a constant");
4372 else
4373 add_unwind_entry (output_prologue ());
4375 unwind.prologue = 1;
4376 unwind.prologue_mask = mask;
4377 unwind.body = 0;
4378 ++unwind.prologue_count;
4381 static void
4382 dot_endp (dummy)
4383 int dummy ATTRIBUTE_UNUSED;
4385 expressionS e;
4386 char *ptr;
4387 int bytes_per_address;
4388 long where;
4389 segT saved_seg;
4390 subsegT saved_subseg;
4391 char *name, *default_name, *p, c;
4392 symbolS *sym;
4393 int unwind_check = md.unwind_check;
4395 md.unwind_check = unwind_check_error;
4396 if (!in_procedure ("endp"))
4397 return;
4398 md.unwind_check = unwind_check;
4400 if (unwind.saved_text_seg)
4402 saved_seg = unwind.saved_text_seg;
4403 saved_subseg = unwind.saved_text_subseg;
4404 unwind.saved_text_seg = NULL;
4406 else
4408 saved_seg = now_seg;
4409 saved_subseg = now_subseg;
4412 insn_group_break (1, 0, 0);
4414 /* If there wasn't a .handlerdata, we haven't generated an image yet. */
4415 if (!unwind.info)
4416 generate_unwind_image (saved_seg);
4418 if (unwind.info || unwind.force_unwind_entry)
4420 symbolS *proc_end;
4422 subseg_set (md.last_text_seg, 0);
4423 proc_end = expr_build_dot ();
4425 start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND);
4427 /* Make sure that section has 4 byte alignment for ILP32 and
4428 8 byte alignment for LP64. */
4429 record_alignment (now_seg, md.pointer_size_shift);
4431 /* Need space for 3 pointers for procedure start, procedure end,
4432 and unwind info. */
4433 ptr = frag_more (3 * md.pointer_size);
4434 where = frag_now_fix () - (3 * md.pointer_size);
4435 bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8;
4437 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
4438 e.X_op = O_pseudo_fixup;
4439 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4440 e.X_add_number = 0;
4441 e.X_add_symbol = unwind.proc_start;
4442 ia64_cons_fix_new (frag_now, where, bytes_per_address, &e);
4444 e.X_op = O_pseudo_fixup;
4445 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4446 e.X_add_number = 0;
4447 e.X_add_symbol = proc_end;
4448 ia64_cons_fix_new (frag_now, where + bytes_per_address,
4449 bytes_per_address, &e);
4451 if (unwind.info)
4453 e.X_op = O_pseudo_fixup;
4454 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
4455 e.X_add_number = 0;
4456 e.X_add_symbol = unwind.info;
4457 ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2),
4458 bytes_per_address, &e);
4460 else
4461 md_number_to_chars (ptr + (bytes_per_address * 2), 0,
4462 bytes_per_address);
4465 subseg_set (saved_seg, saved_subseg);
4467 if (unwind.proc_start)
4468 default_name = (char *) S_GET_NAME (unwind.proc_start);
4469 else
4470 default_name = NULL;
4472 /* Parse names of main and alternate entry points and set symbol sizes. */
4473 while (1)
4475 SKIP_WHITESPACE ();
4476 name = input_line_pointer;
4477 c = get_symbol_end ();
4478 p = input_line_pointer;
4479 if (!*name)
4481 if (md.unwind_check == unwind_check_warning)
4483 if (default_name)
4485 as_warn ("Empty argument of .endp. Use the default name `%s'",
4486 default_name);
4487 name = default_name;
4489 else
4490 as_warn ("Empty argument of .endp");
4492 else
4493 as_bad ("Empty argument of .endp");
4495 if (*name)
4497 sym = symbol_find (name);
4498 if (!sym
4499 && md.unwind_check == unwind_check_warning
4500 && default_name
4501 && default_name != name)
4503 /* We have a bad name. Try the default one if needed. */
4504 as_warn ("`%s' was not defined within procedure. Use the default name `%s'",
4505 name, default_name);
4506 name = default_name;
4507 sym = symbol_find (name);
4509 if (!sym || !S_IS_DEFINED (sym))
4510 as_bad ("`%s' was not defined within procedure", name);
4511 else if (unwind.proc_start
4512 && (symbol_get_bfdsym (sym)->flags & BSF_FUNCTION)
4513 && S_GET_SIZE (sym) == 0 && symbol_get_obj (sym)->size == NULL)
4515 fragS *fr = symbol_get_frag (unwind.proc_start);
4516 fragS *frag = symbol_get_frag (sym);
4518 /* Check whether the function label is at or beyond last
4519 .proc directive. */
4520 while (fr && fr != frag)
4521 fr = fr->fr_next;
4522 if (fr)
4524 if (frag == frag_now && SEG_NORMAL (now_seg))
4525 S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym));
4526 else
4528 symbol_get_obj (sym)->size =
4529 (expressionS *) xmalloc (sizeof (expressionS));
4530 symbol_get_obj (sym)->size->X_op = O_subtract;
4531 symbol_get_obj (sym)->size->X_add_symbol
4532 = symbol_new (FAKE_LABEL_NAME, now_seg,
4533 frag_now_fix (), frag_now);
4534 symbol_get_obj (sym)->size->X_op_symbol = sym;
4535 symbol_get_obj (sym)->size->X_add_number = 0;
4540 *p = c;
4541 SKIP_WHITESPACE ();
4542 if (*input_line_pointer != ',')
4543 break;
4544 ++input_line_pointer;
4546 demand_empty_rest_of_line ();
4547 unwind.proc_start = unwind.info = 0;
4550 static void
4551 dot_template (template)
4552 int template;
4554 CURR_SLOT.user_template = template;
4557 static void
4558 dot_regstk (dummy)
4559 int dummy ATTRIBUTE_UNUSED;
4561 int ins, locs, outs, rots;
4563 if (is_it_end_of_statement ())
4564 ins = locs = outs = rots = 0;
4565 else
4567 ins = get_absolute_expression ();
4568 if (*input_line_pointer++ != ',')
4569 goto err;
4570 locs = get_absolute_expression ();
4571 if (*input_line_pointer++ != ',')
4572 goto err;
4573 outs = get_absolute_expression ();
4574 if (*input_line_pointer++ != ',')
4575 goto err;
4576 rots = get_absolute_expression ();
4578 set_regstack (ins, locs, outs, rots);
4579 return;
4581 err:
4582 as_bad ("Comma expected");
4583 ignore_rest_of_line ();
4586 static void
4587 dot_rot (type)
4588 int type;
4590 unsigned num_regs, num_alloced = 0;
4591 struct dynreg **drpp, *dr;
4592 int ch, base_reg = 0;
4593 char *name, *start;
4594 size_t len;
4596 switch (type)
4598 case DYNREG_GR: base_reg = REG_GR + 32; break;
4599 case DYNREG_FR: base_reg = REG_FR + 32; break;
4600 case DYNREG_PR: base_reg = REG_P + 16; break;
4601 default: break;
4604 /* First, remove existing names from hash table. */
4605 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
4607 hash_delete (md.dynreg_hash, dr->name);
4608 /* FIXME: Free dr->name. */
4609 dr->num_regs = 0;
4612 drpp = &md.dynreg[type];
4613 while (1)
4615 start = input_line_pointer;
4616 ch = get_symbol_end ();
4617 len = strlen (ia64_canonicalize_symbol_name (start));
4618 *input_line_pointer = ch;
4620 SKIP_WHITESPACE ();
4621 if (*input_line_pointer != '[')
4623 as_bad ("Expected '['");
4624 goto err;
4626 ++input_line_pointer; /* skip '[' */
4628 num_regs = get_absolute_expression ();
4630 if (*input_line_pointer++ != ']')
4632 as_bad ("Expected ']'");
4633 goto err;
4635 SKIP_WHITESPACE ();
4637 num_alloced += num_regs;
4638 switch (type)
4640 case DYNREG_GR:
4641 if (num_alloced > md.rot.num_regs)
4643 as_bad ("Used more than the declared %d rotating registers",
4644 md.rot.num_regs);
4645 goto err;
4647 break;
4648 case DYNREG_FR:
4649 if (num_alloced > 96)
4651 as_bad ("Used more than the available 96 rotating registers");
4652 goto err;
4654 break;
4655 case DYNREG_PR:
4656 if (num_alloced > 48)
4658 as_bad ("Used more than the available 48 rotating registers");
4659 goto err;
4661 break;
4663 default:
4664 break;
4667 if (!*drpp)
4669 *drpp = obstack_alloc (&notes, sizeof (*dr));
4670 memset (*drpp, 0, sizeof (*dr));
4673 name = obstack_alloc (&notes, len + 1);
4674 memcpy (name, start, len);
4675 name[len] = '\0';
4677 dr = *drpp;
4678 dr->name = name;
4679 dr->num_regs = num_regs;
4680 dr->base = base_reg;
4681 drpp = &dr->next;
4682 base_reg += num_regs;
4684 if (hash_insert (md.dynreg_hash, name, dr))
4686 as_bad ("Attempt to redefine register set `%s'", name);
4687 obstack_free (&notes, name);
4688 goto err;
4691 if (*input_line_pointer != ',')
4692 break;
4693 ++input_line_pointer; /* skip comma */
4694 SKIP_WHITESPACE ();
4696 demand_empty_rest_of_line ();
4697 return;
4699 err:
4700 ignore_rest_of_line ();
4703 static void
4704 dot_byteorder (byteorder)
4705 int byteorder;
4707 segment_info_type *seginfo = seg_info (now_seg);
4709 if (byteorder == -1)
4711 if (seginfo->tc_segment_info_data.endian == 0)
4712 seginfo->tc_segment_info_data.endian = default_big_endian ? 1 : 2;
4713 byteorder = seginfo->tc_segment_info_data.endian == 1;
4715 else
4716 seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2;
4718 if (target_big_endian != byteorder)
4720 target_big_endian = byteorder;
4721 if (target_big_endian)
4723 ia64_number_to_chars = number_to_chars_bigendian;
4724 ia64_float_to_chars = ia64_float_to_chars_bigendian;
4726 else
4728 ia64_number_to_chars = number_to_chars_littleendian;
4729 ia64_float_to_chars = ia64_float_to_chars_littleendian;
4734 static void
4735 dot_psr (dummy)
4736 int dummy ATTRIBUTE_UNUSED;
4738 char *option;
4739 int ch;
4741 while (1)
4743 option = input_line_pointer;
4744 ch = get_symbol_end ();
4745 if (strcmp (option, "lsb") == 0)
4746 md.flags &= ~EF_IA_64_BE;
4747 else if (strcmp (option, "msb") == 0)
4748 md.flags |= EF_IA_64_BE;
4749 else if (strcmp (option, "abi32") == 0)
4750 md.flags &= ~EF_IA_64_ABI64;
4751 else if (strcmp (option, "abi64") == 0)
4752 md.flags |= EF_IA_64_ABI64;
4753 else
4754 as_bad ("Unknown psr option `%s'", option);
4755 *input_line_pointer = ch;
4757 SKIP_WHITESPACE ();
4758 if (*input_line_pointer != ',')
4759 break;
4761 ++input_line_pointer;
4762 SKIP_WHITESPACE ();
4764 demand_empty_rest_of_line ();
4767 static void
4768 dot_ln (dummy)
4769 int dummy ATTRIBUTE_UNUSED;
4771 new_logical_line (0, get_absolute_expression ());
4772 demand_empty_rest_of_line ();
4775 static void
4776 cross_section (ref, cons, ua)
4777 int ref;
4778 void (*cons) PARAMS((int));
4779 int ua;
4781 char *start, *end;
4782 int saved_auto_align;
4783 unsigned int section_count;
4785 SKIP_WHITESPACE ();
4786 start = input_line_pointer;
4787 if (*start == '"')
4789 int len;
4790 char *name;
4792 name = demand_copy_C_string (&len);
4793 obstack_free(&notes, name);
4794 if (!name)
4796 ignore_rest_of_line ();
4797 return;
4800 else
4802 char c = get_symbol_end ();
4804 if (input_line_pointer == start)
4806 as_bad ("Missing section name");
4807 ignore_rest_of_line ();
4808 return;
4810 *input_line_pointer = c;
4812 end = input_line_pointer;
4813 SKIP_WHITESPACE ();
4814 if (*input_line_pointer != ',')
4816 as_bad ("Comma expected after section name");
4817 ignore_rest_of_line ();
4818 return;
4820 *end = '\0';
4821 end = input_line_pointer + 1; /* skip comma */
4822 input_line_pointer = start;
4823 md.keep_pending_output = 1;
4824 section_count = bfd_count_sections(stdoutput);
4825 obj_elf_section (0);
4826 if (section_count != bfd_count_sections(stdoutput))
4827 as_warn ("Creating sections with .xdataN/.xrealN/.xstringZ is deprecated.");
4828 input_line_pointer = end;
4829 saved_auto_align = md.auto_align;
4830 if (ua)
4831 md.auto_align = 0;
4832 (*cons) (ref);
4833 if (ua)
4834 md.auto_align = saved_auto_align;
4835 obj_elf_previous (0);
4836 md.keep_pending_output = 0;
4839 static void
4840 dot_xdata (size)
4841 int size;
4843 cross_section (size, cons, 0);
4846 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
4848 static void
4849 stmt_float_cons (kind)
4850 int kind;
4852 size_t alignment;
4854 switch (kind)
4856 case 'd':
4857 alignment = 8;
4858 break;
4860 case 'x':
4861 case 'X':
4862 alignment = 16;
4863 break;
4865 case 'f':
4866 default:
4867 alignment = 4;
4868 break;
4870 ia64_do_align (alignment);
4871 float_cons (kind);
4874 static void
4875 stmt_cons_ua (size)
4876 int size;
4878 int saved_auto_align = md.auto_align;
4880 md.auto_align = 0;
4881 cons (size);
4882 md.auto_align = saved_auto_align;
4885 static void
4886 dot_xfloat_cons (kind)
4887 int kind;
4889 cross_section (kind, stmt_float_cons, 0);
4892 static void
4893 dot_xstringer (zero)
4894 int zero;
4896 cross_section (zero, stringer, 0);
4899 static void
4900 dot_xdata_ua (size)
4901 int size;
4903 cross_section (size, cons, 1);
4906 static void
4907 dot_xfloat_cons_ua (kind)
4908 int kind;
4910 cross_section (kind, float_cons, 1);
4913 /* .reg.val <regname>,value */
4915 static void
4916 dot_reg_val (dummy)
4917 int dummy ATTRIBUTE_UNUSED;
4919 expressionS reg;
4921 expression (&reg);
4922 if (reg.X_op != O_register)
4924 as_bad (_("Register name expected"));
4925 ignore_rest_of_line ();
4927 else if (*input_line_pointer++ != ',')
4929 as_bad (_("Comma expected"));
4930 ignore_rest_of_line ();
4932 else
4934 valueT value = get_absolute_expression ();
4935 int regno = reg.X_add_number;
4936 if (regno <= REG_GR || regno > REG_GR + 127)
4937 as_warn (_("Register value annotation ignored"));
4938 else
4940 gr_values[regno - REG_GR].known = 1;
4941 gr_values[regno - REG_GR].value = value;
4942 gr_values[regno - REG_GR].path = md.path;
4945 demand_empty_rest_of_line ();
4949 .serialize.data
4950 .serialize.instruction
4952 static void
4953 dot_serialize (type)
4954 int type;
4956 insn_group_break (0, 0, 0);
4957 if (type)
4958 instruction_serialization ();
4959 else
4960 data_serialization ();
4961 insn_group_break (0, 0, 0);
4962 demand_empty_rest_of_line ();
4965 /* select dv checking mode
4966 .auto
4967 .explicit
4968 .default
4970 A stop is inserted when changing modes
4973 static void
4974 dot_dv_mode (type)
4975 int type;
4977 if (md.manual_bundling)
4978 as_warn (_("Directive invalid within a bundle"));
4980 if (type == 'E' || type == 'A')
4981 md.mode_explicitly_set = 0;
4982 else
4983 md.mode_explicitly_set = 1;
4985 md.detect_dv = 1;
4986 switch (type)
4988 case 'A':
4989 case 'a':
4990 if (md.explicit_mode)
4991 insn_group_break (1, 0, 0);
4992 md.explicit_mode = 0;
4993 break;
4994 case 'E':
4995 case 'e':
4996 if (!md.explicit_mode)
4997 insn_group_break (1, 0, 0);
4998 md.explicit_mode = 1;
4999 break;
5000 default:
5001 case 'd':
5002 if (md.explicit_mode != md.default_explicit_mode)
5003 insn_group_break (1, 0, 0);
5004 md.explicit_mode = md.default_explicit_mode;
5005 md.mode_explicitly_set = 0;
5006 break;
5010 static void
5011 print_prmask (mask)
5012 valueT mask;
5014 int regno;
5015 char *comma = "";
5016 for (regno = 0; regno < 64; regno++)
5018 if (mask & ((valueT) 1 << regno))
5020 fprintf (stderr, "%s p%d", comma, regno);
5021 comma = ",";
5027 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear" or @clear)
5028 .pred.rel.imply p1, p2 (also .pred.rel "imply" or @imply)
5029 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex" or @mutex)
5030 .pred.safe_across_calls p1 [, p2 [,...]]
5033 static void
5034 dot_pred_rel (type)
5035 int type;
5037 valueT mask = 0;
5038 int count = 0;
5039 int p1 = -1, p2 = -1;
5041 if (type == 0)
5043 if (*input_line_pointer == '"')
5045 int len;
5046 char *form = demand_copy_C_string (&len);
5048 if (strcmp (form, "mutex") == 0)
5049 type = 'm';
5050 else if (strcmp (form, "clear") == 0)
5051 type = 'c';
5052 else if (strcmp (form, "imply") == 0)
5053 type = 'i';
5054 obstack_free (&notes, form);
5056 else if (*input_line_pointer == '@')
5058 char *form = ++input_line_pointer;
5059 char c = get_symbol_end();
5061 if (strcmp (form, "mutex") == 0)
5062 type = 'm';
5063 else if (strcmp (form, "clear") == 0)
5064 type = 'c';
5065 else if (strcmp (form, "imply") == 0)
5066 type = 'i';
5067 *input_line_pointer = c;
5069 else
5071 as_bad (_("Missing predicate relation type"));
5072 ignore_rest_of_line ();
5073 return;
5075 if (type == 0)
5077 as_bad (_("Unrecognized predicate relation type"));
5078 ignore_rest_of_line ();
5079 return;
5081 if (*input_line_pointer == ',')
5082 ++input_line_pointer;
5083 SKIP_WHITESPACE ();
5086 SKIP_WHITESPACE ();
5087 while (1)
5089 valueT bits = 1;
5090 int regno;
5091 expressionS pr, *pr1, *pr2;
5093 expression (&pr);
5094 if (pr.X_op == O_register
5095 && pr.X_add_number >= REG_P
5096 && pr.X_add_number <= REG_P + 63)
5098 regno = pr.X_add_number - REG_P;
5099 bits <<= regno;
5100 count++;
5101 if (p1 == -1)
5102 p1 = regno;
5103 else if (p2 == -1)
5104 p2 = regno;
5106 else if (type != 'i'
5107 && pr.X_op == O_subtract
5108 && (pr1 = symbol_get_value_expression (pr.X_add_symbol))
5109 && pr1->X_op == O_register
5110 && pr1->X_add_number >= REG_P
5111 && pr1->X_add_number <= REG_P + 63
5112 && (pr2 = symbol_get_value_expression (pr.X_op_symbol))
5113 && pr2->X_op == O_register
5114 && pr2->X_add_number >= REG_P
5115 && pr2->X_add_number <= REG_P + 63)
5117 /* It's a range. */
5118 int stop;
5120 regno = pr1->X_add_number - REG_P;
5121 stop = pr2->X_add_number - REG_P;
5122 if (regno >= stop)
5124 as_bad (_("Bad register range"));
5125 ignore_rest_of_line ();
5126 return;
5128 bits = ((bits << stop) << 1) - (bits << regno);
5129 count += stop - regno + 1;
5131 else
5133 as_bad (_("Predicate register expected"));
5134 ignore_rest_of_line ();
5135 return;
5137 if (mask & bits)
5138 as_warn (_("Duplicate predicate register ignored"));
5139 mask |= bits;
5140 if (*input_line_pointer != ',')
5141 break;
5142 ++input_line_pointer;
5143 SKIP_WHITESPACE ();
5146 switch (type)
5148 case 'c':
5149 if (count == 0)
5150 mask = ~(valueT) 0;
5151 clear_qp_mutex (mask);
5152 clear_qp_implies (mask, (valueT) 0);
5153 break;
5154 case 'i':
5155 if (count != 2 || p1 == -1 || p2 == -1)
5156 as_bad (_("Predicate source and target required"));
5157 else if (p1 == 0 || p2 == 0)
5158 as_bad (_("Use of p0 is not valid in this context"));
5159 else
5160 add_qp_imply (p1, p2);
5161 break;
5162 case 'm':
5163 if (count < 2)
5165 as_bad (_("At least two PR arguments expected"));
5166 break;
5168 else if (mask & 1)
5170 as_bad (_("Use of p0 is not valid in this context"));
5171 break;
5173 add_qp_mutex (mask);
5174 break;
5175 case 's':
5176 /* note that we don't override any existing relations */
5177 if (count == 0)
5179 as_bad (_("At least one PR argument expected"));
5180 break;
5182 if (md.debug_dv)
5184 fprintf (stderr, "Safe across calls: ");
5185 print_prmask (mask);
5186 fprintf (stderr, "\n");
5188 qp_safe_across_calls = mask;
5189 break;
5191 demand_empty_rest_of_line ();
5194 /* .entry label [, label [, ...]]
5195 Hint to DV code that the given labels are to be considered entry points.
5196 Otherwise, only global labels are considered entry points. */
5198 static void
5199 dot_entry (dummy)
5200 int dummy ATTRIBUTE_UNUSED;
5202 const char *err;
5203 char *name;
5204 int c;
5205 symbolS *symbolP;
5209 name = input_line_pointer;
5210 c = get_symbol_end ();
5211 symbolP = symbol_find_or_make (name);
5213 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
5214 if (err)
5215 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
5216 name, err);
5218 *input_line_pointer = c;
5219 SKIP_WHITESPACE ();
5220 c = *input_line_pointer;
5221 if (c == ',')
5223 input_line_pointer++;
5224 SKIP_WHITESPACE ();
5225 if (*input_line_pointer == '\n')
5226 c = '\n';
5229 while (c == ',');
5231 demand_empty_rest_of_line ();
5234 /* .mem.offset offset, base
5235 "base" is used to distinguish between offsets from a different base. */
5237 static void
5238 dot_mem_offset (dummy)
5239 int dummy ATTRIBUTE_UNUSED;
5241 md.mem_offset.hint = 1;
5242 md.mem_offset.offset = get_absolute_expression ();
5243 if (*input_line_pointer != ',')
5245 as_bad (_("Comma expected"));
5246 ignore_rest_of_line ();
5247 return;
5249 ++input_line_pointer;
5250 md.mem_offset.base = get_absolute_expression ();
5251 demand_empty_rest_of_line ();
5254 /* ia64-specific pseudo-ops: */
5255 const pseudo_typeS md_pseudo_table[] =
5257 { "radix", dot_radix, 0 },
5258 { "lcomm", s_lcomm_bytes, 1 },
5259 { "loc", dot_loc, 0 },
5260 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
5261 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
5262 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
5263 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
5264 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
5265 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
5266 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
5267 { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY },
5268 { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY },
5269 { "proc", dot_proc, 0 },
5270 { "body", dot_body, 0 },
5271 { "prologue", dot_prologue, 0 },
5272 { "endp", dot_endp, 0 },
5274 { "fframe", dot_fframe, 0 },
5275 { "vframe", dot_vframe, 0 },
5276 { "vframesp", dot_vframesp, 0 },
5277 { "vframepsp", dot_vframepsp, 0 },
5278 { "save", dot_save, 0 },
5279 { "restore", dot_restore, 0 },
5280 { "restorereg", dot_restorereg, 0 },
5281 { "restorereg.p", dot_restorereg_p, 0 },
5282 { "handlerdata", dot_handlerdata, 0 },
5283 { "unwentry", dot_unwentry, 0 },
5284 { "altrp", dot_altrp, 0 },
5285 { "savesp", dot_savemem, 0 },
5286 { "savepsp", dot_savemem, 1 },
5287 { "save.g", dot_saveg, 0 },
5288 { "save.f", dot_savef, 0 },
5289 { "save.b", dot_saveb, 0 },
5290 { "save.gf", dot_savegf, 0 },
5291 { "spill", dot_spill, 0 },
5292 { "spillreg", dot_spillreg, 0 },
5293 { "spillsp", dot_spillmem, 0 },
5294 { "spillpsp", dot_spillmem, 1 },
5295 { "spillreg.p", dot_spillreg_p, 0 },
5296 { "spillsp.p", dot_spillmem_p, 0 },
5297 { "spillpsp.p", dot_spillmem_p, 1 },
5298 { "label_state", dot_label_state, 0 },
5299 { "copy_state", dot_copy_state, 0 },
5300 { "unwabi", dot_unwabi, 0 },
5301 { "personality", dot_personality, 0 },
5302 { "mii", dot_template, 0x0 },
5303 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
5304 { "mlx", dot_template, 0x2 },
5305 { "mmi", dot_template, 0x4 },
5306 { "mfi", dot_template, 0x6 },
5307 { "mmf", dot_template, 0x7 },
5308 { "mib", dot_template, 0x8 },
5309 { "mbb", dot_template, 0x9 },
5310 { "bbb", dot_template, 0xb },
5311 { "mmb", dot_template, 0xc },
5312 { "mfb", dot_template, 0xe },
5313 { "align", dot_align, 0 },
5314 { "regstk", dot_regstk, 0 },
5315 { "rotr", dot_rot, DYNREG_GR },
5316 { "rotf", dot_rot, DYNREG_FR },
5317 { "rotp", dot_rot, DYNREG_PR },
5318 { "lsb", dot_byteorder, 0 },
5319 { "msb", dot_byteorder, 1 },
5320 { "psr", dot_psr, 0 },
5321 { "alias", dot_alias, 0 },
5322 { "secalias", dot_alias, 1 },
5323 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
5325 { "xdata1", dot_xdata, 1 },
5326 { "xdata2", dot_xdata, 2 },
5327 { "xdata4", dot_xdata, 4 },
5328 { "xdata8", dot_xdata, 8 },
5329 { "xdata16", dot_xdata, 16 },
5330 { "xreal4", dot_xfloat_cons, 'f' },
5331 { "xreal8", dot_xfloat_cons, 'd' },
5332 { "xreal10", dot_xfloat_cons, 'x' },
5333 { "xreal16", dot_xfloat_cons, 'X' },
5334 { "xstring", dot_xstringer, 0 },
5335 { "xstringz", dot_xstringer, 1 },
5337 /* unaligned versions: */
5338 { "xdata2.ua", dot_xdata_ua, 2 },
5339 { "xdata4.ua", dot_xdata_ua, 4 },
5340 { "xdata8.ua", dot_xdata_ua, 8 },
5341 { "xdata16.ua", dot_xdata_ua, 16 },
5342 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
5343 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
5344 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
5345 { "xreal16.ua", dot_xfloat_cons_ua, 'X' },
5347 /* annotations/DV checking support */
5348 { "entry", dot_entry, 0 },
5349 { "mem.offset", dot_mem_offset, 0 },
5350 { "pred.rel", dot_pred_rel, 0 },
5351 { "pred.rel.clear", dot_pred_rel, 'c' },
5352 { "pred.rel.imply", dot_pred_rel, 'i' },
5353 { "pred.rel.mutex", dot_pred_rel, 'm' },
5354 { "pred.safe_across_calls", dot_pred_rel, 's' },
5355 { "reg.val", dot_reg_val, 0 },
5356 { "serialize.data", dot_serialize, 0 },
5357 { "serialize.instruction", dot_serialize, 1 },
5358 { "auto", dot_dv_mode, 'a' },
5359 { "explicit", dot_dv_mode, 'e' },
5360 { "default", dot_dv_mode, 'd' },
5362 /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work.
5363 IA-64 aligns data allocation pseudo-ops by default, so we have to
5364 tell it that these ones are supposed to be unaligned. Long term,
5365 should rewrite so that only IA-64 specific data allocation pseudo-ops
5366 are aligned by default. */
5367 {"2byte", stmt_cons_ua, 2},
5368 {"4byte", stmt_cons_ua, 4},
5369 {"8byte", stmt_cons_ua, 8},
5371 { NULL, 0, 0 }
5374 static const struct pseudo_opcode
5376 const char *name;
5377 void (*handler) (int);
5378 int arg;
5380 pseudo_opcode[] =
5382 /* these are more like pseudo-ops, but don't start with a dot */
5383 { "data1", cons, 1 },
5384 { "data2", cons, 2 },
5385 { "data4", cons, 4 },
5386 { "data8", cons, 8 },
5387 { "data16", cons, 16 },
5388 { "real4", stmt_float_cons, 'f' },
5389 { "real8", stmt_float_cons, 'd' },
5390 { "real10", stmt_float_cons, 'x' },
5391 { "real16", stmt_float_cons, 'X' },
5392 { "string", stringer, 0 },
5393 { "stringz", stringer, 1 },
5395 /* unaligned versions: */
5396 { "data2.ua", stmt_cons_ua, 2 },
5397 { "data4.ua", stmt_cons_ua, 4 },
5398 { "data8.ua", stmt_cons_ua, 8 },
5399 { "data16.ua", stmt_cons_ua, 16 },
5400 { "real4.ua", float_cons, 'f' },
5401 { "real8.ua", float_cons, 'd' },
5402 { "real10.ua", float_cons, 'x' },
5403 { "real16.ua", float_cons, 'X' },
5406 /* Declare a register by creating a symbol for it and entering it in
5407 the symbol table. */
5409 static symbolS *
5410 declare_register (name, regnum)
5411 const char *name;
5412 int regnum;
5414 const char *err;
5415 symbolS *sym;
5417 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
5419 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
5420 if (err)
5421 as_fatal ("Inserting \"%s\" into register table failed: %s",
5422 name, err);
5424 return sym;
5427 static void
5428 declare_register_set (prefix, num_regs, base_regnum)
5429 const char *prefix;
5430 int num_regs;
5431 int base_regnum;
5433 char name[8];
5434 int i;
5436 for (i = 0; i < num_regs; ++i)
5438 sprintf (name, "%s%u", prefix, i);
5439 declare_register (name, base_regnum + i);
5443 static unsigned int
5444 operand_width (opnd)
5445 enum ia64_opnd opnd;
5447 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
5448 unsigned int bits = 0;
5449 int i;
5451 bits = 0;
5452 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
5453 bits += odesc->field[i].bits;
5455 return bits;
5458 static enum operand_match_result
5459 operand_match (idesc, index, e)
5460 const struct ia64_opcode *idesc;
5461 int index;
5462 expressionS *e;
5464 enum ia64_opnd opnd = idesc->operands[index];
5465 int bits, relocatable = 0;
5466 struct insn_fix *fix;
5467 bfd_signed_vma val;
5469 switch (opnd)
5471 /* constants: */
5473 case IA64_OPND_AR_CCV:
5474 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
5475 return OPERAND_MATCH;
5476 break;
5478 case IA64_OPND_AR_CSD:
5479 if (e->X_op == O_register && e->X_add_number == REG_AR + 25)
5480 return OPERAND_MATCH;
5481 break;
5483 case IA64_OPND_AR_PFS:
5484 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
5485 return OPERAND_MATCH;
5486 break;
5488 case IA64_OPND_GR0:
5489 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
5490 return OPERAND_MATCH;
5491 break;
5493 case IA64_OPND_IP:
5494 if (e->X_op == O_register && e->X_add_number == REG_IP)
5495 return OPERAND_MATCH;
5496 break;
5498 case IA64_OPND_PR:
5499 if (e->X_op == O_register && e->X_add_number == REG_PR)
5500 return OPERAND_MATCH;
5501 break;
5503 case IA64_OPND_PR_ROT:
5504 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
5505 return OPERAND_MATCH;
5506 break;
5508 case IA64_OPND_PSR:
5509 if (e->X_op == O_register && e->X_add_number == REG_PSR)
5510 return OPERAND_MATCH;
5511 break;
5513 case IA64_OPND_PSR_L:
5514 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
5515 return OPERAND_MATCH;
5516 break;
5518 case IA64_OPND_PSR_UM:
5519 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
5520 return OPERAND_MATCH;
5521 break;
5523 case IA64_OPND_C1:
5524 if (e->X_op == O_constant)
5526 if (e->X_add_number == 1)
5527 return OPERAND_MATCH;
5528 else
5529 return OPERAND_OUT_OF_RANGE;
5531 break;
5533 case IA64_OPND_C8:
5534 if (e->X_op == O_constant)
5536 if (e->X_add_number == 8)
5537 return OPERAND_MATCH;
5538 else
5539 return OPERAND_OUT_OF_RANGE;
5541 break;
5543 case IA64_OPND_C16:
5544 if (e->X_op == O_constant)
5546 if (e->X_add_number == 16)
5547 return OPERAND_MATCH;
5548 else
5549 return OPERAND_OUT_OF_RANGE;
5551 break;
5553 /* register operands: */
5555 case IA64_OPND_AR3:
5556 if (e->X_op == O_register && e->X_add_number >= REG_AR
5557 && e->X_add_number < REG_AR + 128)
5558 return OPERAND_MATCH;
5559 break;
5561 case IA64_OPND_B1:
5562 case IA64_OPND_B2:
5563 if (e->X_op == O_register && e->X_add_number >= REG_BR
5564 && e->X_add_number < REG_BR + 8)
5565 return OPERAND_MATCH;
5566 break;
5568 case IA64_OPND_CR3:
5569 if (e->X_op == O_register && e->X_add_number >= REG_CR
5570 && e->X_add_number < REG_CR + 128)
5571 return OPERAND_MATCH;
5572 break;
5574 case IA64_OPND_F1:
5575 case IA64_OPND_F2:
5576 case IA64_OPND_F3:
5577 case IA64_OPND_F4:
5578 if (e->X_op == O_register && e->X_add_number >= REG_FR
5579 && e->X_add_number < REG_FR + 128)
5580 return OPERAND_MATCH;
5581 break;
5583 case IA64_OPND_P1:
5584 case IA64_OPND_P2:
5585 if (e->X_op == O_register && e->X_add_number >= REG_P
5586 && e->X_add_number < REG_P + 64)
5587 return OPERAND_MATCH;
5588 break;
5590 case IA64_OPND_R1:
5591 case IA64_OPND_R2:
5592 case IA64_OPND_R3:
5593 if (e->X_op == O_register && e->X_add_number >= REG_GR
5594 && e->X_add_number < REG_GR + 128)
5595 return OPERAND_MATCH;
5596 break;
5598 case IA64_OPND_R3_2:
5599 if (e->X_op == O_register && e->X_add_number >= REG_GR)
5601 if (e->X_add_number < REG_GR + 4)
5602 return OPERAND_MATCH;
5603 else if (e->X_add_number < REG_GR + 128)
5604 return OPERAND_OUT_OF_RANGE;
5606 break;
5608 /* indirect operands: */
5609 case IA64_OPND_CPUID_R3:
5610 case IA64_OPND_DBR_R3:
5611 case IA64_OPND_DTR_R3:
5612 case IA64_OPND_ITR_R3:
5613 case IA64_OPND_IBR_R3:
5614 case IA64_OPND_MSR_R3:
5615 case IA64_OPND_PKR_R3:
5616 case IA64_OPND_PMC_R3:
5617 case IA64_OPND_PMD_R3:
5618 case IA64_OPND_RR_R3:
5619 if (e->X_op == O_index && e->X_op_symbol
5620 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
5621 == opnd - IA64_OPND_CPUID_R3))
5622 return OPERAND_MATCH;
5623 break;
5625 case IA64_OPND_MR3:
5626 if (e->X_op == O_index && !e->X_op_symbol)
5627 return OPERAND_MATCH;
5628 break;
5630 /* immediate operands: */
5631 case IA64_OPND_CNT2a:
5632 case IA64_OPND_LEN4:
5633 case IA64_OPND_LEN6:
5634 bits = operand_width (idesc->operands[index]);
5635 if (e->X_op == O_constant)
5637 if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
5638 return OPERAND_MATCH;
5639 else
5640 return OPERAND_OUT_OF_RANGE;
5642 break;
5644 case IA64_OPND_CNT2b:
5645 if (e->X_op == O_constant)
5647 if ((bfd_vma) (e->X_add_number - 1) < 3)
5648 return OPERAND_MATCH;
5649 else
5650 return OPERAND_OUT_OF_RANGE;
5652 break;
5654 case IA64_OPND_CNT2c:
5655 val = e->X_add_number;
5656 if (e->X_op == O_constant)
5658 if ((val == 0 || val == 7 || val == 15 || val == 16))
5659 return OPERAND_MATCH;
5660 else
5661 return OPERAND_OUT_OF_RANGE;
5663 break;
5665 case IA64_OPND_SOR:
5666 /* SOR must be an integer multiple of 8 */
5667 if (e->X_op == O_constant && e->X_add_number & 0x7)
5668 return OPERAND_OUT_OF_RANGE;
5669 case IA64_OPND_SOF:
5670 case IA64_OPND_SOL:
5671 if (e->X_op == O_constant)
5673 if ((bfd_vma) e->X_add_number <= 96)
5674 return OPERAND_MATCH;
5675 else
5676 return OPERAND_OUT_OF_RANGE;
5678 break;
5680 case IA64_OPND_IMMU62:
5681 if (e->X_op == O_constant)
5683 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
5684 return OPERAND_MATCH;
5685 else
5686 return OPERAND_OUT_OF_RANGE;
5688 else
5690 /* FIXME -- need 62-bit relocation type */
5691 as_bad (_("62-bit relocation not yet implemented"));
5693 break;
5695 case IA64_OPND_IMMU64:
5696 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
5697 || e->X_op == O_subtract)
5699 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5700 fix->code = BFD_RELOC_IA64_IMM64;
5701 if (e->X_op != O_subtract)
5703 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5704 if (e->X_op == O_pseudo_fixup)
5705 e->X_op = O_symbol;
5708 fix->opnd = idesc->operands[index];
5709 fix->expr = *e;
5710 fix->is_pcrel = 0;
5711 ++CURR_SLOT.num_fixups;
5712 return OPERAND_MATCH;
5714 else if (e->X_op == O_constant)
5715 return OPERAND_MATCH;
5716 break;
5718 case IA64_OPND_CCNT5:
5719 case IA64_OPND_CNT5:
5720 case IA64_OPND_CNT6:
5721 case IA64_OPND_CPOS6a:
5722 case IA64_OPND_CPOS6b:
5723 case IA64_OPND_CPOS6c:
5724 case IA64_OPND_IMMU2:
5725 case IA64_OPND_IMMU7a:
5726 case IA64_OPND_IMMU7b:
5727 case IA64_OPND_IMMU21:
5728 case IA64_OPND_IMMU24:
5729 case IA64_OPND_MBTYPE4:
5730 case IA64_OPND_MHTYPE8:
5731 case IA64_OPND_POS6:
5732 bits = operand_width (idesc->operands[index]);
5733 if (e->X_op == O_constant)
5735 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5736 return OPERAND_MATCH;
5737 else
5738 return OPERAND_OUT_OF_RANGE;
5740 break;
5742 case IA64_OPND_IMMU9:
5743 bits = operand_width (idesc->operands[index]);
5744 if (e->X_op == O_constant)
5746 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
5748 int lobits = e->X_add_number & 0x3;
5749 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
5750 e->X_add_number |= (bfd_vma) 0x3;
5751 return OPERAND_MATCH;
5753 else
5754 return OPERAND_OUT_OF_RANGE;
5756 break;
5758 case IA64_OPND_IMM44:
5759 /* least 16 bits must be zero */
5760 if ((e->X_add_number & 0xffff) != 0)
5761 /* XXX technically, this is wrong: we should not be issuing warning
5762 messages until we're sure this instruction pattern is going to
5763 be used! */
5764 as_warn (_("lower 16 bits of mask ignored"));
5766 if (e->X_op == O_constant)
5768 if (((e->X_add_number >= 0
5769 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44))
5770 || (e->X_add_number < 0
5771 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44))))
5773 /* sign-extend */
5774 if (e->X_add_number >= 0
5775 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
5777 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
5779 return OPERAND_MATCH;
5781 else
5782 return OPERAND_OUT_OF_RANGE;
5784 break;
5786 case IA64_OPND_IMM17:
5787 /* bit 0 is a don't care (pr0 is hardwired to 1) */
5788 if (e->X_op == O_constant)
5790 if (((e->X_add_number >= 0
5791 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17))
5792 || (e->X_add_number < 0
5793 && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17))))
5795 /* sign-extend */
5796 if (e->X_add_number >= 0
5797 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
5799 e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1);
5801 return OPERAND_MATCH;
5803 else
5804 return OPERAND_OUT_OF_RANGE;
5806 break;
5808 case IA64_OPND_IMM14:
5809 case IA64_OPND_IMM22:
5810 relocatable = 1;
5811 case IA64_OPND_IMM1:
5812 case IA64_OPND_IMM8:
5813 case IA64_OPND_IMM8U4:
5814 case IA64_OPND_IMM8M1:
5815 case IA64_OPND_IMM8M1U4:
5816 case IA64_OPND_IMM8M1U8:
5817 case IA64_OPND_IMM9a:
5818 case IA64_OPND_IMM9b:
5819 bits = operand_width (idesc->operands[index]);
5820 if (relocatable && (e->X_op == O_symbol
5821 || e->X_op == O_subtract
5822 || e->X_op == O_pseudo_fixup))
5824 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5826 if (idesc->operands[index] == IA64_OPND_IMM14)
5827 fix->code = BFD_RELOC_IA64_IMM14;
5828 else
5829 fix->code = BFD_RELOC_IA64_IMM22;
5831 if (e->X_op != O_subtract)
5833 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5834 if (e->X_op == O_pseudo_fixup)
5835 e->X_op = O_symbol;
5838 fix->opnd = idesc->operands[index];
5839 fix->expr = *e;
5840 fix->is_pcrel = 0;
5841 ++CURR_SLOT.num_fixups;
5842 return OPERAND_MATCH;
5844 else if (e->X_op != O_constant
5845 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
5846 return OPERAND_MISMATCH;
5848 if (opnd == IA64_OPND_IMM8M1U4)
5850 /* Zero is not valid for unsigned compares that take an adjusted
5851 constant immediate range. */
5852 if (e->X_add_number == 0)
5853 return OPERAND_OUT_OF_RANGE;
5855 /* Sign-extend 32-bit unsigned numbers, so that the following range
5856 checks will work. */
5857 val = e->X_add_number;
5858 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5859 && ((val & ((bfd_vma) 1 << 31)) != 0))
5860 val = ((val << 32) >> 32);
5862 /* Check for 0x100000000. This is valid because
5863 0x100000000-1 is the same as ((uint32_t) -1). */
5864 if (val == ((bfd_signed_vma) 1 << 32))
5865 return OPERAND_MATCH;
5867 val = val - 1;
5869 else if (opnd == IA64_OPND_IMM8M1U8)
5871 /* Zero is not valid for unsigned compares that take an adjusted
5872 constant immediate range. */
5873 if (e->X_add_number == 0)
5874 return OPERAND_OUT_OF_RANGE;
5876 /* Check for 0x10000000000000000. */
5877 if (e->X_op == O_big)
5879 if (generic_bignum[0] == 0
5880 && generic_bignum[1] == 0
5881 && generic_bignum[2] == 0
5882 && generic_bignum[3] == 0
5883 && generic_bignum[4] == 1)
5884 return OPERAND_MATCH;
5885 else
5886 return OPERAND_OUT_OF_RANGE;
5888 else
5889 val = e->X_add_number - 1;
5891 else if (opnd == IA64_OPND_IMM8M1)
5892 val = e->X_add_number - 1;
5893 else if (opnd == IA64_OPND_IMM8U4)
5895 /* Sign-extend 32-bit unsigned numbers, so that the following range
5896 checks will work. */
5897 val = e->X_add_number;
5898 if (((val & (~(bfd_vma) 0 << 32)) == 0)
5899 && ((val & ((bfd_vma) 1 << 31)) != 0))
5900 val = ((val << 32) >> 32);
5902 else
5903 val = e->X_add_number;
5905 if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1)))
5906 || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1))))
5907 return OPERAND_MATCH;
5908 else
5909 return OPERAND_OUT_OF_RANGE;
5911 case IA64_OPND_INC3:
5912 /* +/- 1, 4, 8, 16 */
5913 val = e->X_add_number;
5914 if (val < 0)
5915 val = -val;
5916 if (e->X_op == O_constant)
5918 if ((val == 1 || val == 4 || val == 8 || val == 16))
5919 return OPERAND_MATCH;
5920 else
5921 return OPERAND_OUT_OF_RANGE;
5923 break;
5925 case IA64_OPND_TGT25:
5926 case IA64_OPND_TGT25b:
5927 case IA64_OPND_TGT25c:
5928 case IA64_OPND_TGT64:
5929 if (e->X_op == O_symbol)
5931 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5932 if (opnd == IA64_OPND_TGT25)
5933 fix->code = BFD_RELOC_IA64_PCREL21F;
5934 else if (opnd == IA64_OPND_TGT25b)
5935 fix->code = BFD_RELOC_IA64_PCREL21M;
5936 else if (opnd == IA64_OPND_TGT25c)
5937 fix->code = BFD_RELOC_IA64_PCREL21B;
5938 else if (opnd == IA64_OPND_TGT64)
5939 fix->code = BFD_RELOC_IA64_PCREL60B;
5940 else
5941 abort ();
5943 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5944 fix->opnd = idesc->operands[index];
5945 fix->expr = *e;
5946 fix->is_pcrel = 1;
5947 ++CURR_SLOT.num_fixups;
5948 return OPERAND_MATCH;
5950 case IA64_OPND_TAG13:
5951 case IA64_OPND_TAG13b:
5952 switch (e->X_op)
5954 case O_constant:
5955 return OPERAND_MATCH;
5957 case O_symbol:
5958 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5959 /* There are no external relocs for TAG13/TAG13b fields, so we
5960 create a dummy reloc. This will not live past md_apply_fix3. */
5961 fix->code = BFD_RELOC_UNUSED;
5962 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
5963 fix->opnd = idesc->operands[index];
5964 fix->expr = *e;
5965 fix->is_pcrel = 1;
5966 ++CURR_SLOT.num_fixups;
5967 return OPERAND_MATCH;
5969 default:
5970 break;
5972 break;
5974 case IA64_OPND_LDXMOV:
5975 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
5976 fix->code = BFD_RELOC_IA64_LDXMOV;
5977 fix->opnd = idesc->operands[index];
5978 fix->expr = *e;
5979 fix->is_pcrel = 0;
5980 ++CURR_SLOT.num_fixups;
5981 return OPERAND_MATCH;
5983 default:
5984 break;
5986 return OPERAND_MISMATCH;
5989 static int
5990 parse_operand (e)
5991 expressionS *e;
5993 int sep = '\0';
5995 memset (e, 0, sizeof (*e));
5996 e->X_op = O_absent;
5997 SKIP_WHITESPACE ();
5998 if (*input_line_pointer != '}')
5999 expression (e);
6000 sep = *input_line_pointer++;
6002 if (sep == '}')
6004 if (!md.manual_bundling)
6005 as_warn ("Found '}' when manual bundling is off");
6006 else
6007 CURR_SLOT.manual_bundling_off = 1;
6008 md.manual_bundling = 0;
6009 sep = '\0';
6011 return sep;
6014 /* Returns the next entry in the opcode table that matches the one in
6015 IDESC, and frees the entry in IDESC. If no matching entry is
6016 found, NULL is returned instead. */
6018 static struct ia64_opcode *
6019 get_next_opcode (struct ia64_opcode *idesc)
6021 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
6022 ia64_free_opcode (idesc);
6023 return next;
6026 /* Parse the operands for the opcode and find the opcode variant that
6027 matches the specified operands, or NULL if no match is possible. */
6029 static struct ia64_opcode *
6030 parse_operands (idesc)
6031 struct ia64_opcode *idesc;
6033 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
6034 int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0;
6035 int reg1, reg2;
6036 char reg_class;
6037 enum ia64_opnd expected_operand = IA64_OPND_NIL;
6038 enum operand_match_result result;
6039 char mnemonic[129];
6040 char *first_arg = 0, *end, *saved_input_pointer;
6041 unsigned int sof;
6043 assert (strlen (idesc->name) <= 128);
6045 strcpy (mnemonic, idesc->name);
6046 if (idesc->operands[2] == IA64_OPND_SOF
6047 || idesc->operands[1] == IA64_OPND_SOF)
6049 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
6050 can't parse the first operand until we have parsed the
6051 remaining operands of the "alloc" instruction. */
6052 SKIP_WHITESPACE ();
6053 first_arg = input_line_pointer;
6054 end = strchr (input_line_pointer, '=');
6055 if (!end)
6057 as_bad ("Expected separator `='");
6058 return 0;
6060 input_line_pointer = end + 1;
6061 ++i;
6062 ++num_outputs;
6065 for (; ; ++i)
6067 if (i < NELEMS (CURR_SLOT.opnd))
6069 sep = parse_operand (CURR_SLOT.opnd + i);
6070 if (CURR_SLOT.opnd[i].X_op == O_absent)
6071 break;
6073 else
6075 expressionS dummy;
6077 sep = parse_operand (&dummy);
6078 if (dummy.X_op == O_absent)
6079 break;
6082 ++num_operands;
6084 if (sep != '=' && sep != ',')
6085 break;
6087 if (sep == '=')
6089 if (num_outputs > 0)
6090 as_bad ("Duplicate equal sign (=) in instruction");
6091 else
6092 num_outputs = i + 1;
6095 if (sep != '\0')
6097 as_bad ("Illegal operand separator `%c'", sep);
6098 return 0;
6101 if (idesc->operands[2] == IA64_OPND_SOF
6102 || idesc->operands[1] == IA64_OPND_SOF)
6104 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
6105 know (strcmp (idesc->name, "alloc") == 0);
6106 i = (CURR_SLOT.opnd[1].X_op == O_register
6107 && CURR_SLOT.opnd[1].X_add_number == REG_AR + AR_PFS) ? 2 : 1;
6108 if (num_operands == i + 3 /* first_arg not included in this count! */
6109 && CURR_SLOT.opnd[i].X_op == O_constant
6110 && CURR_SLOT.opnd[i + 1].X_op == O_constant
6111 && CURR_SLOT.opnd[i + 2].X_op == O_constant
6112 && CURR_SLOT.opnd[i + 3].X_op == O_constant)
6114 sof = set_regstack (CURR_SLOT.opnd[i].X_add_number,
6115 CURR_SLOT.opnd[i + 1].X_add_number,
6116 CURR_SLOT.opnd[i + 2].X_add_number,
6117 CURR_SLOT.opnd[i + 3].X_add_number);
6119 /* now we can parse the first arg: */
6120 saved_input_pointer = input_line_pointer;
6121 input_line_pointer = first_arg;
6122 sep = parse_operand (CURR_SLOT.opnd + 0);
6123 if (sep != '=')
6124 --num_outputs; /* force error */
6125 input_line_pointer = saved_input_pointer;
6127 CURR_SLOT.opnd[i].X_add_number = sof;
6128 CURR_SLOT.opnd[i + 1].X_add_number
6129 = sof - CURR_SLOT.opnd[i + 2].X_add_number;
6130 CURR_SLOT.opnd[i + 2] = CURR_SLOT.opnd[i + 3];
6134 highest_unmatched_operand = -4;
6135 curr_out_of_range_pos = -1;
6136 error_pos = 0;
6137 for (; idesc; idesc = get_next_opcode (idesc))
6139 if (num_outputs != idesc->num_outputs)
6140 continue; /* mismatch in # of outputs */
6141 if (highest_unmatched_operand < 0)
6142 highest_unmatched_operand |= 1;
6143 if (num_operands > NELEMS (idesc->operands)
6144 || (num_operands < NELEMS (idesc->operands)
6145 && idesc->operands[num_operands])
6146 || (num_operands > 0 && !idesc->operands[num_operands - 1]))
6147 continue; /* mismatch in number of arguments */
6148 if (highest_unmatched_operand < 0)
6149 highest_unmatched_operand |= 2;
6151 CURR_SLOT.num_fixups = 0;
6153 /* Try to match all operands. If we see an out-of-range operand,
6154 then continue trying to match the rest of the operands, since if
6155 the rest match, then this idesc will give the best error message. */
6157 out_of_range_pos = -1;
6158 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
6160 result = operand_match (idesc, i, CURR_SLOT.opnd + i);
6161 if (result != OPERAND_MATCH)
6163 if (result != OPERAND_OUT_OF_RANGE)
6164 break;
6165 if (out_of_range_pos < 0)
6166 /* remember position of the first out-of-range operand: */
6167 out_of_range_pos = i;
6171 /* If we did not match all operands, or if at least one operand was
6172 out-of-range, then this idesc does not match. Keep track of which
6173 idesc matched the most operands before failing. If we have two
6174 idescs that failed at the same position, and one had an out-of-range
6175 operand, then prefer the out-of-range operand. Thus if we have
6176 "add r0=0x1000000,r1" we get an error saying the constant is out
6177 of range instead of an error saying that the constant should have been
6178 a register. */
6180 if (i != num_operands || out_of_range_pos >= 0)
6182 if (i > highest_unmatched_operand
6183 || (i == highest_unmatched_operand
6184 && out_of_range_pos > curr_out_of_range_pos))
6186 highest_unmatched_operand = i;
6187 if (out_of_range_pos >= 0)
6189 expected_operand = idesc->operands[out_of_range_pos];
6190 error_pos = out_of_range_pos;
6192 else
6194 expected_operand = idesc->operands[i];
6195 error_pos = i;
6197 curr_out_of_range_pos = out_of_range_pos;
6199 continue;
6202 break;
6204 if (!idesc)
6206 if (expected_operand)
6207 as_bad ("Operand %u of `%s' should be %s",
6208 error_pos + 1, mnemonic,
6209 elf64_ia64_operands[expected_operand].desc);
6210 else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 1))
6211 as_bad ("Wrong number of output operands");
6212 else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 2))
6213 as_bad ("Wrong number of input operands");
6214 else
6215 as_bad ("Operand mismatch");
6216 return 0;
6219 /* Check that the instruction doesn't use
6220 - r0, f0, or f1 as output operands
6221 - the same predicate twice as output operands
6222 - r0 as address of a base update load or store
6223 - the same GR as output and address of a base update load
6224 - two even- or two odd-numbered FRs as output operands of a floating
6225 point parallel load.
6226 At most two (conflicting) output (or output-like) operands can exist,
6227 (floating point parallel loads have three outputs, but the base register,
6228 if updated, cannot conflict with the actual outputs). */
6229 reg2 = reg1 = -1;
6230 for (i = 0; i < num_operands; ++i)
6232 int regno = 0;
6234 reg_class = 0;
6235 switch (idesc->operands[i])
6237 case IA64_OPND_R1:
6238 case IA64_OPND_R2:
6239 case IA64_OPND_R3:
6240 if (i < num_outputs)
6242 if (CURR_SLOT.opnd[i].X_add_number == REG_GR)
6243 reg_class = 'r';
6244 else if (reg1 < 0)
6245 reg1 = CURR_SLOT.opnd[i].X_add_number;
6246 else if (reg2 < 0)
6247 reg2 = CURR_SLOT.opnd[i].X_add_number;
6249 break;
6250 case IA64_OPND_P1:
6251 case IA64_OPND_P2:
6252 if (i < num_outputs)
6254 if (reg1 < 0)
6255 reg1 = CURR_SLOT.opnd[i].X_add_number;
6256 else if (reg2 < 0)
6257 reg2 = CURR_SLOT.opnd[i].X_add_number;
6259 break;
6260 case IA64_OPND_F1:
6261 case IA64_OPND_F2:
6262 case IA64_OPND_F3:
6263 case IA64_OPND_F4:
6264 if (i < num_outputs)
6266 if (CURR_SLOT.opnd[i].X_add_number >= REG_FR
6267 && CURR_SLOT.opnd[i].X_add_number <= REG_FR + 1)
6269 reg_class = 'f';
6270 regno = CURR_SLOT.opnd[i].X_add_number - REG_FR;
6272 else if (reg1 < 0)
6273 reg1 = CURR_SLOT.opnd[i].X_add_number;
6274 else if (reg2 < 0)
6275 reg2 = CURR_SLOT.opnd[i].X_add_number;
6277 break;
6278 case IA64_OPND_MR3:
6279 if (idesc->flags & IA64_OPCODE_POSTINC)
6281 if (CURR_SLOT.opnd[i].X_add_number == REG_GR)
6282 reg_class = 'm';
6283 else if (reg1 < 0)
6284 reg1 = CURR_SLOT.opnd[i].X_add_number;
6285 else if (reg2 < 0)
6286 reg2 = CURR_SLOT.opnd[i].X_add_number;
6288 break;
6289 default:
6290 break;
6292 switch (reg_class)
6294 case 0:
6295 break;
6296 default:
6297 as_warn ("Invalid use of `%c%d' as output operand", reg_class, regno);
6298 break;
6299 case 'm':
6300 as_warn ("Invalid use of `r%d' as base update address operand", regno);
6301 break;
6304 if (reg1 == reg2)
6306 if (reg1 >= REG_GR && reg1 <= REG_GR + 127)
6308 reg1 -= REG_GR;
6309 reg_class = 'r';
6311 else if (reg1 >= REG_P && reg1 <= REG_P + 63)
6313 reg1 -= REG_P;
6314 reg_class = 'p';
6316 else if (reg1 >= REG_FR && reg1 <= REG_FR + 127)
6318 reg1 -= REG_FR;
6319 reg_class = 'f';
6321 else
6322 reg_class = 0;
6323 if (reg_class)
6324 as_warn ("Invalid duplicate use of `%c%d'", reg_class, reg1);
6326 else if (((reg1 >= REG_FR && reg1 <= REG_FR + 31
6327 && reg2 >= REG_FR && reg2 <= REG_FR + 31)
6328 || (reg1 >= REG_FR + 32 && reg1 <= REG_FR + 127
6329 && reg2 >= REG_FR + 32 && reg2 <= REG_FR + 127))
6330 && ! ((reg1 ^ reg2) & 1))
6331 as_warn ("Invalid simultaneous use of `f%d' and `f%d'",
6332 reg1 - REG_FR, reg2 - REG_FR);
6333 else if ((reg1 >= REG_FR && reg1 <= REG_FR + 31
6334 && reg2 >= REG_FR + 32 && reg2 <= REG_FR + 127)
6335 || (reg1 >= REG_FR + 32 && reg1 <= REG_FR + 127
6336 && reg2 >= REG_FR && reg2 <= REG_FR + 31))
6337 as_warn ("Dangerous simultaneous use of `f%d' and `f%d'",
6338 reg1 - REG_FR, reg2 - REG_FR);
6339 return idesc;
6342 static void
6343 build_insn (slot, insnp)
6344 struct slot *slot;
6345 bfd_vma *insnp;
6347 const struct ia64_operand *odesc, *o2desc;
6348 struct ia64_opcode *idesc = slot->idesc;
6349 bfd_vma insn;
6350 bfd_signed_vma val;
6351 const char *err;
6352 int i;
6354 insn = idesc->opcode | slot->qp_regno;
6356 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
6358 if (slot->opnd[i].X_op == O_register
6359 || slot->opnd[i].X_op == O_constant
6360 || slot->opnd[i].X_op == O_index)
6361 val = slot->opnd[i].X_add_number;
6362 else if (slot->opnd[i].X_op == O_big)
6364 /* This must be the value 0x10000000000000000. */
6365 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
6366 val = 0;
6368 else
6369 val = 0;
6371 switch (idesc->operands[i])
6373 case IA64_OPND_IMMU64:
6374 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
6375 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
6376 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
6377 | (((val >> 63) & 0x1) << 36));
6378 continue;
6380 case IA64_OPND_IMMU62:
6381 val &= 0x3fffffffffffffffULL;
6382 if (val != slot->opnd[i].X_add_number)
6383 as_warn (_("Value truncated to 62 bits"));
6384 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
6385 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
6386 continue;
6388 case IA64_OPND_TGT64:
6389 val >>= 4;
6390 *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2;
6391 insn |= ((((val >> 59) & 0x1) << 36)
6392 | (((val >> 0) & 0xfffff) << 13));
6393 continue;
6395 case IA64_OPND_AR3:
6396 val -= REG_AR;
6397 break;
6399 case IA64_OPND_B1:
6400 case IA64_OPND_B2:
6401 val -= REG_BR;
6402 break;
6404 case IA64_OPND_CR3:
6405 val -= REG_CR;
6406 break;
6408 case IA64_OPND_F1:
6409 case IA64_OPND_F2:
6410 case IA64_OPND_F3:
6411 case IA64_OPND_F4:
6412 val -= REG_FR;
6413 break;
6415 case IA64_OPND_P1:
6416 case IA64_OPND_P2:
6417 val -= REG_P;
6418 break;
6420 case IA64_OPND_R1:
6421 case IA64_OPND_R2:
6422 case IA64_OPND_R3:
6423 case IA64_OPND_R3_2:
6424 case IA64_OPND_CPUID_R3:
6425 case IA64_OPND_DBR_R3:
6426 case IA64_OPND_DTR_R3:
6427 case IA64_OPND_ITR_R3:
6428 case IA64_OPND_IBR_R3:
6429 case IA64_OPND_MR3:
6430 case IA64_OPND_MSR_R3:
6431 case IA64_OPND_PKR_R3:
6432 case IA64_OPND_PMC_R3:
6433 case IA64_OPND_PMD_R3:
6434 case IA64_OPND_RR_R3:
6435 val -= REG_GR;
6436 break;
6438 default:
6439 break;
6442 odesc = elf64_ia64_operands + idesc->operands[i];
6443 err = (*odesc->insert) (odesc, val, &insn);
6444 if (err)
6445 as_bad_where (slot->src_file, slot->src_line,
6446 "Bad operand value: %s", err);
6447 if (idesc->flags & IA64_OPCODE_PSEUDO)
6449 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
6450 && odesc == elf64_ia64_operands + IA64_OPND_F3)
6452 o2desc = elf64_ia64_operands + IA64_OPND_F2;
6453 (*o2desc->insert) (o2desc, val, &insn);
6455 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
6456 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
6457 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
6459 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
6460 (*o2desc->insert) (o2desc, 64 - val, &insn);
6464 *insnp = insn;
6467 static void
6468 emit_one_bundle ()
6470 int manual_bundling_off = 0, manual_bundling = 0;
6471 enum ia64_unit required_unit, insn_unit = 0;
6472 enum ia64_insn_type type[3], insn_type;
6473 unsigned int template, orig_template;
6474 bfd_vma insn[3] = { -1, -1, -1 };
6475 struct ia64_opcode *idesc;
6476 int end_of_insn_group = 0, user_template = -1;
6477 int n, i, j, first, curr, last_slot;
6478 unw_rec_list *ptr, *last_ptr, *end_ptr;
6479 bfd_vma t0 = 0, t1 = 0;
6480 struct label_fix *lfix;
6481 struct insn_fix *ifix;
6482 char mnemonic[16];
6483 fixS *fix;
6484 char *f;
6485 int addr_mod;
6487 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
6488 know (first >= 0 & first < NUM_SLOTS);
6489 n = MIN (3, md.num_slots_in_use);
6491 /* Determine template: user user_template if specified, best match
6492 otherwise: */
6494 if (md.slot[first].user_template >= 0)
6495 user_template = template = md.slot[first].user_template;
6496 else
6498 /* Auto select appropriate template. */
6499 memset (type, 0, sizeof (type));
6500 curr = first;
6501 for (i = 0; i < n; ++i)
6503 if (md.slot[curr].label_fixups && i != 0)
6504 break;
6505 type[i] = md.slot[curr].idesc->type;
6506 curr = (curr + 1) % NUM_SLOTS;
6508 template = best_template[type[0]][type[1]][type[2]];
6511 /* initialize instructions with appropriate nops: */
6512 for (i = 0; i < 3; ++i)
6513 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
6515 f = frag_more (16);
6517 /* Check to see if this bundle is at an offset that is a multiple of 16-bytes
6518 from the start of the frag. */
6519 addr_mod = frag_now_fix () & 15;
6520 if (frag_now->has_code && frag_now->insn_addr != addr_mod)
6521 as_bad (_("instruction address is not a multiple of 16"));
6522 frag_now->insn_addr = addr_mod;
6523 frag_now->has_code = 1;
6525 /* now fill in slots with as many insns as possible: */
6526 curr = first;
6527 idesc = md.slot[curr].idesc;
6528 end_of_insn_group = 0;
6529 last_slot = -1;
6530 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
6532 /* If we have unwind records, we may need to update some now. */
6533 ptr = md.slot[curr].unwind_record;
6534 if (ptr)
6536 /* Find the last prologue/body record in the list for the current
6537 insn, and set the slot number for all records up to that point.
6538 This needs to be done now, because prologue/body records refer to
6539 the current point, not the point after the instruction has been
6540 issued. This matters because there may have been nops emitted
6541 meanwhile. Any non-prologue non-body record followed by a
6542 prologue/body record must also refer to the current point. */
6543 last_ptr = NULL;
6544 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6545 for (; ptr != end_ptr; ptr = ptr->next)
6546 if (ptr->r.type == prologue || ptr->r.type == prologue_gr
6547 || ptr->r.type == body)
6548 last_ptr = ptr;
6549 if (last_ptr)
6551 /* Make last_ptr point one after the last prologue/body
6552 record. */
6553 last_ptr = last_ptr->next;
6554 for (ptr = md.slot[curr].unwind_record; ptr != last_ptr;
6555 ptr = ptr->next)
6557 ptr->slot_number = (unsigned long) f + i;
6558 ptr->slot_frag = frag_now;
6560 /* Remove the initialized records, so that we won't accidentally
6561 update them again if we insert a nop and continue. */
6562 md.slot[curr].unwind_record = last_ptr;
6566 manual_bundling_off = md.slot[curr].manual_bundling_off;
6567 if (md.slot[curr].manual_bundling_on)
6569 if (curr == first)
6570 manual_bundling = 1;
6571 else
6572 break; /* Need to start a new bundle. */
6575 /* If this instruction specifies a template, then it must be the first
6576 instruction of a bundle. */
6577 if (curr != first && md.slot[curr].user_template >= 0)
6578 break;
6580 if (idesc->flags & IA64_OPCODE_SLOT2)
6582 if (manual_bundling && !manual_bundling_off)
6584 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6585 "`%s' must be last in bundle", idesc->name);
6586 if (i < 2)
6587 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6589 i = 2;
6591 if (idesc->flags & IA64_OPCODE_LAST)
6593 int required_slot;
6594 unsigned int required_template;
6596 /* If we need a stop bit after an M slot, our only choice is
6597 template 5 (M;;MI). If we need a stop bit after a B
6598 slot, our only choice is to place it at the end of the
6599 bundle, because the only available templates are MIB,
6600 MBB, BBB, MMB, and MFB. We don't handle anything other
6601 than M and B slots because these are the only kind of
6602 instructions that can have the IA64_OPCODE_LAST bit set. */
6603 required_template = template;
6604 switch (idesc->type)
6606 case IA64_TYPE_M:
6607 required_slot = 0;
6608 required_template = 5;
6609 break;
6611 case IA64_TYPE_B:
6612 required_slot = 2;
6613 break;
6615 default:
6616 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6617 "Internal error: don't know how to force %s to end"
6618 "of instruction group", idesc->name);
6619 required_slot = i;
6620 break;
6622 if (manual_bundling
6623 && (i > required_slot
6624 || (required_slot == 2 && !manual_bundling_off)
6625 || (user_template >= 0
6626 /* Changing from MMI to M;MI is OK. */
6627 && (template ^ required_template) > 1)))
6629 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6630 "`%s' must be last in instruction group",
6631 idesc->name);
6632 if (i < 2 && required_slot == 2 && !manual_bundling_off)
6633 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6635 if (required_slot < i)
6636 /* Can't fit this instruction. */
6637 break;
6639 i = required_slot;
6640 if (required_template != template)
6642 /* If we switch the template, we need to reset the NOPs
6643 after slot i. The slot-types of the instructions ahead
6644 of i never change, so we don't need to worry about
6645 changing NOPs in front of this slot. */
6646 for (j = i; j < 3; ++j)
6647 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
6649 template = required_template;
6651 if (curr != first && md.slot[curr].label_fixups)
6653 if (manual_bundling)
6655 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6656 "Label must be first in a bundle");
6657 manual_bundling = -1; /* Suppress meaningless post-loop errors. */
6659 /* This insn must go into the first slot of a bundle. */
6660 break;
6663 if (end_of_insn_group && md.num_slots_in_use >= 1)
6665 /* We need an instruction group boundary in the middle of a
6666 bundle. See if we can switch to an other template with
6667 an appropriate boundary. */
6669 orig_template = template;
6670 if (i == 1 && (user_template == 4
6671 || (user_template < 0
6672 && (ia64_templ_desc[template].exec_unit[0]
6673 == IA64_UNIT_M))))
6675 template = 5;
6676 end_of_insn_group = 0;
6678 else if (i == 2 && (user_template == 0
6679 || (user_template < 0
6680 && (ia64_templ_desc[template].exec_unit[1]
6681 == IA64_UNIT_I)))
6682 /* This test makes sure we don't switch the template if
6683 the next instruction is one that needs to be first in
6684 an instruction group. Since all those instructions are
6685 in the M group, there is no way such an instruction can
6686 fit in this bundle even if we switch the template. The
6687 reason we have to check for this is that otherwise we
6688 may end up generating "MI;;I M.." which has the deadly
6689 effect that the second M instruction is no longer the
6690 first in the group! --davidm 99/12/16 */
6691 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
6693 template = 1;
6694 end_of_insn_group = 0;
6696 else if (i == 1
6697 && user_template == 0
6698 && !(idesc->flags & IA64_OPCODE_FIRST))
6699 /* Use the next slot. */
6700 continue;
6701 else if (curr != first)
6702 /* can't fit this insn */
6703 break;
6705 if (template != orig_template)
6706 /* if we switch the template, we need to reset the NOPs
6707 after slot i. The slot-types of the instructions ahead
6708 of i never change, so we don't need to worry about
6709 changing NOPs in front of this slot. */
6710 for (j = i; j < 3; ++j)
6711 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
6713 required_unit = ia64_templ_desc[template].exec_unit[i];
6715 /* resolve dynamic opcodes such as "break", "hint", and "nop": */
6716 if (idesc->type == IA64_TYPE_DYN)
6718 enum ia64_opnd opnd1, opnd2;
6720 if ((strcmp (idesc->name, "nop") == 0)
6721 || (strcmp (idesc->name, "break") == 0))
6722 insn_unit = required_unit;
6723 else if (strcmp (idesc->name, "hint") == 0)
6725 insn_unit = required_unit;
6726 if (required_unit == IA64_UNIT_B)
6728 switch (md.hint_b)
6730 case hint_b_ok:
6731 break;
6732 case hint_b_warning:
6733 as_warn ("hint in B unit may be treated as nop");
6734 break;
6735 case hint_b_error:
6736 /* When manual bundling is off and there is no
6737 user template, we choose a different unit so
6738 that hint won't go into the current slot. We
6739 will fill the current bundle with nops and
6740 try to put hint into the next bundle. */
6741 if (!manual_bundling && user_template < 0)
6742 insn_unit = IA64_UNIT_I;
6743 else
6744 as_bad ("hint in B unit can't be used");
6745 break;
6749 else if (strcmp (idesc->name, "chk.s") == 0
6750 || strcmp (idesc->name, "mov") == 0)
6752 insn_unit = IA64_UNIT_M;
6753 if (required_unit == IA64_UNIT_I
6754 || (required_unit == IA64_UNIT_F && template == 6))
6755 insn_unit = IA64_UNIT_I;
6757 else
6758 as_fatal ("emit_one_bundle: unexpected dynamic op");
6760 sprintf (mnemonic, "%s.%c", idesc->name, "?imbfxx"[insn_unit]);
6761 opnd1 = idesc->operands[0];
6762 opnd2 = idesc->operands[1];
6763 ia64_free_opcode (idesc);
6764 idesc = ia64_find_opcode (mnemonic);
6765 /* moves to/from ARs have collisions */
6766 if (opnd1 == IA64_OPND_AR3 || opnd2 == IA64_OPND_AR3)
6768 while (idesc != NULL
6769 && (idesc->operands[0] != opnd1
6770 || idesc->operands[1] != opnd2))
6771 idesc = get_next_opcode (idesc);
6773 md.slot[curr].idesc = idesc;
6775 else
6777 insn_type = idesc->type;
6778 insn_unit = IA64_UNIT_NIL;
6779 switch (insn_type)
6781 case IA64_TYPE_A:
6782 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
6783 insn_unit = required_unit;
6784 break;
6785 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
6786 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
6787 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
6788 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
6789 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
6790 default: break;
6794 if (insn_unit != required_unit)
6795 continue; /* Try next slot. */
6797 if (debug_type == DEBUG_DWARF2 || md.slot[curr].loc_directive_seen)
6799 bfd_vma addr = frag_now->fr_address + frag_now_fix () - 16 + i;
6801 md.slot[curr].loc_directive_seen = 0;
6802 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
6805 build_insn (md.slot + curr, insn + i);
6807 ptr = md.slot[curr].unwind_record;
6808 if (ptr)
6810 /* Set slot numbers for all remaining unwind records belonging to the
6811 current insn. There can not be any prologue/body unwind records
6812 here. */
6813 end_ptr = md.slot[(curr + 1) % NUM_SLOTS].unwind_record;
6814 for (; ptr != end_ptr; ptr = ptr->next)
6816 ptr->slot_number = (unsigned long) f + i;
6817 ptr->slot_frag = frag_now;
6819 md.slot[curr].unwind_record = NULL;
6822 if (required_unit == IA64_UNIT_L)
6824 know (i == 1);
6825 /* skip one slot for long/X-unit instructions */
6826 ++i;
6828 --md.num_slots_in_use;
6829 last_slot = i;
6831 /* now is a good time to fix up the labels for this insn: */
6832 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
6834 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
6835 symbol_set_frag (lfix->sym, frag_now);
6837 /* and fix up the tags also. */
6838 for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next)
6840 S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i);
6841 symbol_set_frag (lfix->sym, frag_now);
6844 for (j = 0; j < md.slot[curr].num_fixups; ++j)
6846 ifix = md.slot[curr].fixup + j;
6847 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8,
6848 &ifix->expr, ifix->is_pcrel, ifix->code);
6849 fix->tc_fix_data.opnd = ifix->opnd;
6850 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
6851 fix->fx_file = md.slot[curr].src_file;
6852 fix->fx_line = md.slot[curr].src_line;
6855 end_of_insn_group = md.slot[curr].end_of_insn_group;
6857 /* clear slot: */
6858 ia64_free_opcode (md.slot[curr].idesc);
6859 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6860 md.slot[curr].user_template = -1;
6862 if (manual_bundling_off)
6864 manual_bundling = 0;
6865 break;
6867 curr = (curr + 1) % NUM_SLOTS;
6868 idesc = md.slot[curr].idesc;
6870 if (manual_bundling > 0)
6872 if (md.num_slots_in_use > 0)
6874 if (last_slot >= 2)
6875 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6876 "`%s' does not fit into bundle", idesc->name);
6877 else if (last_slot < 0)
6879 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6880 "`%s' does not fit into %s template",
6881 idesc->name, ia64_templ_desc[template].name);
6882 /* Drop first insn so we don't livelock. */
6883 --md.num_slots_in_use;
6884 know (curr == first);
6885 ia64_free_opcode (md.slot[curr].idesc);
6886 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
6887 md.slot[curr].user_template = -1;
6889 else
6891 const char *where;
6893 if (template == 2)
6894 where = "X slot";
6895 else if (last_slot == 0)
6896 where = "slots 2 or 3";
6897 else
6898 where = "slot 3";
6899 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6900 "`%s' can't go in %s of %s template",
6901 idesc->name, where, ia64_templ_desc[template].name);
6904 else
6905 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
6906 "Missing '}' at end of file");
6908 know (md.num_slots_in_use < NUM_SLOTS);
6910 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
6911 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
6913 number_to_chars_littleendian (f + 0, t0, 8);
6914 number_to_chars_littleendian (f + 8, t1, 8);
6916 if (unwind.list)
6918 unwind.list->next_slot_number = (unsigned long) f + 16;
6919 unwind.list->next_slot_frag = frag_now;
6924 md_parse_option (c, arg)
6925 int c;
6926 char *arg;
6929 switch (c)
6931 /* Switches from the Intel assembler. */
6932 case 'm':
6933 if (strcmp (arg, "ilp64") == 0
6934 || strcmp (arg, "lp64") == 0
6935 || strcmp (arg, "p64") == 0)
6937 md.flags |= EF_IA_64_ABI64;
6939 else if (strcmp (arg, "ilp32") == 0)
6941 md.flags &= ~EF_IA_64_ABI64;
6943 else if (strcmp (arg, "le") == 0)
6945 md.flags &= ~EF_IA_64_BE;
6946 default_big_endian = 0;
6948 else if (strcmp (arg, "be") == 0)
6950 md.flags |= EF_IA_64_BE;
6951 default_big_endian = 1;
6953 else if (strncmp (arg, "unwind-check=", 13) == 0)
6955 arg += 13;
6956 if (strcmp (arg, "warning") == 0)
6957 md.unwind_check = unwind_check_warning;
6958 else if (strcmp (arg, "error") == 0)
6959 md.unwind_check = unwind_check_error;
6960 else
6961 return 0;
6963 else if (strncmp (arg, "hint.b=", 7) == 0)
6965 arg += 7;
6966 if (strcmp (arg, "ok") == 0)
6967 md.hint_b = hint_b_ok;
6968 else if (strcmp (arg, "warning") == 0)
6969 md.hint_b = hint_b_warning;
6970 else if (strcmp (arg, "error") == 0)
6971 md.hint_b = hint_b_error;
6972 else
6973 return 0;
6975 else if (strncmp (arg, "tune=", 5) == 0)
6977 arg += 5;
6978 if (strcmp (arg, "itanium1") == 0)
6979 md.tune = itanium1;
6980 else if (strcmp (arg, "itanium2") == 0)
6981 md.tune = itanium2;
6982 else
6983 return 0;
6985 else
6986 return 0;
6987 break;
6989 case 'N':
6990 if (strcmp (arg, "so") == 0)
6992 /* Suppress signon message. */
6994 else if (strcmp (arg, "pi") == 0)
6996 /* Reject privileged instructions. FIXME */
6998 else if (strcmp (arg, "us") == 0)
7000 /* Allow union of signed and unsigned range. FIXME */
7002 else if (strcmp (arg, "close_fcalls") == 0)
7004 /* Do not resolve global function calls. */
7006 else
7007 return 0;
7008 break;
7010 case 'C':
7011 /* temp[="prefix"] Insert temporary labels into the object file
7012 symbol table prefixed by "prefix".
7013 Default prefix is ":temp:".
7015 break;
7017 case 'a':
7018 /* indirect=<tgt> Assume unannotated indirect branches behavior
7019 according to <tgt> --
7020 exit: branch out from the current context (default)
7021 labels: all labels in context may be branch targets
7023 if (strncmp (arg, "indirect=", 9) != 0)
7024 return 0;
7025 break;
7027 case 'x':
7028 /* -X conflicts with an ignored option, use -x instead */
7029 md.detect_dv = 1;
7030 if (!arg || strcmp (arg, "explicit") == 0)
7032 /* set default mode to explicit */
7033 md.default_explicit_mode = 1;
7034 break;
7036 else if (strcmp (arg, "auto") == 0)
7038 md.default_explicit_mode = 0;
7040 else if (strcmp (arg, "none") == 0)
7042 md.detect_dv = 0;
7044 else if (strcmp (arg, "debug") == 0)
7046 md.debug_dv = 1;
7048 else if (strcmp (arg, "debugx") == 0)
7050 md.default_explicit_mode = 1;
7051 md.debug_dv = 1;
7053 else if (strcmp (arg, "debugn") == 0)
7055 md.debug_dv = 1;
7056 md.detect_dv = 0;
7058 else
7060 as_bad (_("Unrecognized option '-x%s'"), arg);
7062 break;
7064 case 'S':
7065 /* nops Print nops statistics. */
7066 break;
7068 /* GNU specific switches for gcc. */
7069 case OPTION_MCONSTANT_GP:
7070 md.flags |= EF_IA_64_CONS_GP;
7071 break;
7073 case OPTION_MAUTO_PIC:
7074 md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP;
7075 break;
7077 default:
7078 return 0;
7081 return 1;
7084 void
7085 md_show_usage (stream)
7086 FILE *stream;
7088 fputs (_("\
7089 IA-64 options:\n\
7090 --mconstant-gp mark output file as using the constant-GP model\n\
7091 (sets ELF header flag EF_IA_64_CONS_GP)\n\
7092 --mauto-pic mark output file as using the constant-GP model\n\
7093 without function descriptors (sets ELF header flag\n\
7094 EF_IA_64_NOFUNCDESC_CONS_GP)\n\
7095 -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\
7096 -mle | -mbe select little- or big-endian byte order (default -mle)\n\
7097 -mtune=[itanium1|itanium2]\n\
7098 tune for a specific CPU (default -mtune=itanium2)\n\
7099 -munwind-check=[warning|error]\n\
7100 unwind directive check (default -munwind-check=warning)\n\
7101 -mhint.b=[ok|warning|error]\n\
7102 hint.b check (default -mhint.b=error)\n\
7103 -x | -xexplicit turn on dependency violation checking\n\
7104 -xauto automagically remove dependency violations (default)\n\
7105 -xnone turn off dependency violation checking\n\
7106 -xdebug debug dependency violation checker\n\
7107 -xdebugn debug dependency violation checker but turn off\n\
7108 dependency violation checking\n\
7109 -xdebugx debug dependency violation checker and turn on\n\
7110 dependency violation checking\n"),
7111 stream);
7114 void
7115 ia64_after_parse_args ()
7117 if (debug_type == DEBUG_STABS)
7118 as_fatal (_("--gstabs is not supported for ia64"));
7121 /* Return true if TYPE fits in TEMPL at SLOT. */
7123 static int
7124 match (int templ, int type, int slot)
7126 enum ia64_unit unit;
7127 int result;
7129 unit = ia64_templ_desc[templ].exec_unit[slot];
7130 switch (type)
7132 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
7133 case IA64_TYPE_A:
7134 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
7135 break;
7136 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
7137 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
7138 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
7139 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
7140 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
7141 default: result = 0; break;
7143 return result;
7146 /* Add a bit of extra goodness if a nop of type F or B would fit
7147 in TEMPL at SLOT. */
7149 static inline int
7150 extra_goodness (int templ, int slot)
7152 switch (md.tune)
7154 case itanium1:
7155 if (slot == 1 && match (templ, IA64_TYPE_F, slot))
7156 return 2;
7157 else if (slot == 2 && match (templ, IA64_TYPE_B, slot))
7158 return 1;
7159 else
7160 return 0;
7161 break;
7162 case itanium2:
7163 if (match (templ, IA64_TYPE_M, slot)
7164 || match (templ, IA64_TYPE_I, slot))
7165 /* Favor M- and I-unit NOPs. We definitely want to avoid
7166 F-unit and B-unit may cause split-issue or less-than-optimal
7167 branch-prediction. */
7168 return 2;
7169 else
7170 return 0;
7171 break;
7172 default:
7173 abort ();
7174 return 0;
7178 /* This function is called once, at assembler startup time. It sets
7179 up all the tables, etc. that the MD part of the assembler will need
7180 that can be determined before arguments are parsed. */
7181 void
7182 md_begin ()
7184 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum, ok;
7185 const char *err;
7186 char name[8];
7188 md.auto_align = 1;
7189 md.explicit_mode = md.default_explicit_mode;
7191 bfd_set_section_alignment (stdoutput, text_section, 4);
7193 /* Make sure function pointers get initialized. */
7194 target_big_endian = -1;
7195 dot_byteorder (default_big_endian);
7197 alias_hash = hash_new ();
7198 alias_name_hash = hash_new ();
7199 secalias_hash = hash_new ();
7200 secalias_name_hash = hash_new ();
7202 pseudo_func[FUNC_DTP_MODULE].u.sym =
7203 symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE,
7204 &zero_address_frag);
7206 pseudo_func[FUNC_DTP_RELATIVE].u.sym =
7207 symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE,
7208 &zero_address_frag);
7210 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
7211 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
7212 &zero_address_frag);
7214 pseudo_func[FUNC_GP_RELATIVE].u.sym =
7215 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
7216 &zero_address_frag);
7218 pseudo_func[FUNC_LT_RELATIVE].u.sym =
7219 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
7220 &zero_address_frag);
7222 pseudo_func[FUNC_LT_RELATIVE_X].u.sym =
7223 symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X,
7224 &zero_address_frag);
7226 pseudo_func[FUNC_PC_RELATIVE].u.sym =
7227 symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE,
7228 &zero_address_frag);
7230 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
7231 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
7232 &zero_address_frag);
7234 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
7235 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
7236 &zero_address_frag);
7238 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
7239 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
7240 &zero_address_frag);
7242 pseudo_func[FUNC_TP_RELATIVE].u.sym =
7243 symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE,
7244 &zero_address_frag);
7246 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
7247 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
7248 &zero_address_frag);
7250 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
7251 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
7252 &zero_address_frag);
7254 pseudo_func[FUNC_LT_DTP_MODULE].u.sym =
7255 symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE,
7256 &zero_address_frag);
7258 pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym =
7259 symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE,
7260 &zero_address_frag);
7262 pseudo_func[FUNC_LT_TP_RELATIVE].u.sym =
7263 symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE,
7264 &zero_address_frag);
7266 pseudo_func[FUNC_IPLT_RELOC].u.sym =
7267 symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC,
7268 &zero_address_frag);
7270 if (md.tune != itanium1)
7272 /* Convert MFI NOPs bundles into MMI NOPs bundles. */
7273 le_nop[0] = 0x8;
7274 le_nop_stop[0] = 0x9;
7277 /* Compute the table of best templates. We compute goodness as a
7278 base 4 value, in which each match counts for 3. Match-failures
7279 result in NOPs and we use extra_goodness() to pick the execution
7280 units that are best suited for issuing the NOP. */
7281 for (i = 0; i < IA64_NUM_TYPES; ++i)
7282 for (j = 0; j < IA64_NUM_TYPES; ++j)
7283 for (k = 0; k < IA64_NUM_TYPES; ++k)
7285 best = 0;
7286 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
7288 goodness = 0;
7289 if (match (t, i, 0))
7291 if (match (t, j, 1))
7293 if (match (t, k, 2))
7294 goodness = 3 + 3 + 3;
7295 else
7296 goodness = 3 + 3 + extra_goodness (t, 2);
7298 else if (match (t, j, 2))
7299 goodness = 3 + 3 + extra_goodness (t, 1);
7300 else
7302 goodness = 3;
7303 goodness += extra_goodness (t, 1);
7304 goodness += extra_goodness (t, 2);
7307 else if (match (t, i, 1))
7309 if (match (t, j, 2))
7310 goodness = 3 + 3;
7311 else
7312 goodness = 3 + extra_goodness (t, 2);
7314 else if (match (t, i, 2))
7315 goodness = 3 + extra_goodness (t, 1);
7317 if (goodness > best)
7319 best = goodness;
7320 best_template[i][j][k] = t;
7325 for (i = 0; i < NUM_SLOTS; ++i)
7326 md.slot[i].user_template = -1;
7328 md.pseudo_hash = hash_new ();
7329 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
7331 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
7332 (void *) (pseudo_opcode + i));
7333 if (err)
7334 as_fatal ("ia64.md_begin: can't hash `%s': %s",
7335 pseudo_opcode[i].name, err);
7338 md.reg_hash = hash_new ();
7339 md.dynreg_hash = hash_new ();
7340 md.const_hash = hash_new ();
7341 md.entry_hash = hash_new ();
7343 /* general registers: */
7345 total = 128;
7346 for (i = 0; i < total; ++i)
7348 sprintf (name, "r%d", i - REG_GR);
7349 md.regsym[i] = declare_register (name, i);
7352 /* floating point registers: */
7353 total += 128;
7354 for (; i < total; ++i)
7356 sprintf (name, "f%d", i - REG_FR);
7357 md.regsym[i] = declare_register (name, i);
7360 /* application registers: */
7361 total += 128;
7362 ar_base = i;
7363 for (; i < total; ++i)
7365 sprintf (name, "ar%d", i - REG_AR);
7366 md.regsym[i] = declare_register (name, i);
7369 /* control registers: */
7370 total += 128;
7371 cr_base = i;
7372 for (; i < total; ++i)
7374 sprintf (name, "cr%d", i - REG_CR);
7375 md.regsym[i] = declare_register (name, i);
7378 /* predicate registers: */
7379 total += 64;
7380 for (; i < total; ++i)
7382 sprintf (name, "p%d", i - REG_P);
7383 md.regsym[i] = declare_register (name, i);
7386 /* branch registers: */
7387 total += 8;
7388 for (; i < total; ++i)
7390 sprintf (name, "b%d", i - REG_BR);
7391 md.regsym[i] = declare_register (name, i);
7394 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
7395 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
7396 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
7397 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
7398 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
7399 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
7400 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
7402 for (i = 0; i < NELEMS (indirect_reg); ++i)
7404 regnum = indirect_reg[i].regnum;
7405 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
7408 /* define synonyms for application registers: */
7409 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
7410 md.regsym[i] = declare_register (ar[i - REG_AR].name,
7411 REG_AR + ar[i - REG_AR].regnum);
7413 /* define synonyms for control registers: */
7414 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
7415 md.regsym[i] = declare_register (cr[i - REG_CR].name,
7416 REG_CR + cr[i - REG_CR].regnum);
7418 declare_register ("gp", REG_GR + 1);
7419 declare_register ("sp", REG_GR + 12);
7420 declare_register ("rp", REG_BR + 0);
7422 /* pseudo-registers used to specify unwind info: */
7423 declare_register ("psp", REG_PSP);
7425 declare_register_set ("ret", 4, REG_GR + 8);
7426 declare_register_set ("farg", 8, REG_FR + 8);
7427 declare_register_set ("fret", 8, REG_FR + 8);
7429 for (i = 0; i < NELEMS (const_bits); ++i)
7431 err = hash_insert (md.const_hash, const_bits[i].name,
7432 (PTR) (const_bits + i));
7433 if (err)
7434 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
7435 name, err);
7438 /* Set the architecture and machine depending on defaults and command line
7439 options. */
7440 if (md.flags & EF_IA_64_ABI64)
7441 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64);
7442 else
7443 ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32);
7445 if (! ok)
7446 as_warn (_("Could not set architecture and machine"));
7448 /* Set the pointer size and pointer shift size depending on md.flags */
7450 if (md.flags & EF_IA_64_ABI64)
7452 md.pointer_size = 8; /* pointers are 8 bytes */
7453 md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */
7455 else
7457 md.pointer_size = 4; /* pointers are 4 bytes */
7458 md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */
7461 md.mem_offset.hint = 0;
7462 md.path = 0;
7463 md.maxpaths = 0;
7464 md.entry_labels = NULL;
7467 /* Set the default options in md. Cannot do this in md_begin because
7468 that is called after md_parse_option which is where we set the
7469 options in md based on command line options. */
7471 void
7472 ia64_init (argc, argv)
7473 int argc ATTRIBUTE_UNUSED;
7474 char **argv ATTRIBUTE_UNUSED;
7476 md.flags = MD_FLAGS_DEFAULT;
7477 md.detect_dv = 1;
7478 /* FIXME: We should change it to unwind_check_error someday. */
7479 md.unwind_check = unwind_check_warning;
7480 md.hint_b = hint_b_error;
7481 md.tune = itanium2;
7484 /* Return a string for the target object file format. */
7486 const char *
7487 ia64_target_format ()
7489 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
7491 if (md.flags & EF_IA_64_BE)
7493 if (md.flags & EF_IA_64_ABI64)
7494 #if defined(TE_AIX50)
7495 return "elf64-ia64-aix-big";
7496 #elif defined(TE_HPUX)
7497 return "elf64-ia64-hpux-big";
7498 #else
7499 return "elf64-ia64-big";
7500 #endif
7501 else
7502 #if defined(TE_AIX50)
7503 return "elf32-ia64-aix-big";
7504 #elif defined(TE_HPUX)
7505 return "elf32-ia64-hpux-big";
7506 #else
7507 return "elf32-ia64-big";
7508 #endif
7510 else
7512 if (md.flags & EF_IA_64_ABI64)
7513 #ifdef TE_AIX50
7514 return "elf64-ia64-aix-little";
7515 #else
7516 return "elf64-ia64-little";
7517 #endif
7518 else
7519 #ifdef TE_AIX50
7520 return "elf32-ia64-aix-little";
7521 #else
7522 return "elf32-ia64-little";
7523 #endif
7526 else
7527 return "unknown-format";
7530 void
7531 ia64_end_of_source ()
7533 /* terminate insn group upon reaching end of file: */
7534 insn_group_break (1, 0, 0);
7536 /* emits slots we haven't written yet: */
7537 ia64_flush_insns ();
7539 bfd_set_private_flags (stdoutput, md.flags);
7541 md.mem_offset.hint = 0;
7544 void
7545 ia64_start_line ()
7547 if (md.qp.X_op == O_register)
7548 as_bad ("qualifying predicate not followed by instruction");
7549 md.qp.X_op = O_absent;
7551 if (ignore_input ())
7552 return;
7554 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
7556 if (md.detect_dv && !md.explicit_mode)
7558 static int warned;
7560 if (!warned)
7562 warned = 1;
7563 as_warn (_("Explicit stops are ignored in auto mode"));
7566 else
7567 insn_group_break (1, 0, 0);
7571 /* This is a hook for ia64_frob_label, so that it can distinguish tags from
7572 labels. */
7573 static int defining_tag = 0;
7576 ia64_unrecognized_line (ch)
7577 int ch;
7579 switch (ch)
7581 case '(':
7582 expression (&md.qp);
7583 if (*input_line_pointer++ != ')')
7585 as_bad ("Expected ')'");
7586 return 0;
7588 if (md.qp.X_op != O_register)
7590 as_bad ("Qualifying predicate expected");
7591 return 0;
7593 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
7595 as_bad ("Predicate register expected");
7596 return 0;
7598 return 1;
7600 case '{':
7601 if (md.manual_bundling)
7602 as_warn ("Found '{' when manual bundling is already turned on");
7603 else
7604 CURR_SLOT.manual_bundling_on = 1;
7605 md.manual_bundling = 1;
7607 /* Bundling is only acceptable in explicit mode
7608 or when in default automatic mode. */
7609 if (md.detect_dv && !md.explicit_mode)
7611 if (!md.mode_explicitly_set
7612 && !md.default_explicit_mode)
7613 dot_dv_mode ('E');
7614 else
7615 as_warn (_("Found '{' after explicit switch to automatic mode"));
7617 return 1;
7619 case '}':
7620 if (!md.manual_bundling)
7621 as_warn ("Found '}' when manual bundling is off");
7622 else
7623 PREV_SLOT.manual_bundling_off = 1;
7624 md.manual_bundling = 0;
7626 /* switch back to automatic mode, if applicable */
7627 if (md.detect_dv
7628 && md.explicit_mode
7629 && !md.mode_explicitly_set
7630 && !md.default_explicit_mode)
7631 dot_dv_mode ('A');
7633 /* Allow '{' to follow on the same line. We also allow ";;", but that
7634 happens automatically because ';' is an end of line marker. */
7635 SKIP_WHITESPACE ();
7636 if (input_line_pointer[0] == '{')
7638 input_line_pointer++;
7639 return ia64_unrecognized_line ('{');
7642 demand_empty_rest_of_line ();
7643 return 1;
7645 case '[':
7647 char *s;
7648 char c;
7649 symbolS *tag;
7650 int temp;
7652 if (md.qp.X_op == O_register)
7654 as_bad ("Tag must come before qualifying predicate.");
7655 return 0;
7658 /* This implements just enough of read_a_source_file in read.c to
7659 recognize labels. */
7660 if (is_name_beginner (*input_line_pointer))
7662 s = input_line_pointer;
7663 c = get_symbol_end ();
7665 else if (LOCAL_LABELS_FB
7666 && ISDIGIT (*input_line_pointer))
7668 temp = 0;
7669 while (ISDIGIT (*input_line_pointer))
7670 temp = (temp * 10) + *input_line_pointer++ - '0';
7671 fb_label_instance_inc (temp);
7672 s = fb_label_name (temp, 0);
7673 c = *input_line_pointer;
7675 else
7677 s = NULL;
7678 c = '\0';
7680 if (c != ':')
7682 /* Put ':' back for error messages' sake. */
7683 *input_line_pointer++ = ':';
7684 as_bad ("Expected ':'");
7685 return 0;
7688 defining_tag = 1;
7689 tag = colon (s);
7690 defining_tag = 0;
7691 /* Put ':' back for error messages' sake. */
7692 *input_line_pointer++ = ':';
7693 if (*input_line_pointer++ != ']')
7695 as_bad ("Expected ']'");
7696 return 0;
7698 if (! tag)
7700 as_bad ("Tag name expected");
7701 return 0;
7703 return 1;
7706 default:
7707 break;
7710 /* Not a valid line. */
7711 return 0;
7714 void
7715 ia64_frob_label (sym)
7716 struct symbol *sym;
7718 struct label_fix *fix;
7720 /* Tags need special handling since they are not bundle breaks like
7721 labels. */
7722 if (defining_tag)
7724 fix = obstack_alloc (&notes, sizeof (*fix));
7725 fix->sym = sym;
7726 fix->next = CURR_SLOT.tag_fixups;
7727 CURR_SLOT.tag_fixups = fix;
7729 return;
7732 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7734 md.last_text_seg = now_seg;
7735 fix = obstack_alloc (&notes, sizeof (*fix));
7736 fix->sym = sym;
7737 fix->next = CURR_SLOT.label_fixups;
7738 CURR_SLOT.label_fixups = fix;
7740 /* Keep track of how many code entry points we've seen. */
7741 if (md.path == md.maxpaths)
7743 md.maxpaths += 20;
7744 md.entry_labels = (const char **)
7745 xrealloc ((void *) md.entry_labels,
7746 md.maxpaths * sizeof (char *));
7748 md.entry_labels[md.path++] = S_GET_NAME (sym);
7752 #ifdef TE_HPUX
7753 /* The HP-UX linker will give unresolved symbol errors for symbols
7754 that are declared but unused. This routine removes declared,
7755 unused symbols from an object. */
7757 ia64_frob_symbol (sym)
7758 struct symbol *sym;
7760 if ((S_GET_SEGMENT (sym) == &bfd_und_section && ! symbol_used_p (sym) &&
7761 ELF_ST_VISIBILITY (S_GET_OTHER (sym)) == STV_DEFAULT)
7762 || (S_GET_SEGMENT (sym) == &bfd_abs_section
7763 && ! S_IS_EXTERNAL (sym)))
7764 return 1;
7765 return 0;
7767 #endif
7769 void
7770 ia64_flush_pending_output ()
7772 if (!md.keep_pending_output
7773 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
7775 /* ??? This causes many unnecessary stop bits to be emitted.
7776 Unfortunately, it isn't clear if it is safe to remove this. */
7777 insn_group_break (1, 0, 0);
7778 ia64_flush_insns ();
7782 /* Do ia64-specific expression optimization. All that's done here is
7783 to transform index expressions that are either due to the indexing
7784 of rotating registers or due to the indexing of indirect register
7785 sets. */
7787 ia64_optimize_expr (l, op, r)
7788 expressionS *l;
7789 operatorT op;
7790 expressionS *r;
7792 unsigned num_regs;
7794 if (op == O_index)
7796 if (l->X_op == O_register && r->X_op == O_constant)
7798 num_regs = (l->X_add_number >> 16);
7799 if ((unsigned) r->X_add_number >= num_regs)
7801 if (!num_regs)
7802 as_bad ("No current frame");
7803 else
7804 as_bad ("Index out of range 0..%u", num_regs - 1);
7805 r->X_add_number = 0;
7807 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
7808 return 1;
7810 else if (l->X_op == O_register && r->X_op == O_register)
7812 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
7813 || l->X_add_number == IND_MEM)
7815 as_bad ("Indirect register set name expected");
7816 l->X_add_number = IND_CPUID;
7818 l->X_op = O_index;
7819 l->X_op_symbol = md.regsym[l->X_add_number];
7820 l->X_add_number = r->X_add_number;
7821 return 1;
7824 return 0;
7828 ia64_parse_name (name, e, nextcharP)
7829 char *name;
7830 expressionS *e;
7831 char *nextcharP;
7833 struct const_desc *cdesc;
7834 struct dynreg *dr = 0;
7835 unsigned int idx;
7836 struct symbol *sym;
7837 char *end;
7839 if (*name == '@')
7841 enum pseudo_type pseudo_type = PSEUDO_FUNC_NONE;
7843 /* Find what relocation pseudo-function we're dealing with. */
7844 for (idx = 0; idx < NELEMS (pseudo_func); ++idx)
7845 if (pseudo_func[idx].name
7846 && pseudo_func[idx].name[0] == name[1]
7847 && strcmp (pseudo_func[idx].name + 1, name + 2) == 0)
7849 pseudo_type = pseudo_func[idx].type;
7850 break;
7852 switch (pseudo_type)
7854 case PSEUDO_FUNC_RELOC:
7855 end = input_line_pointer;
7856 if (*nextcharP != '(')
7858 as_bad ("Expected '('");
7859 break;
7861 /* Skip '('. */
7862 ++input_line_pointer;
7863 expression (e);
7864 if (*input_line_pointer != ')')
7866 as_bad ("Missing ')'");
7867 goto done;
7869 /* Skip ')'. */
7870 ++input_line_pointer;
7871 if (e->X_op != O_symbol)
7873 if (e->X_op != O_pseudo_fixup)
7875 as_bad ("Not a symbolic expression");
7876 goto done;
7878 if (idx != FUNC_LT_RELATIVE)
7880 as_bad ("Illegal combination of relocation functions");
7881 goto done;
7883 switch (S_GET_VALUE (e->X_op_symbol))
7885 case FUNC_FPTR_RELATIVE:
7886 idx = FUNC_LT_FPTR_RELATIVE; break;
7887 case FUNC_DTP_MODULE:
7888 idx = FUNC_LT_DTP_MODULE; break;
7889 case FUNC_DTP_RELATIVE:
7890 idx = FUNC_LT_DTP_RELATIVE; break;
7891 case FUNC_TP_RELATIVE:
7892 idx = FUNC_LT_TP_RELATIVE; break;
7893 default:
7894 as_bad ("Illegal combination of relocation functions");
7895 goto done;
7898 /* Make sure gas doesn't get rid of local symbols that are used
7899 in relocs. */
7900 e->X_op = O_pseudo_fixup;
7901 e->X_op_symbol = pseudo_func[idx].u.sym;
7902 done:
7903 *nextcharP = *input_line_pointer;
7904 break;
7906 case PSEUDO_FUNC_CONST:
7907 e->X_op = O_constant;
7908 e->X_add_number = pseudo_func[idx].u.ival;
7909 break;
7911 case PSEUDO_FUNC_REG:
7912 e->X_op = O_register;
7913 e->X_add_number = pseudo_func[idx].u.ival;
7914 break;
7916 default:
7917 return 0;
7919 return 1;
7922 /* first see if NAME is a known register name: */
7923 sym = hash_find (md.reg_hash, name);
7924 if (sym)
7926 e->X_op = O_register;
7927 e->X_add_number = S_GET_VALUE (sym);
7928 return 1;
7931 cdesc = hash_find (md.const_hash, name);
7932 if (cdesc)
7934 e->X_op = O_constant;
7935 e->X_add_number = cdesc->value;
7936 return 1;
7939 /* check for inN, locN, or outN: */
7940 idx = 0;
7941 switch (name[0])
7943 case 'i':
7944 if (name[1] == 'n' && ISDIGIT (name[2]))
7946 dr = &md.in;
7947 idx = 2;
7949 break;
7951 case 'l':
7952 if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3]))
7954 dr = &md.loc;
7955 idx = 3;
7957 break;
7959 case 'o':
7960 if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3]))
7962 dr = &md.out;
7963 idx = 3;
7965 break;
7967 default:
7968 break;
7971 /* Ignore register numbers with leading zeroes, except zero itself. */
7972 if (dr && (name[idx] != '0' || name[idx + 1] == '\0'))
7974 unsigned long regnum;
7976 /* The name is inN, locN, or outN; parse the register number. */
7977 regnum = strtoul (name + idx, &end, 10);
7978 if (end > name + idx && *end == '\0' && regnum < 96)
7980 if (regnum >= dr->num_regs)
7982 if (!dr->num_regs)
7983 as_bad ("No current frame");
7984 else
7985 as_bad ("Register number out of range 0..%u",
7986 dr->num_regs - 1);
7987 regnum = 0;
7989 e->X_op = O_register;
7990 e->X_add_number = dr->base + regnum;
7991 return 1;
7995 end = alloca (strlen (name) + 1);
7996 strcpy (end, name);
7997 name = ia64_canonicalize_symbol_name (end);
7998 if ((dr = hash_find (md.dynreg_hash, name)))
8000 /* We've got ourselves the name of a rotating register set.
8001 Store the base register number in the low 16 bits of
8002 X_add_number and the size of the register set in the top 16
8003 bits. */
8004 e->X_op = O_register;
8005 e->X_add_number = dr->base | (dr->num_regs << 16);
8006 return 1;
8008 return 0;
8011 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
8013 char *
8014 ia64_canonicalize_symbol_name (name)
8015 char *name;
8017 size_t len = strlen (name), full = len;
8019 while (len > 0 && name[len - 1] == '#')
8020 --len;
8021 if (len <= 0)
8023 if (full > 0)
8024 as_bad ("Standalone `#' is illegal");
8026 else if (len < full - 1)
8027 as_warn ("Redundant `#' suffix operators");
8028 name[len] = '\0';
8029 return name;
8032 /* Return true if idesc is a conditional branch instruction. This excludes
8033 the modulo scheduled branches, and br.ia. Mod-sched branches are excluded
8034 because they always read/write resources regardless of the value of the
8035 qualifying predicate. br.ia must always use p0, and hence is always
8036 taken. Thus this function returns true for branches which can fall
8037 through, and which use no resources if they do fall through. */
8039 static int
8040 is_conditional_branch (idesc)
8041 struct ia64_opcode *idesc;
8043 /* br is a conditional branch. Everything that starts with br. except
8044 br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch.
8045 Everything that starts with brl is a conditional branch. */
8046 return (idesc->name[0] == 'b' && idesc->name[1] == 'r'
8047 && (idesc->name[2] == '\0'
8048 || (idesc->name[2] == '.' && idesc->name[3] != 'i'
8049 && idesc->name[3] != 'c' && idesc->name[3] != 'w')
8050 || idesc->name[2] == 'l'
8051 /* br.cond, br.call, br.clr */
8052 || (idesc->name[2] == '.' && idesc->name[3] == 'c'
8053 && (idesc->name[4] == 'a' || idesc->name[4] == 'o'
8054 || (idesc->name[4] == 'l' && idesc->name[5] == 'r')))));
8057 /* Return whether the given opcode is a taken branch. If there's any doubt,
8058 returns zero. */
8060 static int
8061 is_taken_branch (idesc)
8062 struct ia64_opcode *idesc;
8064 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
8065 || strncmp (idesc->name, "br.ia", 5) == 0);
8068 /* Return whether the given opcode is an interruption or rfi. If there's any
8069 doubt, returns zero. */
8071 static int
8072 is_interruption_or_rfi (idesc)
8073 struct ia64_opcode *idesc;
8075 if (strcmp (idesc->name, "rfi") == 0)
8076 return 1;
8077 return 0;
8080 /* Returns the index of the given dependency in the opcode's list of chks, or
8081 -1 if there is no dependency. */
8083 static int
8084 depends_on (depind, idesc)
8085 int depind;
8086 struct ia64_opcode *idesc;
8088 int i;
8089 const struct ia64_opcode_dependency *dep = idesc->dependencies;
8090 for (i = 0; i < dep->nchks; i++)
8092 if (depind == DEP (dep->chks[i]))
8093 return i;
8095 return -1;
8098 /* Determine a set of specific resources used for a particular resource
8099 class. Returns the number of specific resources identified For those
8100 cases which are not determinable statically, the resource returned is
8101 marked nonspecific.
8103 Meanings of value in 'NOTE':
8104 1) only read/write when the register number is explicitly encoded in the
8105 insn.
8106 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
8107 accesses CFM when qualifying predicate is in the rotating region.
8108 3) general register value is used to specify an indirect register; not
8109 determinable statically.
8110 4) only read the given resource when bits 7:0 of the indirect index
8111 register value does not match the register number of the resource; not
8112 determinable statically.
8113 5) all rules are implementation specific.
8114 6) only when both the index specified by the reader and the index specified
8115 by the writer have the same value in bits 63:61; not determinable
8116 statically.
8117 7) only access the specified resource when the corresponding mask bit is
8119 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
8120 only read when these insns reference FR2-31
8121 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
8122 written when these insns write FR32-127
8123 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
8124 instruction
8125 11) The target predicates are written independently of PR[qp], but source
8126 registers are only read if PR[qp] is true. Since the state of PR[qp]
8127 cannot statically be determined, all source registers are marked used.
8128 12) This insn only reads the specified predicate register when that
8129 register is the PR[qp].
8130 13) This reference to ld-c only applies to teh GR whose value is loaded
8131 with data returned from memory, not the post-incremented address register.
8132 14) The RSE resource includes the implementation-specific RSE internal
8133 state resources. At least one (and possibly more) of these resources are
8134 read by each instruction listed in IC:rse-readers. At least one (and
8135 possibly more) of these resources are written by each insn listed in
8136 IC:rse-writers.
8137 15+16) Represents reserved instructions, which the assembler does not
8138 generate.
8140 Memory resources (i.e. locations in memory) are *not* marked or tracked by
8141 this code; there are no dependency violations based on memory access.
8144 #define MAX_SPECS 256
8145 #define DV_CHK 1
8146 #define DV_REG 0
8148 static int
8149 specify_resource (dep, idesc, type, specs, note, path)
8150 const struct ia64_dependency *dep;
8151 struct ia64_opcode *idesc;
8152 int type; /* is this a DV chk or a DV reg? */
8153 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
8154 int note; /* resource note for this insn's usage */
8155 int path; /* which execution path to examine */
8157 int count = 0;
8158 int i;
8159 int rsrc_write = 0;
8160 struct rsrc tmpl;
8162 if (dep->mode == IA64_DV_WAW
8163 || (dep->mode == IA64_DV_RAW && type == DV_REG)
8164 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
8165 rsrc_write = 1;
8167 /* template for any resources we identify */
8168 tmpl.dependency = dep;
8169 tmpl.note = note;
8170 tmpl.insn_srlz = tmpl.data_srlz = 0;
8171 tmpl.qp_regno = CURR_SLOT.qp_regno;
8172 tmpl.link_to_qp_branch = 1;
8173 tmpl.mem_offset.hint = 0;
8174 tmpl.mem_offset.offset = 0;
8175 tmpl.mem_offset.base = 0;
8176 tmpl.specific = 1;
8177 tmpl.index = -1;
8178 tmpl.cmp_type = CMP_NONE;
8179 tmpl.depind = 0;
8180 tmpl.file = NULL;
8181 tmpl.line = 0;
8182 tmpl.path = 0;
8184 #define UNHANDLED \
8185 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
8186 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
8187 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
8189 /* we don't need to track these */
8190 if (dep->semantics == IA64_DVS_NONE)
8191 return 0;
8193 switch (dep->specifier)
8195 case IA64_RS_AR_K:
8196 if (note == 1)
8198 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8200 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8201 if (regno >= 0 && regno <= 7)
8203 specs[count] = tmpl;
8204 specs[count++].index = regno;
8208 else if (note == 0)
8210 for (i = 0; i < 8; i++)
8212 specs[count] = tmpl;
8213 specs[count++].index = i;
8216 else
8218 UNHANDLED;
8220 break;
8222 case IA64_RS_AR_UNAT:
8223 /* This is a mov =AR or mov AR= instruction. */
8224 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8226 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8227 if (regno == AR_UNAT)
8229 specs[count++] = tmpl;
8232 else
8234 /* This is a spill/fill, or other instruction that modifies the
8235 unat register. */
8237 /* Unless we can determine the specific bits used, mark the whole
8238 thing; bits 8:3 of the memory address indicate the bit used in
8239 UNAT. The .mem.offset hint may be used to eliminate a small
8240 subset of conflicts. */
8241 specs[count] = tmpl;
8242 if (md.mem_offset.hint)
8244 if (md.debug_dv)
8245 fprintf (stderr, " Using hint for spill/fill\n");
8246 /* The index isn't actually used, just set it to something
8247 approximating the bit index. */
8248 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
8249 specs[count].mem_offset.hint = 1;
8250 specs[count].mem_offset.offset = md.mem_offset.offset;
8251 specs[count++].mem_offset.base = md.mem_offset.base;
8253 else
8255 specs[count++].specific = 0;
8258 break;
8260 case IA64_RS_AR:
8261 if (note == 1)
8263 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8265 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8266 if ((regno >= 8 && regno <= 15)
8267 || (regno >= 20 && regno <= 23)
8268 || (regno >= 31 && regno <= 39)
8269 || (regno >= 41 && regno <= 47)
8270 || (regno >= 67 && regno <= 111))
8272 specs[count] = tmpl;
8273 specs[count++].index = regno;
8277 else
8279 UNHANDLED;
8281 break;
8283 case IA64_RS_ARb:
8284 if (note == 1)
8286 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
8288 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
8289 if ((regno >= 48 && regno <= 63)
8290 || (regno >= 112 && regno <= 127))
8292 specs[count] = tmpl;
8293 specs[count++].index = regno;
8297 else if (note == 0)
8299 for (i = 48; i < 64; i++)
8301 specs[count] = tmpl;
8302 specs[count++].index = i;
8304 for (i = 112; i < 128; i++)
8306 specs[count] = tmpl;
8307 specs[count++].index = i;
8310 else
8312 UNHANDLED;
8314 break;
8316 case IA64_RS_BR:
8317 if (note != 1)
8319 UNHANDLED;
8321 else
8323 if (rsrc_write)
8325 for (i = 0; i < idesc->num_outputs; i++)
8326 if (idesc->operands[i] == IA64_OPND_B1
8327 || idesc->operands[i] == IA64_OPND_B2)
8329 specs[count] = tmpl;
8330 specs[count++].index =
8331 CURR_SLOT.opnd[i].X_add_number - REG_BR;
8334 else
8336 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8337 if (idesc->operands[i] == IA64_OPND_B1
8338 || idesc->operands[i] == IA64_OPND_B2)
8340 specs[count] = tmpl;
8341 specs[count++].index =
8342 CURR_SLOT.opnd[i].X_add_number - REG_BR;
8346 break;
8348 case IA64_RS_CPUID: /* four or more registers */
8349 if (note == 3)
8351 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
8353 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8354 if (regno >= 0 && regno < NELEMS (gr_values)
8355 && KNOWN (regno))
8357 specs[count] = tmpl;
8358 specs[count++].index = gr_values[regno].value & 0xFF;
8360 else
8362 specs[count] = tmpl;
8363 specs[count++].specific = 0;
8367 else
8369 UNHANDLED;
8371 break;
8373 case IA64_RS_DBR: /* four or more registers */
8374 if (note == 3)
8376 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
8378 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8379 if (regno >= 0 && regno < NELEMS (gr_values)
8380 && KNOWN (regno))
8382 specs[count] = tmpl;
8383 specs[count++].index = gr_values[regno].value & 0xFF;
8385 else
8387 specs[count] = tmpl;
8388 specs[count++].specific = 0;
8392 else if (note == 0 && !rsrc_write)
8394 specs[count] = tmpl;
8395 specs[count++].specific = 0;
8397 else
8399 UNHANDLED;
8401 break;
8403 case IA64_RS_IBR: /* four or more registers */
8404 if (note == 3)
8406 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
8408 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8409 if (regno >= 0 && regno < NELEMS (gr_values)
8410 && KNOWN (regno))
8412 specs[count] = tmpl;
8413 specs[count++].index = gr_values[regno].value & 0xFF;
8415 else
8417 specs[count] = tmpl;
8418 specs[count++].specific = 0;
8422 else
8424 UNHANDLED;
8426 break;
8428 case IA64_RS_MSR:
8429 if (note == 5)
8431 /* These are implementation specific. Force all references to
8432 conflict with all other references. */
8433 specs[count] = tmpl;
8434 specs[count++].specific = 0;
8436 else
8438 UNHANDLED;
8440 break;
8442 case IA64_RS_PKR: /* 16 or more registers */
8443 if (note == 3 || note == 4)
8445 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
8447 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8448 if (regno >= 0 && regno < NELEMS (gr_values)
8449 && KNOWN (regno))
8451 if (note == 3)
8453 specs[count] = tmpl;
8454 specs[count++].index = gr_values[regno].value & 0xFF;
8456 else
8457 for (i = 0; i < NELEMS (gr_values); i++)
8459 /* Uses all registers *except* the one in R3. */
8460 if ((unsigned)i != (gr_values[regno].value & 0xFF))
8462 specs[count] = tmpl;
8463 specs[count++].index = i;
8467 else
8469 specs[count] = tmpl;
8470 specs[count++].specific = 0;
8474 else if (note == 0)
8476 /* probe et al. */
8477 specs[count] = tmpl;
8478 specs[count++].specific = 0;
8480 break;
8482 case IA64_RS_PMC: /* four or more registers */
8483 if (note == 3)
8485 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
8486 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
8489 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
8490 ? 1 : !rsrc_write);
8491 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
8492 if (regno >= 0 && regno < NELEMS (gr_values)
8493 && KNOWN (regno))
8495 specs[count] = tmpl;
8496 specs[count++].index = gr_values[regno].value & 0xFF;
8498 else
8500 specs[count] = tmpl;
8501 specs[count++].specific = 0;
8505 else
8507 UNHANDLED;
8509 break;
8511 case IA64_RS_PMD: /* four or more registers */
8512 if (note == 3)
8514 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
8516 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8517 if (regno >= 0 && regno < NELEMS (gr_values)
8518 && KNOWN (regno))
8520 specs[count] = tmpl;
8521 specs[count++].index = gr_values[regno].value & 0xFF;
8523 else
8525 specs[count] = tmpl;
8526 specs[count++].specific = 0;
8530 else
8532 UNHANDLED;
8534 break;
8536 case IA64_RS_RR: /* eight registers */
8537 if (note == 6)
8539 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
8541 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
8542 if (regno >= 0 && regno < NELEMS (gr_values)
8543 && KNOWN (regno))
8545 specs[count] = tmpl;
8546 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
8548 else
8550 specs[count] = tmpl;
8551 specs[count++].specific = 0;
8555 else if (note == 0 && !rsrc_write)
8557 specs[count] = tmpl;
8558 specs[count++].specific = 0;
8560 else
8562 UNHANDLED;
8564 break;
8566 case IA64_RS_CR_IRR:
8567 if (note == 0)
8569 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
8570 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
8571 if (rsrc_write
8572 && idesc->operands[1] == IA64_OPND_CR3
8573 && regno == CR_IVR)
8575 for (i = 0; i < 4; i++)
8577 specs[count] = tmpl;
8578 specs[count++].index = CR_IRR0 + i;
8582 else if (note == 1)
8584 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8585 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8586 && regno >= CR_IRR0
8587 && regno <= CR_IRR3)
8589 specs[count] = tmpl;
8590 specs[count++].index = regno;
8593 else
8595 UNHANDLED;
8597 break;
8599 case IA64_RS_CR_LRR:
8600 if (note != 1)
8602 UNHANDLED;
8604 else
8606 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8607 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
8608 && (regno == CR_LRR0 || regno == CR_LRR1))
8610 specs[count] = tmpl;
8611 specs[count++].index = regno;
8614 break;
8616 case IA64_RS_CR:
8617 if (note == 1)
8619 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
8621 specs[count] = tmpl;
8622 specs[count++].index =
8623 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
8626 else
8628 UNHANDLED;
8630 break;
8632 case IA64_RS_FR:
8633 case IA64_RS_FRb:
8634 if (note != 1)
8636 UNHANDLED;
8638 else if (rsrc_write)
8640 if (dep->specifier == IA64_RS_FRb
8641 && idesc->operands[0] == IA64_OPND_F1)
8643 specs[count] = tmpl;
8644 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
8647 else
8649 for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++)
8651 if (idesc->operands[i] == IA64_OPND_F2
8652 || idesc->operands[i] == IA64_OPND_F3
8653 || idesc->operands[i] == IA64_OPND_F4)
8655 specs[count] = tmpl;
8656 specs[count++].index =
8657 CURR_SLOT.opnd[i].X_add_number - REG_FR;
8661 break;
8663 case IA64_RS_GR:
8664 if (note == 13)
8666 /* This reference applies only to the GR whose value is loaded with
8667 data returned from memory. */
8668 specs[count] = tmpl;
8669 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
8671 else if (note == 1)
8673 if (rsrc_write)
8675 for (i = 0; i < idesc->num_outputs; i++)
8676 if (idesc->operands[i] == IA64_OPND_R1
8677 || idesc->operands[i] == IA64_OPND_R2
8678 || idesc->operands[i] == IA64_OPND_R3)
8680 specs[count] = tmpl;
8681 specs[count++].index =
8682 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8684 if (idesc->flags & IA64_OPCODE_POSTINC)
8685 for (i = 0; i < NELEMS (idesc->operands); i++)
8686 if (idesc->operands[i] == IA64_OPND_MR3)
8688 specs[count] = tmpl;
8689 specs[count++].index =
8690 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8693 else
8695 /* Look for anything that reads a GR. */
8696 for (i = 0; i < NELEMS (idesc->operands); i++)
8698 if (idesc->operands[i] == IA64_OPND_MR3
8699 || idesc->operands[i] == IA64_OPND_CPUID_R3
8700 || idesc->operands[i] == IA64_OPND_DBR_R3
8701 || idesc->operands[i] == IA64_OPND_IBR_R3
8702 || idesc->operands[i] == IA64_OPND_MSR_R3
8703 || idesc->operands[i] == IA64_OPND_PKR_R3
8704 || idesc->operands[i] == IA64_OPND_PMC_R3
8705 || idesc->operands[i] == IA64_OPND_PMD_R3
8706 || idesc->operands[i] == IA64_OPND_RR_R3
8707 || ((i >= idesc->num_outputs)
8708 && (idesc->operands[i] == IA64_OPND_R1
8709 || idesc->operands[i] == IA64_OPND_R2
8710 || idesc->operands[i] == IA64_OPND_R3
8711 /* addl source register. */
8712 || idesc->operands[i] == IA64_OPND_R3_2)))
8714 specs[count] = tmpl;
8715 specs[count++].index =
8716 CURR_SLOT.opnd[i].X_add_number - REG_GR;
8721 else
8723 UNHANDLED;
8725 break;
8727 /* This is the same as IA64_RS_PRr, except that the register range is
8728 from 1 - 15, and there are no rotating register reads/writes here. */
8729 case IA64_RS_PR:
8730 if (note == 0)
8732 for (i = 1; i < 16; i++)
8734 specs[count] = tmpl;
8735 specs[count++].index = i;
8738 else if (note == 7)
8740 valueT mask = 0;
8741 /* Mark only those registers indicated by the mask. */
8742 if (rsrc_write)
8744 mask = CURR_SLOT.opnd[2].X_add_number;
8745 for (i = 1; i < 16; i++)
8746 if (mask & ((valueT) 1 << i))
8748 specs[count] = tmpl;
8749 specs[count++].index = i;
8752 else
8754 UNHANDLED;
8757 else if (note == 11) /* note 11 implies note 1 as well */
8759 if (rsrc_write)
8761 for (i = 0; i < idesc->num_outputs; i++)
8763 if (idesc->operands[i] == IA64_OPND_P1
8764 || idesc->operands[i] == IA64_OPND_P2)
8766 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8767 if (regno >= 1 && regno < 16)
8769 specs[count] = tmpl;
8770 specs[count++].index = regno;
8775 else
8777 UNHANDLED;
8780 else if (note == 12)
8782 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8784 specs[count] = tmpl;
8785 specs[count++].index = CURR_SLOT.qp_regno;
8788 else if (note == 1)
8790 if (rsrc_write)
8792 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8793 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8794 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8795 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8797 if ((idesc->operands[0] == IA64_OPND_P1
8798 || idesc->operands[0] == IA64_OPND_P2)
8799 && p1 >= 1 && p1 < 16)
8801 specs[count] = tmpl;
8802 specs[count].cmp_type =
8803 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8804 specs[count++].index = p1;
8806 if ((idesc->operands[1] == IA64_OPND_P1
8807 || idesc->operands[1] == IA64_OPND_P2)
8808 && p2 >= 1 && p2 < 16)
8810 specs[count] = tmpl;
8811 specs[count].cmp_type =
8812 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8813 specs[count++].index = p2;
8816 else
8818 if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16)
8820 specs[count] = tmpl;
8821 specs[count++].index = CURR_SLOT.qp_regno;
8823 if (idesc->operands[1] == IA64_OPND_PR)
8825 for (i = 1; i < 16; i++)
8827 specs[count] = tmpl;
8828 specs[count++].index = i;
8833 else
8835 UNHANDLED;
8837 break;
8839 /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are
8840 simplified cases of this. */
8841 case IA64_RS_PRr:
8842 if (note == 0)
8844 for (i = 16; i < 63; i++)
8846 specs[count] = tmpl;
8847 specs[count++].index = i;
8850 else if (note == 7)
8852 valueT mask = 0;
8853 /* Mark only those registers indicated by the mask. */
8854 if (rsrc_write
8855 && idesc->operands[0] == IA64_OPND_PR)
8857 mask = CURR_SLOT.opnd[2].X_add_number;
8858 if (mask & ((valueT) 1 << 16))
8859 for (i = 16; i < 63; i++)
8861 specs[count] = tmpl;
8862 specs[count++].index = i;
8865 else if (rsrc_write
8866 && idesc->operands[0] == IA64_OPND_PR_ROT)
8868 for (i = 16; i < 63; i++)
8870 specs[count] = tmpl;
8871 specs[count++].index = i;
8874 else
8876 UNHANDLED;
8879 else if (note == 11) /* note 11 implies note 1 as well */
8881 if (rsrc_write)
8883 for (i = 0; i < idesc->num_outputs; i++)
8885 if (idesc->operands[i] == IA64_OPND_P1
8886 || idesc->operands[i] == IA64_OPND_P2)
8888 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
8889 if (regno >= 16 && regno < 63)
8891 specs[count] = tmpl;
8892 specs[count++].index = regno;
8897 else
8899 UNHANDLED;
8902 else if (note == 12)
8904 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8906 specs[count] = tmpl;
8907 specs[count++].index = CURR_SLOT.qp_regno;
8910 else if (note == 1)
8912 if (rsrc_write)
8914 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
8915 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
8916 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
8917 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
8919 if ((idesc->operands[0] == IA64_OPND_P1
8920 || idesc->operands[0] == IA64_OPND_P2)
8921 && p1 >= 16 && p1 < 63)
8923 specs[count] = tmpl;
8924 specs[count].cmp_type =
8925 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
8926 specs[count++].index = p1;
8928 if ((idesc->operands[1] == IA64_OPND_P1
8929 || idesc->operands[1] == IA64_OPND_P2)
8930 && p2 >= 16 && p2 < 63)
8932 specs[count] = tmpl;
8933 specs[count].cmp_type =
8934 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
8935 specs[count++].index = p2;
8938 else
8940 if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63)
8942 specs[count] = tmpl;
8943 specs[count++].index = CURR_SLOT.qp_regno;
8945 if (idesc->operands[1] == IA64_OPND_PR)
8947 for (i = 16; i < 63; i++)
8949 specs[count] = tmpl;
8950 specs[count++].index = i;
8955 else
8957 UNHANDLED;
8959 break;
8961 case IA64_RS_PSR:
8962 /* Verify that the instruction is using the PSR bit indicated in
8963 dep->regindex. */
8964 if (note == 0)
8966 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
8968 if (dep->regindex < 6)
8970 specs[count++] = tmpl;
8973 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
8975 if (dep->regindex < 32
8976 || dep->regindex == 35
8977 || dep->regindex == 36
8978 || (!rsrc_write && dep->regindex == PSR_CPL))
8980 specs[count++] = tmpl;
8983 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
8985 if (dep->regindex < 32
8986 || dep->regindex == 35
8987 || dep->regindex == 36
8988 || (rsrc_write && dep->regindex == PSR_CPL))
8990 specs[count++] = tmpl;
8993 else
8995 /* Several PSR bits have very specific dependencies. */
8996 switch (dep->regindex)
8998 default:
8999 specs[count++] = tmpl;
9000 break;
9001 case PSR_IC:
9002 if (rsrc_write)
9004 specs[count++] = tmpl;
9006 else
9008 /* Only certain CR accesses use PSR.ic */
9009 if (idesc->operands[0] == IA64_OPND_CR3
9010 || idesc->operands[1] == IA64_OPND_CR3)
9012 int index =
9013 ((idesc->operands[0] == IA64_OPND_CR3)
9014 ? 0 : 1);
9015 int regno =
9016 CURR_SLOT.opnd[index].X_add_number - REG_CR;
9018 switch (regno)
9020 default:
9021 break;
9022 case CR_ITIR:
9023 case CR_IFS:
9024 case CR_IIM:
9025 case CR_IIP:
9026 case CR_IPSR:
9027 case CR_ISR:
9028 case CR_IFA:
9029 case CR_IHA:
9030 case CR_IIPA:
9031 specs[count++] = tmpl;
9032 break;
9036 break;
9037 case PSR_CPL:
9038 if (rsrc_write)
9040 specs[count++] = tmpl;
9042 else
9044 /* Only some AR accesses use cpl */
9045 if (idesc->operands[0] == IA64_OPND_AR3
9046 || idesc->operands[1] == IA64_OPND_AR3)
9048 int index =
9049 ((idesc->operands[0] == IA64_OPND_AR3)
9050 ? 0 : 1);
9051 int regno =
9052 CURR_SLOT.opnd[index].X_add_number - REG_AR;
9054 if (regno == AR_ITC
9055 || (index == 0
9056 && (regno == AR_ITC
9057 || regno == AR_RSC
9058 || (regno >= AR_K0
9059 && regno <= AR_K7))))
9061 specs[count++] = tmpl;
9064 else
9066 specs[count++] = tmpl;
9068 break;
9073 else if (note == 7)
9075 valueT mask = 0;
9076 if (idesc->operands[0] == IA64_OPND_IMMU24)
9078 mask = CURR_SLOT.opnd[0].X_add_number;
9080 else
9082 UNHANDLED;
9084 if (mask & ((valueT) 1 << dep->regindex))
9086 specs[count++] = tmpl;
9089 else if (note == 8)
9091 int min = dep->regindex == PSR_DFL ? 2 : 32;
9092 int max = dep->regindex == PSR_DFL ? 31 : 127;
9093 /* dfh is read on FR32-127; dfl is read on FR2-31 */
9094 for (i = 0; i < NELEMS (idesc->operands); i++)
9096 if (idesc->operands[i] == IA64_OPND_F1
9097 || idesc->operands[i] == IA64_OPND_F2
9098 || idesc->operands[i] == IA64_OPND_F3
9099 || idesc->operands[i] == IA64_OPND_F4)
9101 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9102 if (reg >= min && reg <= max)
9104 specs[count++] = tmpl;
9109 else if (note == 9)
9111 int min = dep->regindex == PSR_MFL ? 2 : 32;
9112 int max = dep->regindex == PSR_MFL ? 31 : 127;
9113 /* mfh is read on writes to FR32-127; mfl is read on writes to
9114 FR2-31 */
9115 for (i = 0; i < idesc->num_outputs; i++)
9117 if (idesc->operands[i] == IA64_OPND_F1)
9119 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9120 if (reg >= min && reg <= max)
9122 specs[count++] = tmpl;
9127 else if (note == 10)
9129 for (i = 0; i < NELEMS (idesc->operands); i++)
9131 if (idesc->operands[i] == IA64_OPND_R1
9132 || idesc->operands[i] == IA64_OPND_R2
9133 || idesc->operands[i] == IA64_OPND_R3)
9135 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9136 if (regno >= 16 && regno <= 31)
9138 specs[count++] = tmpl;
9143 else
9145 UNHANDLED;
9147 break;
9149 case IA64_RS_AR_FPSR:
9150 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
9152 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
9153 if (regno == AR_FPSR)
9155 specs[count++] = tmpl;
9158 else
9160 specs[count++] = tmpl;
9162 break;
9164 case IA64_RS_ARX:
9165 /* Handle all AR[REG] resources */
9166 if (note == 0 || note == 1)
9168 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
9169 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
9170 && regno == dep->regindex)
9172 specs[count++] = tmpl;
9174 /* other AR[REG] resources may be affected by AR accesses */
9175 else if (idesc->operands[0] == IA64_OPND_AR3)
9177 /* AR[] writes */
9178 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
9179 switch (dep->regindex)
9181 default:
9182 break;
9183 case AR_BSP:
9184 case AR_RNAT:
9185 if (regno == AR_BSPSTORE)
9187 specs[count++] = tmpl;
9189 case AR_RSC:
9190 if (!rsrc_write &&
9191 (regno == AR_BSPSTORE
9192 || regno == AR_RNAT))
9194 specs[count++] = tmpl;
9196 break;
9199 else if (idesc->operands[1] == IA64_OPND_AR3)
9201 /* AR[] reads */
9202 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
9203 switch (dep->regindex)
9205 default:
9206 break;
9207 case AR_RSC:
9208 if (regno == AR_BSPSTORE || regno == AR_RNAT)
9210 specs[count++] = tmpl;
9212 break;
9215 else
9217 specs[count++] = tmpl;
9220 else
9222 UNHANDLED;
9224 break;
9226 case IA64_RS_CRX:
9227 /* Handle all CR[REG] resources */
9228 if (note == 0 || note == 1)
9230 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
9232 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
9233 if (regno == dep->regindex)
9235 specs[count++] = tmpl;
9237 else if (!rsrc_write)
9239 /* Reads from CR[IVR] affect other resources. */
9240 if (regno == CR_IVR)
9242 if ((dep->regindex >= CR_IRR0
9243 && dep->regindex <= CR_IRR3)
9244 || dep->regindex == CR_TPR)
9246 specs[count++] = tmpl;
9251 else
9253 specs[count++] = tmpl;
9256 else
9258 UNHANDLED;
9260 break;
9262 case IA64_RS_INSERVICE:
9263 /* look for write of EOI (67) or read of IVR (65) */
9264 if ((idesc->operands[0] == IA64_OPND_CR3
9265 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
9266 || (idesc->operands[1] == IA64_OPND_CR3
9267 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
9269 specs[count++] = tmpl;
9271 break;
9273 case IA64_RS_GR0:
9274 if (note == 1)
9276 specs[count++] = tmpl;
9278 else
9280 UNHANDLED;
9282 break;
9284 case IA64_RS_CFM:
9285 if (note != 2)
9287 specs[count++] = tmpl;
9289 else
9291 /* Check if any of the registers accessed are in the rotating region.
9292 mov to/from pr accesses CFM only when qp_regno is in the rotating
9293 region */
9294 for (i = 0; i < NELEMS (idesc->operands); i++)
9296 if (idesc->operands[i] == IA64_OPND_R1
9297 || idesc->operands[i] == IA64_OPND_R2
9298 || idesc->operands[i] == IA64_OPND_R3)
9300 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9301 /* Assumes that md.rot.num_regs is always valid */
9302 if (md.rot.num_regs > 0
9303 && num > 31
9304 && num < 31 + md.rot.num_regs)
9306 specs[count] = tmpl;
9307 specs[count++].specific = 0;
9310 else if (idesc->operands[i] == IA64_OPND_F1
9311 || idesc->operands[i] == IA64_OPND_F2
9312 || idesc->operands[i] == IA64_OPND_F3
9313 || idesc->operands[i] == IA64_OPND_F4)
9315 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
9316 if (num > 31)
9318 specs[count] = tmpl;
9319 specs[count++].specific = 0;
9322 else if (idesc->operands[i] == IA64_OPND_P1
9323 || idesc->operands[i] == IA64_OPND_P2)
9325 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
9326 if (num > 15)
9328 specs[count] = tmpl;
9329 specs[count++].specific = 0;
9333 if (CURR_SLOT.qp_regno > 15)
9335 specs[count] = tmpl;
9336 specs[count++].specific = 0;
9339 break;
9341 /* This is the same as IA64_RS_PRr, except simplified to account for
9342 the fact that there is only one register. */
9343 case IA64_RS_PR63:
9344 if (note == 0)
9346 specs[count++] = tmpl;
9348 else if (note == 7)
9350 valueT mask = 0;
9351 if (idesc->operands[2] == IA64_OPND_IMM17)
9352 mask = CURR_SLOT.opnd[2].X_add_number;
9353 if (mask & ((valueT) 1 << 63))
9354 specs[count++] = tmpl;
9356 else if (note == 11)
9358 if ((idesc->operands[0] == IA64_OPND_P1
9359 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
9360 || (idesc->operands[1] == IA64_OPND_P2
9361 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
9363 specs[count++] = tmpl;
9366 else if (note == 12)
9368 if (CURR_SLOT.qp_regno == 63)
9370 specs[count++] = tmpl;
9373 else if (note == 1)
9375 if (rsrc_write)
9377 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9378 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9379 int or_andcm = strstr (idesc->name, "or.andcm") != NULL;
9380 int and_orcm = strstr (idesc->name, "and.orcm") != NULL;
9382 if (p1 == 63
9383 && (idesc->operands[0] == IA64_OPND_P1
9384 || idesc->operands[0] == IA64_OPND_P2))
9386 specs[count] = tmpl;
9387 specs[count++].cmp_type =
9388 (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE));
9390 if (p2 == 63
9391 && (idesc->operands[1] == IA64_OPND_P1
9392 || idesc->operands[1] == IA64_OPND_P2))
9394 specs[count] = tmpl;
9395 specs[count++].cmp_type =
9396 (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE));
9399 else
9401 if (CURR_SLOT.qp_regno == 63)
9403 specs[count++] = tmpl;
9407 else
9409 UNHANDLED;
9411 break;
9413 case IA64_RS_RSE:
9414 /* FIXME we can identify some individual RSE written resources, but RSE
9415 read resources have not yet been completely identified, so for now
9416 treat RSE as a single resource */
9417 if (strncmp (idesc->name, "mov", 3) == 0)
9419 if (rsrc_write)
9421 if (idesc->operands[0] == IA64_OPND_AR3
9422 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
9424 specs[count++] = tmpl;
9427 else
9429 if (idesc->operands[0] == IA64_OPND_AR3)
9431 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
9432 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
9434 specs[count++] = tmpl;
9437 else if (idesc->operands[1] == IA64_OPND_AR3)
9439 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
9440 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
9441 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
9443 specs[count++] = tmpl;
9448 else
9450 specs[count++] = tmpl;
9452 break;
9454 case IA64_RS_ANY:
9455 /* FIXME -- do any of these need to be non-specific? */
9456 specs[count++] = tmpl;
9457 break;
9459 default:
9460 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
9461 break;
9464 return count;
9467 /* Clear branch flags on marked resources. This breaks the link between the
9468 QP of the marking instruction and a subsequent branch on the same QP. */
9470 static void
9471 clear_qp_branch_flag (mask)
9472 valueT mask;
9474 int i;
9475 for (i = 0; i < regdepslen; i++)
9477 valueT bit = ((valueT) 1 << regdeps[i].qp_regno);
9478 if ((bit & mask) != 0)
9480 regdeps[i].link_to_qp_branch = 0;
9485 /* MASK contains 2 and only 2 PRs which are mutually exclusive. Remove
9486 any mutexes which contain one of the PRs and create new ones when
9487 needed. */
9489 static int
9490 update_qp_mutex (valueT mask)
9492 int i;
9493 int add = 0;
9495 i = 0;
9496 while (i < qp_mutexeslen)
9498 if ((qp_mutexes[i].prmask & mask) != 0)
9500 /* If it destroys and creates the same mutex, do nothing. */
9501 if (qp_mutexes[i].prmask == mask
9502 && qp_mutexes[i].path == md.path)
9504 i++;
9505 add = -1;
9507 else
9509 int keep = 0;
9511 if (md.debug_dv)
9513 fprintf (stderr, " Clearing mutex relation");
9514 print_prmask (qp_mutexes[i].prmask);
9515 fprintf (stderr, "\n");
9518 /* Deal with the old mutex with more than 3+ PRs only if
9519 the new mutex on the same execution path with it.
9521 FIXME: The 3+ mutex support is incomplete.
9522 dot_pred_rel () may be a better place to fix it. */
9523 if (qp_mutexes[i].path == md.path)
9525 /* If it is a proper subset of the mutex, create a
9526 new mutex. */
9527 if (add == 0
9528 && (qp_mutexes[i].prmask & mask) == mask)
9529 add = 1;
9531 qp_mutexes[i].prmask &= ~mask;
9532 if (qp_mutexes[i].prmask & (qp_mutexes[i].prmask - 1))
9534 /* Modify the mutex if there are more than one
9535 PR left. */
9536 keep = 1;
9537 i++;
9541 if (keep == 0)
9542 /* Remove the mutex. */
9543 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
9546 else
9547 ++i;
9550 if (add == 1)
9551 add_qp_mutex (mask);
9553 return add;
9556 /* Remove any mutexes which contain any of the PRs indicated in the mask.
9558 Any changes to a PR clears the mutex relations which include that PR. */
9560 static void
9561 clear_qp_mutex (mask)
9562 valueT mask;
9564 int i;
9566 i = 0;
9567 while (i < qp_mutexeslen)
9569 if ((qp_mutexes[i].prmask & mask) != 0)
9571 if (md.debug_dv)
9573 fprintf (stderr, " Clearing mutex relation");
9574 print_prmask (qp_mutexes[i].prmask);
9575 fprintf (stderr, "\n");
9577 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
9579 else
9580 ++i;
9584 /* Clear implies relations which contain PRs in the given masks.
9585 P1_MASK indicates the source of the implies relation, while P2_MASK
9586 indicates the implied PR. */
9588 static void
9589 clear_qp_implies (p1_mask, p2_mask)
9590 valueT p1_mask;
9591 valueT p2_mask;
9593 int i;
9595 i = 0;
9596 while (i < qp_implieslen)
9598 if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0
9599 || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0)
9601 if (md.debug_dv)
9602 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
9603 qp_implies[i].p1, qp_implies[i].p2);
9604 qp_implies[i] = qp_implies[--qp_implieslen];
9606 else
9607 ++i;
9611 /* Add the PRs specified to the list of implied relations. */
9613 static void
9614 add_qp_imply (p1, p2)
9615 int p1, p2;
9617 valueT mask;
9618 valueT bit;
9619 int i;
9621 /* p0 is not meaningful here. */
9622 if (p1 == 0 || p2 == 0)
9623 abort ();
9625 if (p1 == p2)
9626 return;
9628 /* If it exists already, ignore it. */
9629 for (i = 0; i < qp_implieslen; i++)
9631 if (qp_implies[i].p1 == p1
9632 && qp_implies[i].p2 == p2
9633 && qp_implies[i].path == md.path
9634 && !qp_implies[i].p2_branched)
9635 return;
9638 if (qp_implieslen == qp_impliestotlen)
9640 qp_impliestotlen += 20;
9641 qp_implies = (struct qp_imply *)
9642 xrealloc ((void *) qp_implies,
9643 qp_impliestotlen * sizeof (struct qp_imply));
9645 if (md.debug_dv)
9646 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
9647 qp_implies[qp_implieslen].p1 = p1;
9648 qp_implies[qp_implieslen].p2 = p2;
9649 qp_implies[qp_implieslen].path = md.path;
9650 qp_implies[qp_implieslen++].p2_branched = 0;
9652 /* Add in the implied transitive relations; for everything that p2 implies,
9653 make p1 imply that, too; for everything that implies p1, make it imply p2
9654 as well. */
9655 for (i = 0; i < qp_implieslen; i++)
9657 if (qp_implies[i].p1 == p2)
9658 add_qp_imply (p1, qp_implies[i].p2);
9659 if (qp_implies[i].p2 == p1)
9660 add_qp_imply (qp_implies[i].p1, p2);
9662 /* Add in mutex relations implied by this implies relation; for each mutex
9663 relation containing p2, duplicate it and replace p2 with p1. */
9664 bit = (valueT) 1 << p1;
9665 mask = (valueT) 1 << p2;
9666 for (i = 0; i < qp_mutexeslen; i++)
9668 if (qp_mutexes[i].prmask & mask)
9669 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
9673 /* Add the PRs specified in the mask to the mutex list; this means that only
9674 one of the PRs can be true at any time. PR0 should never be included in
9675 the mask. */
9677 static void
9678 add_qp_mutex (mask)
9679 valueT mask;
9681 if (mask & 0x1)
9682 abort ();
9684 if (qp_mutexeslen == qp_mutexestotlen)
9686 qp_mutexestotlen += 20;
9687 qp_mutexes = (struct qpmutex *)
9688 xrealloc ((void *) qp_mutexes,
9689 qp_mutexestotlen * sizeof (struct qpmutex));
9691 if (md.debug_dv)
9693 fprintf (stderr, " Registering mutex on");
9694 print_prmask (mask);
9695 fprintf (stderr, "\n");
9697 qp_mutexes[qp_mutexeslen].path = md.path;
9698 qp_mutexes[qp_mutexeslen++].prmask = mask;
9701 static int
9702 has_suffix_p (name, suffix)
9703 const char *name;
9704 const char *suffix;
9706 size_t namelen = strlen (name);
9707 size_t sufflen = strlen (suffix);
9709 if (namelen <= sufflen)
9710 return 0;
9711 return strcmp (name + namelen - sufflen, suffix) == 0;
9714 static void
9715 clear_register_values ()
9717 int i;
9718 if (md.debug_dv)
9719 fprintf (stderr, " Clearing register values\n");
9720 for (i = 1; i < NELEMS (gr_values); i++)
9721 gr_values[i].known = 0;
9724 /* Keep track of register values/changes which affect DV tracking.
9726 optimization note: should add a flag to classes of insns where otherwise we
9727 have to examine a group of strings to identify them. */
9729 static void
9730 note_register_values (idesc)
9731 struct ia64_opcode *idesc;
9733 valueT qp_changemask = 0;
9734 int i;
9736 /* Invalidate values for registers being written to. */
9737 for (i = 0; i < idesc->num_outputs; i++)
9739 if (idesc->operands[i] == IA64_OPND_R1
9740 || idesc->operands[i] == IA64_OPND_R2
9741 || idesc->operands[i] == IA64_OPND_R3)
9743 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9744 if (regno > 0 && regno < NELEMS (gr_values))
9745 gr_values[regno].known = 0;
9747 else if (idesc->operands[i] == IA64_OPND_R3_2)
9749 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
9750 if (regno > 0 && regno < 4)
9751 gr_values[regno].known = 0;
9753 else if (idesc->operands[i] == IA64_OPND_P1
9754 || idesc->operands[i] == IA64_OPND_P2)
9756 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
9757 qp_changemask |= (valueT) 1 << regno;
9759 else if (idesc->operands[i] == IA64_OPND_PR)
9761 if (idesc->operands[2] & (valueT) 0x10000)
9762 qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2];
9763 else
9764 qp_changemask = idesc->operands[2];
9765 break;
9767 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
9769 if (idesc->operands[1] & ((valueT) 1 << 43))
9770 qp_changemask = -((valueT) 1 << 44) | idesc->operands[1];
9771 else
9772 qp_changemask = idesc->operands[1];
9773 qp_changemask &= ~(valueT) 0xFFFF;
9774 break;
9778 /* Always clear qp branch flags on any PR change. */
9779 /* FIXME there may be exceptions for certain compares. */
9780 clear_qp_branch_flag (qp_changemask);
9782 /* Invalidate rotating registers on insns which affect RRBs in CFM. */
9783 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
9785 qp_changemask |= ~(valueT) 0xFFFF;
9786 if (strcmp (idesc->name, "clrrrb.pr") != 0)
9788 for (i = 32; i < 32 + md.rot.num_regs; i++)
9789 gr_values[i].known = 0;
9791 clear_qp_mutex (qp_changemask);
9792 clear_qp_implies (qp_changemask, qp_changemask);
9794 /* After a call, all register values are undefined, except those marked
9795 as "safe". */
9796 else if (strncmp (idesc->name, "br.call", 6) == 0
9797 || strncmp (idesc->name, "brl.call", 7) == 0)
9799 /* FIXME keep GR values which are marked as "safe_across_calls" */
9800 clear_register_values ();
9801 clear_qp_mutex (~qp_safe_across_calls);
9802 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
9803 clear_qp_branch_flag (~qp_safe_across_calls);
9805 else if (is_interruption_or_rfi (idesc)
9806 || is_taken_branch (idesc))
9808 clear_register_values ();
9809 clear_qp_mutex (~(valueT) 0);
9810 clear_qp_implies (~(valueT) 0, ~(valueT) 0);
9812 /* Look for mutex and implies relations. */
9813 else if ((idesc->operands[0] == IA64_OPND_P1
9814 || idesc->operands[0] == IA64_OPND_P2)
9815 && (idesc->operands[1] == IA64_OPND_P1
9816 || idesc->operands[1] == IA64_OPND_P2))
9818 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
9819 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
9820 valueT p1mask = (p1 != 0) ? (valueT) 1 << p1 : 0;
9821 valueT p2mask = (p2 != 0) ? (valueT) 1 << p2 : 0;
9823 /* If both PRs are PR0, we can't really do anything. */
9824 if (p1 == 0 && p2 == 0)
9826 if (md.debug_dv)
9827 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
9829 /* In general, clear mutexes and implies which include P1 or P2,
9830 with the following exceptions. */
9831 else if (has_suffix_p (idesc->name, ".or.andcm")
9832 || has_suffix_p (idesc->name, ".and.orcm"))
9834 clear_qp_implies (p2mask, p1mask);
9836 else if (has_suffix_p (idesc->name, ".andcm")
9837 || has_suffix_p (idesc->name, ".and"))
9839 clear_qp_implies (0, p1mask | p2mask);
9841 else if (has_suffix_p (idesc->name, ".orcm")
9842 || has_suffix_p (idesc->name, ".or"))
9844 clear_qp_mutex (p1mask | p2mask);
9845 clear_qp_implies (p1mask | p2mask, 0);
9847 else
9849 int added = 0;
9851 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
9853 /* If one of the PRs is PR0, we call clear_qp_mutex. */
9854 if (p1 == 0 || p2 == 0)
9855 clear_qp_mutex (p1mask | p2mask);
9856 else
9857 added = update_qp_mutex (p1mask | p2mask);
9859 if (CURR_SLOT.qp_regno == 0
9860 || has_suffix_p (idesc->name, ".unc"))
9862 if (added == 0 && p1 && p2)
9863 add_qp_mutex (p1mask | p2mask);
9864 if (CURR_SLOT.qp_regno != 0)
9866 if (p1)
9867 add_qp_imply (p1, CURR_SLOT.qp_regno);
9868 if (p2)
9869 add_qp_imply (p2, CURR_SLOT.qp_regno);
9874 /* Look for mov imm insns into GRs. */
9875 else if (idesc->operands[0] == IA64_OPND_R1
9876 && (idesc->operands[1] == IA64_OPND_IMM22
9877 || idesc->operands[1] == IA64_OPND_IMMU64)
9878 && CURR_SLOT.opnd[1].X_op == O_constant
9879 && (strcmp (idesc->name, "mov") == 0
9880 || strcmp (idesc->name, "movl") == 0))
9882 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9883 if (regno > 0 && regno < NELEMS (gr_values))
9885 gr_values[regno].known = 1;
9886 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
9887 gr_values[regno].path = md.path;
9888 if (md.debug_dv)
9890 fprintf (stderr, " Know gr%d = ", regno);
9891 fprintf_vma (stderr, gr_values[regno].value);
9892 fputs ("\n", stderr);
9896 /* Look for dep.z imm insns. */
9897 else if (idesc->operands[0] == IA64_OPND_R1
9898 && idesc->operands[1] == IA64_OPND_IMM8
9899 && strcmp (idesc->name, "dep.z") == 0)
9901 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
9902 if (regno > 0 && regno < NELEMS (gr_values))
9904 valueT value = CURR_SLOT.opnd[1].X_add_number;
9906 if (CURR_SLOT.opnd[3].X_add_number < 64)
9907 value &= ((valueT)1 << CURR_SLOT.opnd[3].X_add_number) - 1;
9908 value <<= CURR_SLOT.opnd[2].X_add_number;
9909 gr_values[regno].known = 1;
9910 gr_values[regno].value = value;
9911 gr_values[regno].path = md.path;
9912 if (md.debug_dv)
9914 fprintf (stderr, " Know gr%d = ", regno);
9915 fprintf_vma (stderr, gr_values[regno].value);
9916 fputs ("\n", stderr);
9920 else
9922 clear_qp_mutex (qp_changemask);
9923 clear_qp_implies (qp_changemask, qp_changemask);
9927 /* Return whether the given predicate registers are currently mutex. */
9929 static int
9930 qp_mutex (p1, p2, path)
9931 int p1;
9932 int p2;
9933 int path;
9935 int i;
9936 valueT mask;
9938 if (p1 != p2)
9940 mask = ((valueT) 1 << p1) | (valueT) 1 << p2;
9941 for (i = 0; i < qp_mutexeslen; i++)
9943 if (qp_mutexes[i].path >= path
9944 && (qp_mutexes[i].prmask & mask) == mask)
9945 return 1;
9948 return 0;
9951 /* Return whether the given resource is in the given insn's list of chks
9952 Return 1 if the conflict is absolutely determined, 2 if it's a potential
9953 conflict. */
9955 static int
9956 resources_match (rs, idesc, note, qp_regno, path)
9957 struct rsrc *rs;
9958 struct ia64_opcode *idesc;
9959 int note;
9960 int qp_regno;
9961 int path;
9963 struct rsrc specs[MAX_SPECS];
9964 int count;
9966 /* If the marked resource's qp_regno and the given qp_regno are mutex,
9967 we don't need to check. One exception is note 11, which indicates that
9968 target predicates are written regardless of PR[qp]. */
9969 if (qp_mutex (rs->qp_regno, qp_regno, path)
9970 && note != 11)
9971 return 0;
9973 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
9974 while (count-- > 0)
9976 /* UNAT checking is a bit more specific than other resources */
9977 if (rs->dependency->specifier == IA64_RS_AR_UNAT
9978 && specs[count].mem_offset.hint
9979 && rs->mem_offset.hint)
9981 if (rs->mem_offset.base == specs[count].mem_offset.base)
9983 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
9984 ((specs[count].mem_offset.offset >> 3) & 0x3F))
9985 return 1;
9986 else
9987 continue;
9991 /* Skip apparent PR write conflicts where both writes are an AND or both
9992 writes are an OR. */
9993 if (rs->dependency->specifier == IA64_RS_PR
9994 || rs->dependency->specifier == IA64_RS_PRr
9995 || rs->dependency->specifier == IA64_RS_PR63)
9997 if (specs[count].cmp_type != CMP_NONE
9998 && specs[count].cmp_type == rs->cmp_type)
10000 if (md.debug_dv)
10001 fprintf (stderr, " %s on parallel compare allowed (PR%d)\n",
10002 dv_mode[rs->dependency->mode],
10003 rs->dependency->specifier != IA64_RS_PR63 ?
10004 specs[count].index : 63);
10005 continue;
10007 if (md.debug_dv)
10008 fprintf (stderr,
10009 " %s on parallel compare conflict %s vs %s on PR%d\n",
10010 dv_mode[rs->dependency->mode],
10011 dv_cmp_type[rs->cmp_type],
10012 dv_cmp_type[specs[count].cmp_type],
10013 rs->dependency->specifier != IA64_RS_PR63 ?
10014 specs[count].index : 63);
10018 /* If either resource is not specific, conservatively assume a conflict
10020 if (!specs[count].specific || !rs->specific)
10021 return 2;
10022 else if (specs[count].index == rs->index)
10023 return 1;
10026 return 0;
10029 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
10030 insert a stop to create the break. Update all resource dependencies
10031 appropriately. If QP_REGNO is non-zero, only apply the break to resources
10032 which use the same QP_REGNO and have the link_to_qp_branch flag set.
10033 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
10034 instruction. */
10036 static void
10037 insn_group_break (insert_stop, qp_regno, save_current)
10038 int insert_stop;
10039 int qp_regno;
10040 int save_current;
10042 int i;
10044 if (insert_stop && md.num_slots_in_use > 0)
10045 PREV_SLOT.end_of_insn_group = 1;
10047 if (md.debug_dv)
10049 fprintf (stderr, " Insn group break%s",
10050 (insert_stop ? " (w/stop)" : ""));
10051 if (qp_regno != 0)
10052 fprintf (stderr, " effective for QP=%d", qp_regno);
10053 fprintf (stderr, "\n");
10056 i = 0;
10057 while (i < regdepslen)
10059 const struct ia64_dependency *dep = regdeps[i].dependency;
10061 if (qp_regno != 0
10062 && regdeps[i].qp_regno != qp_regno)
10064 ++i;
10065 continue;
10068 if (save_current
10069 && CURR_SLOT.src_file == regdeps[i].file
10070 && CURR_SLOT.src_line == regdeps[i].line)
10072 ++i;
10073 continue;
10076 /* clear dependencies which are automatically cleared by a stop, or
10077 those that have reached the appropriate state of insn serialization */
10078 if (dep->semantics == IA64_DVS_IMPLIED
10079 || dep->semantics == IA64_DVS_IMPLIEDF
10080 || regdeps[i].insn_srlz == STATE_SRLZ)
10082 print_dependency ("Removing", i);
10083 regdeps[i] = regdeps[--regdepslen];
10085 else
10087 if (dep->semantics == IA64_DVS_DATA
10088 || dep->semantics == IA64_DVS_INSTR
10089 || dep->semantics == IA64_DVS_SPECIFIC)
10091 if (regdeps[i].insn_srlz == STATE_NONE)
10092 regdeps[i].insn_srlz = STATE_STOP;
10093 if (regdeps[i].data_srlz == STATE_NONE)
10094 regdeps[i].data_srlz = STATE_STOP;
10096 ++i;
10101 /* Add the given resource usage spec to the list of active dependencies. */
10103 static void
10104 mark_resource (idesc, dep, spec, depind, path)
10105 struct ia64_opcode *idesc ATTRIBUTE_UNUSED;
10106 const struct ia64_dependency *dep ATTRIBUTE_UNUSED;
10107 struct rsrc *spec;
10108 int depind;
10109 int path;
10111 if (regdepslen == regdepstotlen)
10113 regdepstotlen += 20;
10114 regdeps = (struct rsrc *)
10115 xrealloc ((void *) regdeps,
10116 regdepstotlen * sizeof (struct rsrc));
10119 regdeps[regdepslen] = *spec;
10120 regdeps[regdepslen].depind = depind;
10121 regdeps[regdepslen].path = path;
10122 regdeps[regdepslen].file = CURR_SLOT.src_file;
10123 regdeps[regdepslen].line = CURR_SLOT.src_line;
10125 print_dependency ("Adding", regdepslen);
10127 ++regdepslen;
10130 static void
10131 print_dependency (action, depind)
10132 const char *action;
10133 int depind;
10135 if (md.debug_dv)
10137 fprintf (stderr, " %s %s '%s'",
10138 action, dv_mode[(regdeps[depind].dependency)->mode],
10139 (regdeps[depind].dependency)->name);
10140 if (regdeps[depind].specific && regdeps[depind].index >= 0)
10141 fprintf (stderr, " (%d)", regdeps[depind].index);
10142 if (regdeps[depind].mem_offset.hint)
10144 fputs (" ", stderr);
10145 fprintf_vma (stderr, regdeps[depind].mem_offset.base);
10146 fputs ("+", stderr);
10147 fprintf_vma (stderr, regdeps[depind].mem_offset.offset);
10149 fprintf (stderr, "\n");
10153 static void
10154 instruction_serialization ()
10156 int i;
10157 if (md.debug_dv)
10158 fprintf (stderr, " Instruction serialization\n");
10159 for (i = 0; i < regdepslen; i++)
10160 if (regdeps[i].insn_srlz == STATE_STOP)
10161 regdeps[i].insn_srlz = STATE_SRLZ;
10164 static void
10165 data_serialization ()
10167 int i = 0;
10168 if (md.debug_dv)
10169 fprintf (stderr, " Data serialization\n");
10170 while (i < regdepslen)
10172 if (regdeps[i].data_srlz == STATE_STOP
10173 /* Note: as of 991210, all "other" dependencies are cleared by a
10174 data serialization. This might change with new tables */
10175 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
10177 print_dependency ("Removing", i);
10178 regdeps[i] = regdeps[--regdepslen];
10180 else
10181 ++i;
10185 /* Insert stops and serializations as needed to avoid DVs. */
10187 static void
10188 remove_marked_resource (rs)
10189 struct rsrc *rs;
10191 switch (rs->dependency->semantics)
10193 case IA64_DVS_SPECIFIC:
10194 if (md.debug_dv)
10195 fprintf (stderr, "Implementation-specific, assume worst case...\n");
10196 /* ...fall through... */
10197 case IA64_DVS_INSTR:
10198 if (md.debug_dv)
10199 fprintf (stderr, "Inserting instr serialization\n");
10200 if (rs->insn_srlz < STATE_STOP)
10201 insn_group_break (1, 0, 0);
10202 if (rs->insn_srlz < STATE_SRLZ)
10204 struct slot oldslot = CURR_SLOT;
10205 /* Manually jam a srlz.i insn into the stream */
10206 memset (&CURR_SLOT, 0, sizeof (CURR_SLOT));
10207 CURR_SLOT.user_template = -1;
10208 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
10209 instruction_serialization ();
10210 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10211 if (++md.num_slots_in_use >= NUM_SLOTS)
10212 emit_one_bundle ();
10213 CURR_SLOT = oldslot;
10215 insn_group_break (1, 0, 0);
10216 break;
10217 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
10218 "other" types of DV are eliminated
10219 by a data serialization */
10220 case IA64_DVS_DATA:
10221 if (md.debug_dv)
10222 fprintf (stderr, "Inserting data serialization\n");
10223 if (rs->data_srlz < STATE_STOP)
10224 insn_group_break (1, 0, 0);
10226 struct slot oldslot = CURR_SLOT;
10227 /* Manually jam a srlz.d insn into the stream */
10228 memset (&CURR_SLOT, 0, sizeof (CURR_SLOT));
10229 CURR_SLOT.user_template = -1;
10230 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
10231 data_serialization ();
10232 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10233 if (++md.num_slots_in_use >= NUM_SLOTS)
10234 emit_one_bundle ();
10235 CURR_SLOT = oldslot;
10237 break;
10238 case IA64_DVS_IMPLIED:
10239 case IA64_DVS_IMPLIEDF:
10240 if (md.debug_dv)
10241 fprintf (stderr, "Inserting stop\n");
10242 insn_group_break (1, 0, 0);
10243 break;
10244 default:
10245 break;
10249 /* Check the resources used by the given opcode against the current dependency
10250 list.
10252 The check is run once for each execution path encountered. In this case,
10253 a unique execution path is the sequence of instructions following a code
10254 entry point, e.g. the following has three execution paths, one starting
10255 at L0, one at L1, and one at L2.
10257 L0: nop
10258 L1: add
10259 L2: add
10260 br.ret
10263 static void
10264 check_dependencies (idesc)
10265 struct ia64_opcode *idesc;
10267 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
10268 int path;
10269 int i;
10271 /* Note that the number of marked resources may change within the
10272 loop if in auto mode. */
10273 i = 0;
10274 while (i < regdepslen)
10276 struct rsrc *rs = &regdeps[i];
10277 const struct ia64_dependency *dep = rs->dependency;
10278 int chkind;
10279 int note;
10280 int start_over = 0;
10282 if (dep->semantics == IA64_DVS_NONE
10283 || (chkind = depends_on (rs->depind, idesc)) == -1)
10285 ++i;
10286 continue;
10289 note = NOTE (opdeps->chks[chkind]);
10291 /* Check this resource against each execution path seen thus far. */
10292 for (path = 0; path <= md.path; path++)
10294 int matchtype;
10296 /* If the dependency wasn't on the path being checked, ignore it. */
10297 if (rs->path < path)
10298 continue;
10300 /* If the QP for this insn implies a QP which has branched, don't
10301 bother checking. Ed. NOTE: I don't think this check is terribly
10302 useful; what's the point of generating code which will only be
10303 reached if its QP is zero?
10304 This code was specifically inserted to handle the following code,
10305 based on notes from Intel's DV checking code, where p1 implies p2.
10307 mov r4 = 2
10308 (p2) br.cond L
10309 (p1) mov r4 = 7
10311 if (CURR_SLOT.qp_regno != 0)
10313 int skip = 0;
10314 int implies;
10315 for (implies = 0; implies < qp_implieslen; implies++)
10317 if (qp_implies[implies].path >= path
10318 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
10319 && qp_implies[implies].p2_branched)
10321 skip = 1;
10322 break;
10325 if (skip)
10326 continue;
10329 if ((matchtype = resources_match (rs, idesc, note,
10330 CURR_SLOT.qp_regno, path)) != 0)
10332 char msg[1024];
10333 char pathmsg[256] = "";
10334 char indexmsg[256] = "";
10335 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
10337 if (path != 0)
10338 sprintf (pathmsg, " when entry is at label '%s'",
10339 md.entry_labels[path - 1]);
10340 if (matchtype == 1 && rs->index >= 0)
10341 sprintf (indexmsg, ", specific resource number is %d",
10342 rs->index);
10343 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
10344 idesc->name,
10345 (certain ? "violates" : "may violate"),
10346 dv_mode[dep->mode], dep->name,
10347 dv_sem[dep->semantics],
10348 pathmsg, indexmsg);
10350 if (md.explicit_mode)
10352 as_warn ("%s", msg);
10353 if (path < md.path)
10354 as_warn (_("Only the first path encountering the conflict "
10355 "is reported"));
10356 as_warn_where (rs->file, rs->line,
10357 _("This is the location of the "
10358 "conflicting usage"));
10359 /* Don't bother checking other paths, to avoid duplicating
10360 the same warning */
10361 break;
10363 else
10365 if (md.debug_dv)
10366 fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
10368 remove_marked_resource (rs);
10370 /* since the set of dependencies has changed, start over */
10371 /* FIXME -- since we're removing dvs as we go, we
10372 probably don't really need to start over... */
10373 start_over = 1;
10374 break;
10378 if (start_over)
10379 i = 0;
10380 else
10381 ++i;
10385 /* Register new dependencies based on the given opcode. */
10387 static void
10388 mark_resources (idesc)
10389 struct ia64_opcode *idesc;
10391 int i;
10392 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
10393 int add_only_qp_reads = 0;
10395 /* A conditional branch only uses its resources if it is taken; if it is
10396 taken, we stop following that path. The other branch types effectively
10397 *always* write their resources. If it's not taken, register only QP
10398 reads. */
10399 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
10401 add_only_qp_reads = 1;
10404 if (md.debug_dv)
10405 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
10407 for (i = 0; i < opdeps->nregs; i++)
10409 const struct ia64_dependency *dep;
10410 struct rsrc specs[MAX_SPECS];
10411 int note;
10412 int path;
10413 int count;
10415 dep = ia64_find_dependency (opdeps->regs[i]);
10416 note = NOTE (opdeps->regs[i]);
10418 if (add_only_qp_reads
10419 && !(dep->mode == IA64_DV_WAR
10420 && (dep->specifier == IA64_RS_PR
10421 || dep->specifier == IA64_RS_PRr
10422 || dep->specifier == IA64_RS_PR63)))
10423 continue;
10425 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
10427 while (count-- > 0)
10429 mark_resource (idesc, dep, &specs[count],
10430 DEP (opdeps->regs[i]), md.path);
10433 /* The execution path may affect register values, which may in turn
10434 affect which indirect-access resources are accessed. */
10435 switch (dep->specifier)
10437 default:
10438 break;
10439 case IA64_RS_CPUID:
10440 case IA64_RS_DBR:
10441 case IA64_RS_IBR:
10442 case IA64_RS_MSR:
10443 case IA64_RS_PKR:
10444 case IA64_RS_PMC:
10445 case IA64_RS_PMD:
10446 case IA64_RS_RR:
10447 for (path = 0; path < md.path; path++)
10449 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
10450 while (count-- > 0)
10451 mark_resource (idesc, dep, &specs[count],
10452 DEP (opdeps->regs[i]), path);
10454 break;
10459 /* Remove dependencies when they no longer apply. */
10461 static void
10462 update_dependencies (idesc)
10463 struct ia64_opcode *idesc;
10465 int i;
10467 if (strcmp (idesc->name, "srlz.i") == 0)
10469 instruction_serialization ();
10471 else if (strcmp (idesc->name, "srlz.d") == 0)
10473 data_serialization ();
10475 else if (is_interruption_or_rfi (idesc)
10476 || is_taken_branch (idesc))
10478 /* Although technically the taken branch doesn't clear dependencies
10479 which require a srlz.[id], we don't follow the branch; the next
10480 instruction is assumed to start with a clean slate. */
10481 regdepslen = 0;
10482 md.path = 0;
10484 else if (is_conditional_branch (idesc)
10485 && CURR_SLOT.qp_regno != 0)
10487 int is_call = strstr (idesc->name, ".call") != NULL;
10489 for (i = 0; i < qp_implieslen; i++)
10491 /* If the conditional branch's predicate is implied by the predicate
10492 in an existing dependency, remove that dependency. */
10493 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
10495 int depind = 0;
10496 /* Note that this implied predicate takes a branch so that if
10497 a later insn generates a DV but its predicate implies this
10498 one, we can avoid the false DV warning. */
10499 qp_implies[i].p2_branched = 1;
10500 while (depind < regdepslen)
10502 if (regdeps[depind].qp_regno == qp_implies[i].p1)
10504 print_dependency ("Removing", depind);
10505 regdeps[depind] = regdeps[--regdepslen];
10507 else
10508 ++depind;
10512 /* Any marked resources which have this same predicate should be
10513 cleared, provided that the QP hasn't been modified between the
10514 marking instruction and the branch. */
10515 if (is_call)
10517 insn_group_break (0, CURR_SLOT.qp_regno, 1);
10519 else
10521 i = 0;
10522 while (i < regdepslen)
10524 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
10525 && regdeps[i].link_to_qp_branch
10526 && (regdeps[i].file != CURR_SLOT.src_file
10527 || regdeps[i].line != CURR_SLOT.src_line))
10529 /* Treat like a taken branch */
10530 print_dependency ("Removing", i);
10531 regdeps[i] = regdeps[--regdepslen];
10533 else
10534 ++i;
10540 /* Examine the current instruction for dependency violations. */
10542 static int
10543 check_dv (idesc)
10544 struct ia64_opcode *idesc;
10546 if (md.debug_dv)
10548 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
10549 idesc->name, CURR_SLOT.src_line,
10550 idesc->dependencies->nchks,
10551 idesc->dependencies->nregs);
10554 /* Look through the list of currently marked resources; if the current
10555 instruction has the dependency in its chks list which uses that resource,
10556 check against the specific resources used. */
10557 check_dependencies (idesc);
10559 /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
10560 then add them to the list of marked resources. */
10561 mark_resources (idesc);
10563 /* There are several types of dependency semantics, and each has its own
10564 requirements for being cleared
10566 Instruction serialization (insns separated by interruption, rfi, or
10567 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
10569 Data serialization (instruction serialization, or writer + srlz.d +
10570 reader, where writer and srlz.d are in separate groups) clears
10571 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
10572 always be the case).
10574 Instruction group break (groups separated by stop, taken branch,
10575 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
10577 update_dependencies (idesc);
10579 /* Sometimes, knowing a register value allows us to avoid giving a false DV
10580 warning. Keep track of as many as possible that are useful. */
10581 note_register_values (idesc);
10583 /* We don't need or want this anymore. */
10584 md.mem_offset.hint = 0;
10586 return 0;
10589 /* Translate one line of assembly. Pseudo ops and labels do not show
10590 here. */
10591 void
10592 md_assemble (str)
10593 char *str;
10595 char *saved_input_line_pointer, *mnemonic;
10596 const struct pseudo_opcode *pdesc;
10597 struct ia64_opcode *idesc;
10598 unsigned char qp_regno;
10599 unsigned int flags;
10600 int ch;
10602 saved_input_line_pointer = input_line_pointer;
10603 input_line_pointer = str;
10605 /* extract the opcode (mnemonic): */
10607 mnemonic = input_line_pointer;
10608 ch = get_symbol_end ();
10609 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
10610 if (pdesc)
10612 *input_line_pointer = ch;
10613 (*pdesc->handler) (pdesc->arg);
10614 goto done;
10617 /* Find the instruction descriptor matching the arguments. */
10619 idesc = ia64_find_opcode (mnemonic);
10620 *input_line_pointer = ch;
10621 if (!idesc)
10623 as_bad ("Unknown opcode `%s'", mnemonic);
10624 goto done;
10627 idesc = parse_operands (idesc);
10628 if (!idesc)
10629 goto done;
10631 /* Handle the dynamic ops we can handle now: */
10632 if (idesc->type == IA64_TYPE_DYN)
10634 if (strcmp (idesc->name, "add") == 0)
10636 if (CURR_SLOT.opnd[2].X_op == O_register
10637 && CURR_SLOT.opnd[2].X_add_number < 4)
10638 mnemonic = "addl";
10639 else
10640 mnemonic = "adds";
10641 ia64_free_opcode (idesc);
10642 idesc = ia64_find_opcode (mnemonic);
10644 else if (strcmp (idesc->name, "mov") == 0)
10646 enum ia64_opnd opnd1, opnd2;
10647 int rop;
10649 opnd1 = idesc->operands[0];
10650 opnd2 = idesc->operands[1];
10651 if (opnd1 == IA64_OPND_AR3)
10652 rop = 0;
10653 else if (opnd2 == IA64_OPND_AR3)
10654 rop = 1;
10655 else
10656 abort ();
10657 if (CURR_SLOT.opnd[rop].X_op == O_register)
10659 if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10660 mnemonic = "mov.i";
10661 else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number))
10662 mnemonic = "mov.m";
10663 else
10664 rop = -1;
10666 else
10667 abort ();
10668 if (rop >= 0)
10670 ia64_free_opcode (idesc);
10671 idesc = ia64_find_opcode (mnemonic);
10672 while (idesc != NULL
10673 && (idesc->operands[0] != opnd1
10674 || idesc->operands[1] != opnd2))
10675 idesc = get_next_opcode (idesc);
10679 else if (strcmp (idesc->name, "mov.i") == 0
10680 || strcmp (idesc->name, "mov.m") == 0)
10682 enum ia64_opnd opnd1, opnd2;
10683 int rop;
10685 opnd1 = idesc->operands[0];
10686 opnd2 = idesc->operands[1];
10687 if (opnd1 == IA64_OPND_AR3)
10688 rop = 0;
10689 else if (opnd2 == IA64_OPND_AR3)
10690 rop = 1;
10691 else
10692 abort ();
10693 if (CURR_SLOT.opnd[rop].X_op == O_register)
10695 char unit = 'a';
10696 if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
10697 unit = 'i';
10698 else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number))
10699 unit = 'm';
10700 if (unit != 'a' && unit != idesc->name [4])
10701 as_bad ("AR %d can only be accessed by %c-unit",
10702 (int) (CURR_SLOT.opnd[rop].X_add_number - REG_AR),
10703 TOUPPER (unit));
10706 else if (strcmp (idesc->name, "hint.b") == 0)
10708 switch (md.hint_b)
10710 case hint_b_ok:
10711 break;
10712 case hint_b_warning:
10713 as_warn ("hint.b may be treated as nop");
10714 break;
10715 case hint_b_error:
10716 as_bad ("hint.b shouldn't be used");
10717 break;
10721 qp_regno = 0;
10722 if (md.qp.X_op == O_register)
10724 qp_regno = md.qp.X_add_number - REG_P;
10725 md.qp.X_op = O_absent;
10728 flags = idesc->flags;
10730 if ((flags & IA64_OPCODE_FIRST) != 0)
10732 /* The alignment frag has to end with a stop bit only if the
10733 next instruction after the alignment directive has to be
10734 the first instruction in an instruction group. */
10735 if (align_frag)
10737 while (align_frag->fr_type != rs_align_code)
10739 align_frag = align_frag->fr_next;
10740 if (!align_frag)
10741 break;
10743 /* align_frag can be NULL if there are directives in
10744 between. */
10745 if (align_frag && align_frag->fr_next == frag_now)
10746 align_frag->tc_frag_data = 1;
10749 insn_group_break (1, 0, 0);
10751 align_frag = NULL;
10753 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
10755 as_bad ("`%s' cannot be predicated", idesc->name);
10756 goto done;
10759 /* Build the instruction. */
10760 CURR_SLOT.qp_regno = qp_regno;
10761 CURR_SLOT.idesc = idesc;
10762 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
10763 dwarf2_where (&CURR_SLOT.debug_line);
10765 /* Add unwind entry, if there is one. */
10766 if (unwind.current_entry)
10768 CURR_SLOT.unwind_record = unwind.current_entry;
10769 unwind.current_entry = NULL;
10771 if (unwind.proc_start && S_IS_DEFINED (unwind.proc_start))
10772 unwind.insn = 1;
10774 /* Check for dependency violations. */
10775 if (md.detect_dv)
10776 check_dv (idesc);
10778 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
10779 if (++md.num_slots_in_use >= NUM_SLOTS)
10780 emit_one_bundle ();
10782 if ((flags & IA64_OPCODE_LAST) != 0)
10783 insn_group_break (1, 0, 0);
10785 md.last_text_seg = now_seg;
10787 done:
10788 input_line_pointer = saved_input_line_pointer;
10791 /* Called when symbol NAME cannot be found in the symbol table.
10792 Should be used for dynamic valued symbols only. */
10794 symbolS *
10795 md_undefined_symbol (name)
10796 char *name ATTRIBUTE_UNUSED;
10798 return 0;
10801 /* Called for any expression that can not be recognized. When the
10802 function is called, `input_line_pointer' will point to the start of
10803 the expression. */
10805 void
10806 md_operand (e)
10807 expressionS *e;
10809 switch (*input_line_pointer)
10811 case '[':
10812 ++input_line_pointer;
10813 expression (e);
10814 if (*input_line_pointer != ']')
10816 as_bad ("Closing bracket missing");
10817 goto err;
10819 else
10821 if (e->X_op != O_register)
10822 as_bad ("Register expected as index");
10824 ++input_line_pointer;
10825 e->X_op = O_index;
10827 break;
10829 default:
10830 break;
10832 return;
10834 err:
10835 ignore_rest_of_line ();
10838 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
10839 a section symbol plus some offset. For relocs involving @fptr(),
10840 directives we don't want such adjustments since we need to have the
10841 original symbol's name in the reloc. */
10843 ia64_fix_adjustable (fix)
10844 fixS *fix;
10846 /* Prevent all adjustments to global symbols */
10847 if (S_IS_EXTERNAL (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
10848 return 0;
10850 switch (fix->fx_r_type)
10852 case BFD_RELOC_IA64_FPTR64I:
10853 case BFD_RELOC_IA64_FPTR32MSB:
10854 case BFD_RELOC_IA64_FPTR32LSB:
10855 case BFD_RELOC_IA64_FPTR64MSB:
10856 case BFD_RELOC_IA64_FPTR64LSB:
10857 case BFD_RELOC_IA64_LTOFF_FPTR22:
10858 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10859 return 0;
10860 default:
10861 break;
10864 return 1;
10868 ia64_force_relocation (fix)
10869 fixS *fix;
10871 switch (fix->fx_r_type)
10873 case BFD_RELOC_IA64_FPTR64I:
10874 case BFD_RELOC_IA64_FPTR32MSB:
10875 case BFD_RELOC_IA64_FPTR32LSB:
10876 case BFD_RELOC_IA64_FPTR64MSB:
10877 case BFD_RELOC_IA64_FPTR64LSB:
10879 case BFD_RELOC_IA64_LTOFF22:
10880 case BFD_RELOC_IA64_LTOFF64I:
10881 case BFD_RELOC_IA64_LTOFF_FPTR22:
10882 case BFD_RELOC_IA64_LTOFF_FPTR64I:
10883 case BFD_RELOC_IA64_PLTOFF22:
10884 case BFD_RELOC_IA64_PLTOFF64I:
10885 case BFD_RELOC_IA64_PLTOFF64MSB:
10886 case BFD_RELOC_IA64_PLTOFF64LSB:
10888 case BFD_RELOC_IA64_LTOFF22X:
10889 case BFD_RELOC_IA64_LDXMOV:
10890 return 1;
10892 default:
10893 break;
10896 return generic_force_reloc (fix);
10899 /* Decide from what point a pc-relative relocation is relative to,
10900 relative to the pc-relative fixup. Er, relatively speaking. */
10901 long
10902 ia64_pcrel_from_section (fix, sec)
10903 fixS *fix;
10904 segT sec;
10906 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
10908 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
10909 off &= ~0xfUL;
10911 return off;
10915 /* Used to emit section-relative relocs for the dwarf2 debug data. */
10916 void
10917 ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
10919 expressionS expr;
10921 expr.X_op = O_pseudo_fixup;
10922 expr.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym;
10923 expr.X_add_number = 0;
10924 expr.X_add_symbol = symbol;
10925 emit_expr (&expr, size);
10928 /* This is called whenever some data item (not an instruction) needs a
10929 fixup. We pick the right reloc code depending on the byteorder
10930 currently in effect. */
10931 void
10932 ia64_cons_fix_new (f, where, nbytes, exp)
10933 fragS *f;
10934 int where;
10935 int nbytes;
10936 expressionS *exp;
10938 bfd_reloc_code_real_type code;
10939 fixS *fix;
10941 switch (nbytes)
10943 /* There are no reloc for 8 and 16 bit quantities, but we allow
10944 them here since they will work fine as long as the expression
10945 is fully defined at the end of the pass over the source file. */
10946 case 1: code = BFD_RELOC_8; break;
10947 case 2: code = BFD_RELOC_16; break;
10948 case 4:
10949 if (target_big_endian)
10950 code = BFD_RELOC_IA64_DIR32MSB;
10951 else
10952 code = BFD_RELOC_IA64_DIR32LSB;
10953 break;
10955 case 8:
10956 /* In 32-bit mode, data8 could mean function descriptors too. */
10957 if (exp->X_op == O_pseudo_fixup
10958 && exp->X_op_symbol
10959 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC
10960 && !(md.flags & EF_IA_64_ABI64))
10962 if (target_big_endian)
10963 code = BFD_RELOC_IA64_IPLTMSB;
10964 else
10965 code = BFD_RELOC_IA64_IPLTLSB;
10966 exp->X_op = O_symbol;
10967 break;
10969 else
10971 if (target_big_endian)
10972 code = BFD_RELOC_IA64_DIR64MSB;
10973 else
10974 code = BFD_RELOC_IA64_DIR64LSB;
10975 break;
10978 case 16:
10979 if (exp->X_op == O_pseudo_fixup
10980 && exp->X_op_symbol
10981 && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC)
10983 if (target_big_endian)
10984 code = BFD_RELOC_IA64_IPLTMSB;
10985 else
10986 code = BFD_RELOC_IA64_IPLTLSB;
10987 exp->X_op = O_symbol;
10988 break;
10990 /* FALLTHRU */
10992 default:
10993 as_bad ("Unsupported fixup size %d", nbytes);
10994 ignore_rest_of_line ();
10995 return;
10998 if (exp->X_op == O_pseudo_fixup)
11000 exp->X_op = O_symbol;
11001 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
11002 /* ??? If code unchanged, unsupported. */
11005 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
11006 /* We need to store the byte order in effect in case we're going
11007 to fix an 8 or 16 bit relocation (for which there no real
11008 relocs available). See md_apply_fix3(). */
11009 fix->tc_fix_data.bigendian = target_big_endian;
11012 /* Return the actual relocation we wish to associate with the pseudo
11013 reloc described by SYM and R_TYPE. SYM should be one of the
11014 symbols in the pseudo_func array, or NULL. */
11016 static bfd_reloc_code_real_type
11017 ia64_gen_real_reloc_type (sym, r_type)
11018 struct symbol *sym;
11019 bfd_reloc_code_real_type r_type;
11021 bfd_reloc_code_real_type new = 0;
11022 const char *type = NULL, *suffix = "";
11024 if (sym == NULL)
11026 return r_type;
11029 switch (S_GET_VALUE (sym))
11031 case FUNC_FPTR_RELATIVE:
11032 switch (r_type)
11034 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
11035 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
11036 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
11037 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
11038 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
11039 default: type = "FPTR"; break;
11041 break;
11043 case FUNC_GP_RELATIVE:
11044 switch (r_type)
11046 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
11047 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
11048 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
11049 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
11050 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
11051 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
11052 default: type = "GPREL"; break;
11054 break;
11056 case FUNC_LT_RELATIVE:
11057 switch (r_type)
11059 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
11060 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
11061 default: type = "LTOFF"; break;
11063 break;
11065 case FUNC_LT_RELATIVE_X:
11066 switch (r_type)
11068 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22X; break;
11069 default: type = "LTOFF"; suffix = "X"; break;
11071 break;
11073 case FUNC_PC_RELATIVE:
11074 switch (r_type)
11076 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PCREL22; break;
11077 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PCREL64I; break;
11078 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_PCREL32MSB; break;
11079 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_PCREL32LSB; break;
11080 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PCREL64MSB; break;
11081 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PCREL64LSB; break;
11082 default: type = "PCREL"; break;
11084 break;
11086 case FUNC_PLT_RELATIVE:
11087 switch (r_type)
11089 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
11090 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
11091 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
11092 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
11093 default: type = "PLTOFF"; break;
11095 break;
11097 case FUNC_SEC_RELATIVE:
11098 switch (r_type)
11100 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
11101 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
11102 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
11103 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
11104 default: type = "SECREL"; break;
11106 break;
11108 case FUNC_SEG_RELATIVE:
11109 switch (r_type)
11111 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
11112 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
11113 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
11114 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
11115 default: type = "SEGREL"; break;
11117 break;
11119 case FUNC_LTV_RELATIVE:
11120 switch (r_type)
11122 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
11123 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
11124 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
11125 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
11126 default: type = "LTV"; break;
11128 break;
11130 case FUNC_LT_FPTR_RELATIVE:
11131 switch (r_type)
11133 case BFD_RELOC_IA64_IMM22:
11134 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
11135 case BFD_RELOC_IA64_IMM64:
11136 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
11137 case BFD_RELOC_IA64_DIR32MSB:
11138 new = BFD_RELOC_IA64_LTOFF_FPTR32MSB; break;
11139 case BFD_RELOC_IA64_DIR32LSB:
11140 new = BFD_RELOC_IA64_LTOFF_FPTR32LSB; break;
11141 case BFD_RELOC_IA64_DIR64MSB:
11142 new = BFD_RELOC_IA64_LTOFF_FPTR64MSB; break;
11143 case BFD_RELOC_IA64_DIR64LSB:
11144 new = BFD_RELOC_IA64_LTOFF_FPTR64LSB; break;
11145 default:
11146 type = "LTOFF_FPTR"; break;
11148 break;
11150 case FUNC_TP_RELATIVE:
11151 switch (r_type)
11153 case BFD_RELOC_IA64_IMM14: new = BFD_RELOC_IA64_TPREL14; break;
11154 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_TPREL22; break;
11155 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_TPREL64I; break;
11156 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_TPREL64MSB; break;
11157 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_TPREL64LSB; break;
11158 default: type = "TPREL"; break;
11160 break;
11162 case FUNC_LT_TP_RELATIVE:
11163 switch (r_type)
11165 case BFD_RELOC_IA64_IMM22:
11166 new = BFD_RELOC_IA64_LTOFF_TPREL22; break;
11167 default:
11168 type = "LTOFF_TPREL"; break;
11170 break;
11172 case FUNC_DTP_MODULE:
11173 switch (r_type)
11175 case BFD_RELOC_IA64_DIR64MSB:
11176 new = BFD_RELOC_IA64_DTPMOD64MSB; break;
11177 case BFD_RELOC_IA64_DIR64LSB:
11178 new = BFD_RELOC_IA64_DTPMOD64LSB; break;
11179 default:
11180 type = "DTPMOD"; break;
11182 break;
11184 case FUNC_LT_DTP_MODULE:
11185 switch (r_type)
11187 case BFD_RELOC_IA64_IMM22:
11188 new = BFD_RELOC_IA64_LTOFF_DTPMOD22; break;
11189 default:
11190 type = "LTOFF_DTPMOD"; break;
11192 break;
11194 case FUNC_DTP_RELATIVE:
11195 switch (r_type)
11197 case BFD_RELOC_IA64_DIR32MSB:
11198 new = BFD_RELOC_IA64_DTPREL32MSB; break;
11199 case BFD_RELOC_IA64_DIR32LSB:
11200 new = BFD_RELOC_IA64_DTPREL32LSB; break;
11201 case BFD_RELOC_IA64_DIR64MSB:
11202 new = BFD_RELOC_IA64_DTPREL64MSB; break;
11203 case BFD_RELOC_IA64_DIR64LSB:
11204 new = BFD_RELOC_IA64_DTPREL64LSB; break;
11205 case BFD_RELOC_IA64_IMM14:
11206 new = BFD_RELOC_IA64_DTPREL14; break;
11207 case BFD_RELOC_IA64_IMM22:
11208 new = BFD_RELOC_IA64_DTPREL22; break;
11209 case BFD_RELOC_IA64_IMM64:
11210 new = BFD_RELOC_IA64_DTPREL64I; break;
11211 default:
11212 type = "DTPREL"; break;
11214 break;
11216 case FUNC_LT_DTP_RELATIVE:
11217 switch (r_type)
11219 case BFD_RELOC_IA64_IMM22:
11220 new = BFD_RELOC_IA64_LTOFF_DTPREL22; break;
11221 default:
11222 type = "LTOFF_DTPREL"; break;
11224 break;
11226 case FUNC_IPLT_RELOC:
11227 switch (r_type)
11229 case BFD_RELOC_IA64_IPLTMSB: return r_type;
11230 case BFD_RELOC_IA64_IPLTLSB: return r_type;
11231 default: type = "IPLT"; break;
11233 break;
11235 default:
11236 abort ();
11239 if (new)
11240 return new;
11241 else
11243 int width;
11245 if (!type)
11246 abort ();
11247 switch (r_type)
11249 case BFD_RELOC_IA64_DIR32MSB: width = 32; suffix = "MSB"; break;
11250 case BFD_RELOC_IA64_DIR32LSB: width = 32; suffix = "LSB"; break;
11251 case BFD_RELOC_IA64_DIR64MSB: width = 64; suffix = "MSB"; break;
11252 case BFD_RELOC_IA64_DIR64LSB: width = 64; suffix = "LSB"; break;
11253 case BFD_RELOC_IA64_IMM14: width = 14; break;
11254 case BFD_RELOC_IA64_IMM22: width = 22; break;
11255 case BFD_RELOC_IA64_IMM64: width = 64; suffix = "I"; break;
11256 default: abort ();
11259 /* This should be an error, but since previously there wasn't any
11260 diagnostic here, dont't make it fail because of this for now. */
11261 as_warn ("Cannot express %s%d%s relocation", type, width, suffix);
11262 return r_type;
11266 /* Here is where generate the appropriate reloc for pseudo relocation
11267 functions. */
11268 void
11269 ia64_validate_fix (fix)
11270 fixS *fix;
11272 switch (fix->fx_r_type)
11274 case BFD_RELOC_IA64_FPTR64I:
11275 case BFD_RELOC_IA64_FPTR32MSB:
11276 case BFD_RELOC_IA64_FPTR64LSB:
11277 case BFD_RELOC_IA64_LTOFF_FPTR22:
11278 case BFD_RELOC_IA64_LTOFF_FPTR64I:
11279 if (fix->fx_offset != 0)
11280 as_bad_where (fix->fx_file, fix->fx_line,
11281 "No addend allowed in @fptr() relocation");
11282 break;
11283 default:
11284 break;
11288 static void
11289 fix_insn (fix, odesc, value)
11290 fixS *fix;
11291 const struct ia64_operand *odesc;
11292 valueT value;
11294 bfd_vma insn[3], t0, t1, control_bits;
11295 const char *err;
11296 char *fixpos;
11297 long slot;
11299 slot = fix->fx_where & 0x3;
11300 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
11302 /* Bundles are always in little-endian byte order */
11303 t0 = bfd_getl64 (fixpos);
11304 t1 = bfd_getl64 (fixpos + 8);
11305 control_bits = t0 & 0x1f;
11306 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
11307 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
11308 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
11310 err = NULL;
11311 if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64)
11313 insn[1] = (value >> 22) & 0x1ffffffffffLL;
11314 insn[2] |= (((value & 0x7f) << 13)
11315 | (((value >> 7) & 0x1ff) << 27)
11316 | (((value >> 16) & 0x1f) << 22)
11317 | (((value >> 21) & 0x1) << 21)
11318 | (((value >> 63) & 0x1) << 36));
11320 else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62)
11322 if (value & ~0x3fffffffffffffffULL)
11323 err = "integer operand out of range";
11324 insn[1] = (value >> 21) & 0x1ffffffffffLL;
11325 insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36));
11327 else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64)
11329 value >>= 4;
11330 insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2;
11331 insn[2] |= ((((value >> 59) & 0x1) << 36)
11332 | (((value >> 0) & 0xfffff) << 13));
11334 else
11335 err = (*odesc->insert) (odesc, value, insn + slot);
11337 if (err)
11338 as_bad_where (fix->fx_file, fix->fx_line, err);
11340 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
11341 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
11342 number_to_chars_littleendian (fixpos + 0, t0, 8);
11343 number_to_chars_littleendian (fixpos + 8, t1, 8);
11346 /* Attempt to simplify or even eliminate a fixup. The return value is
11347 ignored; perhaps it was once meaningful, but now it is historical.
11348 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
11350 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
11351 (if possible). */
11353 void
11354 md_apply_fix3 (fix, valP, seg)
11355 fixS *fix;
11356 valueT *valP;
11357 segT seg ATTRIBUTE_UNUSED;
11359 char *fixpos;
11360 valueT value = *valP;
11362 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
11364 if (fix->fx_pcrel)
11366 switch (fix->fx_r_type)
11368 case BFD_RELOC_IA64_PCREL21B: break;
11369 case BFD_RELOC_IA64_PCREL21BI: break;
11370 case BFD_RELOC_IA64_PCREL21F: break;
11371 case BFD_RELOC_IA64_PCREL21M: break;
11372 case BFD_RELOC_IA64_PCREL60B: break;
11373 case BFD_RELOC_IA64_PCREL22: break;
11374 case BFD_RELOC_IA64_PCREL64I: break;
11375 case BFD_RELOC_IA64_PCREL32MSB: break;
11376 case BFD_RELOC_IA64_PCREL32LSB: break;
11377 case BFD_RELOC_IA64_PCREL64MSB: break;
11378 case BFD_RELOC_IA64_PCREL64LSB: break;
11379 default:
11380 fix->fx_r_type = ia64_gen_real_reloc_type (pseudo_func[FUNC_PC_RELATIVE].u.sym,
11381 fix->fx_r_type);
11382 break;
11385 if (fix->fx_addsy)
11387 switch (fix->fx_r_type)
11389 case BFD_RELOC_UNUSED:
11390 /* This must be a TAG13 or TAG13b operand. There are no external
11391 relocs defined for them, so we must give an error. */
11392 as_bad_where (fix->fx_file, fix->fx_line,
11393 "%s must have a constant value",
11394 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
11395 fix->fx_done = 1;
11396 return;
11398 case BFD_RELOC_IA64_TPREL14:
11399 case BFD_RELOC_IA64_TPREL22:
11400 case BFD_RELOC_IA64_TPREL64I:
11401 case BFD_RELOC_IA64_LTOFF_TPREL22:
11402 case BFD_RELOC_IA64_LTOFF_DTPMOD22:
11403 case BFD_RELOC_IA64_DTPREL14:
11404 case BFD_RELOC_IA64_DTPREL22:
11405 case BFD_RELOC_IA64_DTPREL64I:
11406 case BFD_RELOC_IA64_LTOFF_DTPREL22:
11407 S_SET_THREAD_LOCAL (fix->fx_addsy);
11408 break;
11410 default:
11411 break;
11414 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
11416 if (fix->tc_fix_data.bigendian)
11417 number_to_chars_bigendian (fixpos, value, fix->fx_size);
11418 else
11419 number_to_chars_littleendian (fixpos, value, fix->fx_size);
11420 fix->fx_done = 1;
11422 else
11424 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
11425 fix->fx_done = 1;
11429 /* Generate the BFD reloc to be stuck in the object file from the
11430 fixup used internally in the assembler. */
11432 arelent *
11433 tc_gen_reloc (sec, fixp)
11434 asection *sec ATTRIBUTE_UNUSED;
11435 fixS *fixp;
11437 arelent *reloc;
11439 reloc = xmalloc (sizeof (*reloc));
11440 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
11441 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
11442 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
11443 reloc->addend = fixp->fx_offset;
11444 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
11446 if (!reloc->howto)
11448 as_bad_where (fixp->fx_file, fixp->fx_line,
11449 "Cannot represent %s relocation in object file",
11450 bfd_get_reloc_code_name (fixp->fx_r_type));
11452 return reloc;
11455 /* Turn a string in input_line_pointer into a floating point constant
11456 of type TYPE, and store the appropriate bytes in *LIT. The number
11457 of LITTLENUMS emitted is stored in *SIZE. An error message is
11458 returned, or NULL on OK. */
11460 #define MAX_LITTLENUMS 5
11462 char *
11463 md_atof (type, lit, size)
11464 int type;
11465 char *lit;
11466 int *size;
11468 LITTLENUM_TYPE words[MAX_LITTLENUMS];
11469 char *t;
11470 int prec;
11472 switch (type)
11474 /* IEEE floats */
11475 case 'f':
11476 case 'F':
11477 case 's':
11478 case 'S':
11479 prec = 2;
11480 break;
11482 case 'd':
11483 case 'D':
11484 case 'r':
11485 case 'R':
11486 prec = 4;
11487 break;
11489 case 'x':
11490 case 'X':
11491 case 'p':
11492 case 'P':
11493 prec = 5;
11494 break;
11496 default:
11497 *size = 0;
11498 return "Bad call to MD_ATOF()";
11500 t = atof_ieee (input_line_pointer, type, words);
11501 if (t)
11502 input_line_pointer = t;
11504 (*ia64_float_to_chars) (lit, words, prec);
11506 if (type == 'X')
11508 /* It is 10 byte floating point with 6 byte padding. */
11509 memset (&lit [10], 0, 6);
11510 *size = 8 * sizeof (LITTLENUM_TYPE);
11512 else
11513 *size = prec * sizeof (LITTLENUM_TYPE);
11515 return 0;
11518 /* Handle ia64 specific semantics of the align directive. */
11520 void
11521 ia64_md_do_align (n, fill, len, max)
11522 int n ATTRIBUTE_UNUSED;
11523 const char *fill ATTRIBUTE_UNUSED;
11524 int len ATTRIBUTE_UNUSED;
11525 int max ATTRIBUTE_UNUSED;
11527 if (subseg_text_p (now_seg))
11528 ia64_flush_insns ();
11531 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
11532 of an rs_align_code fragment. */
11534 void
11535 ia64_handle_align (fragp)
11536 fragS *fragp;
11538 int bytes;
11539 char *p;
11540 const unsigned char *nop;
11542 if (fragp->fr_type != rs_align_code)
11543 return;
11545 /* Check if this frag has to end with a stop bit. */
11546 nop = fragp->tc_frag_data ? le_nop_stop : le_nop;
11548 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
11549 p = fragp->fr_literal + fragp->fr_fix;
11551 /* If no paddings are needed, we check if we need a stop bit. */
11552 if (!bytes && fragp->tc_frag_data)
11554 if (fragp->fr_fix < 16)
11555 #if 1
11556 /* FIXME: It won't work with
11557 .align 16
11558 alloc r32=ar.pfs,1,2,4,0
11561 #else
11562 as_bad_where (fragp->fr_file, fragp->fr_line,
11563 _("Can't add stop bit to mark end of instruction group"));
11564 #endif
11565 else
11566 /* Bundles are always in little-endian byte order. Make sure
11567 the previous bundle has the stop bit. */
11568 *(p - 16) |= 1;
11571 /* Make sure we are on a 16-byte boundary, in case someone has been
11572 putting data into a text section. */
11573 if (bytes & 15)
11575 int fix = bytes & 15;
11576 memset (p, 0, fix);
11577 p += fix;
11578 bytes -= fix;
11579 fragp->fr_fix += fix;
11582 /* Instruction bundles are always little-endian. */
11583 memcpy (p, nop, 16);
11584 fragp->fr_var = 16;
11587 static void
11588 ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words,
11589 int prec)
11591 while (prec--)
11593 number_to_chars_bigendian (lit, (long) (*words++),
11594 sizeof (LITTLENUM_TYPE));
11595 lit += sizeof (LITTLENUM_TYPE);
11599 static void
11600 ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words,
11601 int prec)
11603 while (prec--)
11605 number_to_chars_littleendian (lit, (long) (words[prec]),
11606 sizeof (LITTLENUM_TYPE));
11607 lit += sizeof (LITTLENUM_TYPE);
11611 void
11612 ia64_elf_section_change_hook (void)
11614 if (elf_section_type (now_seg) == SHT_IA_64_UNWIND
11615 && elf_linked_to_section (now_seg) == NULL)
11616 elf_linked_to_section (now_seg) = text_section;
11617 dot_byteorder (-1);
11620 /* Check if a label should be made global. */
11621 void
11622 ia64_check_label (symbolS *label)
11624 if (*input_line_pointer == ':')
11626 S_SET_EXTERNAL (label);
11627 input_line_pointer++;
11631 /* Used to remember where .alias and .secalias directives are seen. We
11632 will rename symbol and section names when we are about to output
11633 the relocatable file. */
11634 struct alias
11636 char *file; /* The file where the directive is seen. */
11637 unsigned int line; /* The line number the directive is at. */
11638 const char *name; /* The orignale name of the symbol. */
11641 /* Called for .alias and .secalias directives. If SECTION is 1, it is
11642 .secalias. Otherwise, it is .alias. */
11643 static void
11644 dot_alias (int section)
11646 char *name, *alias;
11647 char delim;
11648 char *end_name;
11649 int len;
11650 const char *error_string;
11651 struct alias *h;
11652 const char *a;
11653 struct hash_control *ahash, *nhash;
11654 const char *kind;
11656 name = input_line_pointer;
11657 delim = get_symbol_end ();
11658 end_name = input_line_pointer;
11659 *end_name = delim;
11661 if (name == end_name)
11663 as_bad (_("expected symbol name"));
11664 discard_rest_of_line ();
11665 return;
11668 SKIP_WHITESPACE ();
11670 if (*input_line_pointer != ',')
11672 *end_name = 0;
11673 as_bad (_("expected comma after \"%s\""), name);
11674 *end_name = delim;
11675 ignore_rest_of_line ();
11676 return;
11679 input_line_pointer++;
11680 *end_name = 0;
11681 ia64_canonicalize_symbol_name (name);
11683 /* We call demand_copy_C_string to check if alias string is valid.
11684 There should be a closing `"' and no `\0' in the string. */
11685 alias = demand_copy_C_string (&len);
11686 if (alias == NULL)
11688 ignore_rest_of_line ();
11689 return;
11692 /* Make a copy of name string. */
11693 len = strlen (name) + 1;
11694 obstack_grow (&notes, name, len);
11695 name = obstack_finish (&notes);
11697 if (section)
11699 kind = "section";
11700 ahash = secalias_hash;
11701 nhash = secalias_name_hash;
11703 else
11705 kind = "symbol";
11706 ahash = alias_hash;
11707 nhash = alias_name_hash;
11710 /* Check if alias has been used before. */
11711 h = (struct alias *) hash_find (ahash, alias);
11712 if (h)
11714 if (strcmp (h->name, name))
11715 as_bad (_("`%s' is already the alias of %s `%s'"),
11716 alias, kind, h->name);
11717 goto out;
11720 /* Check if name already has an alias. */
11721 a = (const char *) hash_find (nhash, name);
11722 if (a)
11724 if (strcmp (a, alias))
11725 as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a);
11726 goto out;
11729 h = (struct alias *) xmalloc (sizeof (struct alias));
11730 as_where (&h->file, &h->line);
11731 h->name = name;
11733 error_string = hash_jam (ahash, alias, (PTR) h);
11734 if (error_string)
11736 as_fatal (_("inserting \"%s\" into %s alias hash table failed: %s"),
11737 alias, kind, error_string);
11738 goto out;
11741 error_string = hash_jam (nhash, name, (PTR) alias);
11742 if (error_string)
11744 as_fatal (_("inserting \"%s\" into %s name hash table failed: %s"),
11745 alias, kind, error_string);
11746 out:
11747 obstack_free (&notes, name);
11748 obstack_free (&notes, alias);
11751 demand_empty_rest_of_line ();
11754 /* It renames the original symbol name to its alias. */
11755 static void
11756 do_alias (const char *alias, PTR value)
11758 struct alias *h = (struct alias *) value;
11759 symbolS *sym = symbol_find (h->name);
11761 if (sym == NULL)
11762 as_warn_where (h->file, h->line,
11763 _("symbol `%s' aliased to `%s' is not used"),
11764 h->name, alias);
11765 else
11766 S_SET_NAME (sym, (char *) alias);
11769 /* Called from write_object_file. */
11770 void
11771 ia64_adjust_symtab (void)
11773 hash_traverse (alias_hash, do_alias);
11776 /* It renames the original section name to its alias. */
11777 static void
11778 do_secalias (const char *alias, PTR value)
11780 struct alias *h = (struct alias *) value;
11781 segT sec = bfd_get_section_by_name (stdoutput, h->name);
11783 if (sec == NULL)
11784 as_warn_where (h->file, h->line,
11785 _("section `%s' aliased to `%s' is not used"),
11786 h->name, alias);
11787 else
11788 sec->name = alias;
11791 /* Called from write_object_file. */
11792 void
11793 ia64_frob_file (void)
11795 hash_traverse (secalias_hash, do_secalias);