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