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