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