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