Unwind info bug fixes from David Mosberger.
[deliverable/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 >> 4, 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, ( ((bfd_vma) 1 << 48) /* version */
2217 | ((bfd_vma) 3 << 32) /* U & E handler flags */
2218 | ((size + extra) / 8)), /* length (dwords) */
2219 8);
2220
2221 process_unw_records (list, output_vbyte_mem);
2222
2223 *ptr = mem;
2224 return size + extra + 16;
2225 }
2226
2227 static void
2228 dot_radix (dummy)
2229 int dummy;
2230 {
2231 int radix;
2232
2233 SKIP_WHITESPACE ();
2234 radix = *input_line_pointer++;
2235
2236 if (radix != 'C' && !is_end_of_line[(unsigned char) radix])
2237 {
2238 as_bad ("Radix `%c' unsupported", *input_line_pointer);
2239 ignore_rest_of_line ();
2240 return;
2241 }
2242 }
2243
2244 /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */
2245 static void
2246 dot_special_section (which)
2247 int which;
2248 {
2249 set_section ((char *) special_section_name[which]);
2250 }
2251
2252 static void
2253 add_unwind_entry (ptr)
2254 unw_rec_list *ptr;
2255 {
2256 if (unwind_tail)
2257 unwind_tail->next = ptr;
2258 else
2259 unwind_list = ptr;
2260 unwind_tail = ptr;
2261
2262 /* The current entry can in fact be a chain of unwind entries. */
2263 if (current_unwind_entry == NULL)
2264 current_unwind_entry = ptr;
2265 }
2266
2267 static void
2268 dot_fframe (dummy)
2269 int dummy;
2270 {
2271 expressionS e;
2272 parse_operand (&e);
2273
2274 if (e.X_op != O_constant)
2275 as_bad ("Operand to .fframe must be a constant");
2276 else
2277 {
2278 add_unwind_entry (output_mem_stack_f (e.X_add_number));
2279 }
2280 }
2281
2282 static void
2283 dot_vframe (dummy)
2284 int dummy;
2285 {
2286 discard_rest_of_line ();
2287 }
2288
2289 static void
2290 dot_save (dummy)
2291 int dummy;
2292 {
2293 expressionS e1, e2;
2294 int sep;
2295 int reg1, reg2;
2296
2297 sep = parse_operand (&e1);
2298 if (sep != ',')
2299 as_bad ("No second operand to .save");
2300 sep = parse_operand (&e2);
2301
2302 reg1 = e1.X_add_number - REG_AR;
2303 reg2 = e2.X_add_number - REG_GR;
2304
2305 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
2306 if (e1.X_op == O_register
2307 && ((reg1 >=0 && reg1 < 128) || reg1 == REG_BR - REG_AR))
2308 {
2309 if (e2.X_op == O_register && reg2 >=0 && reg2 < 128)
2310 {
2311 switch (reg1)
2312 {
2313 case 17: /* ar.bsp */
2314 add_unwind_entry (output_bsp_when ());
2315 add_unwind_entry (output_bsp_gr (reg2));
2316 break;
2317 case 18: /* ar.bspstore */
2318 add_unwind_entry (output_bspstore_when ());
2319 add_unwind_entry (output_bspstore_gr (reg2));
2320 break;
2321 case 19: /* ar.rnat */
2322 add_unwind_entry (output_rnat_when ());
2323 add_unwind_entry (output_rnat_gr (reg2));
2324 break;
2325 case 36: /* ar.unat */
2326 add_unwind_entry (output_unat_when ());
2327 add_unwind_entry (output_unat_gr (reg2));
2328 break;
2329 case 40: /* ar.fpsr */
2330 add_unwind_entry (output_fpsr_when ());
2331 add_unwind_entry (output_fpsr_gr (reg2));
2332 break;
2333 case 64: /* ar.pfs */
2334 add_unwind_entry (output_pfs_when ());
2335 add_unwind_entry (output_pfs_gr (reg2));
2336 break;
2337 case 65: /* ar.lc */
2338 add_unwind_entry (output_lc_when ());
2339 add_unwind_entry (output_lc_gr (reg2));
2340 break;
2341 case REG_BR - REG_AR: /* rp */
2342 add_unwind_entry (output_rp_when ());
2343 add_unwind_entry (output_rp_gr (reg2));
2344 break;
2345 default:
2346 as_bad ("first operand is unknown application register");
2347 }
2348 }
2349 else
2350 as_bad (" Second operand not a valid register");
2351 }
2352 else
2353 as_bad ("First operand not a valid register");
2354 }
2355
2356 static void
2357 dot_restore (dummy)
2358 int dummy;
2359 {
2360 discard_rest_of_line ();
2361 }
2362
2363 static int
2364 generate_unwind_image ()
2365 {
2366 int size;
2367 unsigned char *unw_rec;
2368 int x;
2369
2370 /* Generate the unwind record. */
2371 size = output_unw_records (unwind_list, &unw_rec);
2372 if (size % 4 != 0)
2373 as_bad ("Unwind record is ont a multiple of 4 bytes.");
2374
2375 /* If there are unwind records, switch sections, and output the info. */
2376 if (size != 0)
2377 {
2378 int x;
2379 unsigned char *where;
2380 unsigned char *personality;
2381 expressionS exp;
2382 char *save;
2383 set_section ((char *) special_section_name[SPECIAL_SECTION_UNWIND_INFO]);
2384
2385 /* Set expression which points to start of unwind descriptor area. */
2386 unwind_info = expr_build_dot ();
2387
2388 where = (unsigned char *)frag_more (size);
2389
2390 /* Issue a label for this address, and keep track of it to put it
2391 in the unwind section. */
2392
2393 /* Copy the information from the unwind record into this section. The
2394 data is already in the correct byte order. */
2395 memcpy (where, unw_rec, size);
2396 /* Add the personality address to the image. */
2397 if (personality_routine != 0)
2398 {
2399 exp.X_op = O_symbol;
2400 exp.X_add_symbol = personality_routine;
2401 exp.X_add_number = 0;
2402 fix_new_exp (frag_now, frag_now_fix () - 8, 8,
2403 &exp, 0, BFD_RELOC_IA64_LTOFF_FPTR64LSB);
2404 personality_routine = 0;
2405 }
2406 obj_elf_previous (0);
2407 }
2408
2409 free_list_records (unwind_list);
2410 unwind_list = unwind_tail = current_unwind_entry = NULL;
2411
2412 return size;
2413 }
2414
2415 static void
2416 dot_handlerdata (dummy)
2417 int dummy;
2418 {
2419 generate_unwind_image ();
2420 }
2421
2422 static void
2423 dot_unwentry (dummy)
2424 int dummy;
2425 {
2426 discard_rest_of_line ();
2427 }
2428
2429 static void
2430 dot_altrp (dummy)
2431 int dummy;
2432 {
2433 discard_rest_of_line ();
2434 }
2435
2436 static void
2437 dot_savesp (dummy)
2438 int dummy;
2439 {
2440 expressionS e1, e2;
2441 int sep;
2442 int reg1, val;
2443
2444 sep = parse_operand (&e1);
2445 if (sep != ',')
2446 as_bad ("No second operand to .savesp");
2447 sep = parse_operand (&e2);
2448
2449 reg1 = e1.X_add_number - REG_AR;
2450 val = e2.X_add_number;
2451
2452 /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */
2453 if (e1.X_op == O_register
2454 && ((reg1 >=0 && reg1 < 128) || reg1 == REG_BR - REG_AR || reg1 == REG_PR - REG_AR))
2455 {
2456 if (e2.X_op == O_constant)
2457 {
2458 switch (reg1)
2459 {
2460 case 17: /* ar.bsp */
2461 add_unwind_entry (output_bsp_when ());
2462 add_unwind_entry (output_bsp_sprel (val));
2463 break;
2464 case 18: /* ar.bspstore */
2465 add_unwind_entry (output_bspstore_when ());
2466 add_unwind_entry (output_bspstore_sprel (val));
2467 break;
2468 case 19: /* ar.rnat */
2469 add_unwind_entry (output_rnat_when ());
2470 add_unwind_entry (output_rnat_sprel (val));
2471 break;
2472 case 36: /* ar.unat */
2473 add_unwind_entry (output_unat_when ());
2474 add_unwind_entry (output_unat_sprel (val));
2475 break;
2476 case 40: /* ar.fpsr */
2477 add_unwind_entry (output_fpsr_when ());
2478 add_unwind_entry (output_fpsr_sprel (val));
2479 break;
2480 case 64: /* ar.pfs */
2481 add_unwind_entry (output_pfs_when ());
2482 add_unwind_entry (output_pfs_sprel (val));
2483 break;
2484 case 65: /* ar.lc */
2485 add_unwind_entry (output_lc_when ());
2486 add_unwind_entry (output_lc_sprel (val));
2487 break;
2488 case REG_BR - REG_AR: /* rp */
2489 add_unwind_entry (output_rp_when ());
2490 add_unwind_entry (output_rp_sprel (val));
2491 break;
2492 case REG_PR - REG_AR: /* Predicate registers. */
2493 add_unwind_entry (output_preds_when ());
2494 add_unwind_entry (output_preds_sprel (val));
2495 break;
2496 default:
2497 as_bad ("first operand is unknown application register");
2498 }
2499 }
2500 else
2501 as_bad (" Second operand not a valid constant");
2502 }
2503 else
2504 as_bad ("First operand not a valid register");
2505 }
2506
2507 static void
2508 dot_savepsp (dummy)
2509 int dummy;
2510 {
2511 discard_rest_of_line ();
2512 }
2513
2514 static void
2515 dot_saveg (dummy)
2516 int dummy;
2517 {
2518 expressionS e1, e2;
2519 int sep;
2520 sep = parse_operand (&e1);
2521 if (sep == ',')
2522 parse_operand (&e2);
2523
2524 if (e1.X_op != O_constant)
2525 as_bad ("First operand to .save.g must be a constant.");
2526 else
2527 {
2528 int grmask = e1.X_add_number;
2529 if (sep != ',')
2530 add_unwind_entry (output_gr_mem (grmask));
2531 else
2532 {
2533 int reg = e2.X_add_number - REG_GR;
2534 if (e2.X_op == O_register && reg >=0 && reg < 128)
2535 add_unwind_entry (output_gr_gr (grmask, reg));
2536 else
2537 as_bad ("Second operand is an invalid register.");
2538 }
2539 }
2540 }
2541
2542 static void
2543 dot_savef (dummy)
2544 int dummy;
2545 {
2546 expressionS e1, e2;
2547 int sep;
2548 sep = parse_operand (&e1);
2549
2550 if (e1.X_op != O_constant)
2551 as_bad ("Operand to .save.f must be a constant.");
2552 else
2553 {
2554 int frmask = e1.X_add_number;
2555 add_unwind_entry (output_fr_mem (e1.X_add_number));
2556 }
2557 }
2558
2559 static void
2560 dot_saveb (dummy)
2561 int dummy;
2562 {
2563 expressionS e1;
2564 int sep;
2565 sep = parse_operand (&e1);
2566
2567 if (e1.X_op != O_constant)
2568 as_bad ("Operand to .save.b must be a constant.");
2569 else
2570 {
2571 int brmask = e1.X_add_number;
2572 add_unwind_entry (output_br_mem (brmask));
2573 }
2574 }
2575
2576 static void
2577 dot_savegf (dummy)
2578 int dummy;
2579 {
2580 expressionS e1, e2;
2581 int sep;
2582 sep = parse_operand (&e1);
2583 if (sep == ',')
2584 parse_operand (&e2);
2585
2586 if (e1.X_op != O_constant || sep != ',' || e2.X_op != O_constant)
2587 as_bad ("Both operands of .save.gf must be constants.");
2588 else
2589 {
2590 int grmask = e1.X_add_number;
2591 int frmask = e2.X_add_number;
2592 add_unwind_entry (output_frgr_mem (grmask, frmask));
2593 }
2594 }
2595
2596 static void
2597 dot_spill (dummy)
2598 int dummy;
2599 {
2600 expressionS e;
2601 parse_operand (&e);
2602
2603 if (e.X_op != O_constant)
2604 as_bad ("Operand to .spill must be a constant");
2605 else
2606 {
2607 add_unwind_entry (output_spill_base (e.X_add_number));
2608 }
2609 }
2610
2611 static void
2612 dot_unwabi (dummy)
2613 int dummy;
2614 {
2615 discard_rest_of_line ();
2616 }
2617
2618 static void
2619 dot_personality (dummy)
2620 int dummy;
2621 {
2622 char *name, *p, c;
2623 SKIP_WHITESPACE ();
2624 name = input_line_pointer;
2625 c = get_symbol_end ();
2626 p = input_line_pointer;
2627 personality_routine = symbol_find_or_make (name);
2628 *p = c;
2629 SKIP_WHITESPACE ();
2630 demand_empty_rest_of_line ();
2631 }
2632
2633 static void
2634 dot_proc (dummy)
2635 int dummy;
2636 {
2637 char *name, *p, c;
2638 symbolS *sym;
2639
2640 proc_start = expr_build_dot ();
2641 /* Parse names of main and alternate entry points and mark them s
2642 function symbols: */
2643 while (1)
2644 {
2645 SKIP_WHITESPACE ();
2646 name = input_line_pointer;
2647 c = get_symbol_end ();
2648 p = input_line_pointer;
2649 sym = symbol_find_or_make (name);
2650 if (proc_start == 0)
2651 {
2652 proc_start = sym;
2653 }
2654 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
2655 *p = c;
2656 SKIP_WHITESPACE ();
2657 if (*input_line_pointer != ',')
2658 break;
2659 ++input_line_pointer;
2660 }
2661 demand_empty_rest_of_line ();
2662 ia64_do_align (16);
2663
2664 unwind_list = unwind_tail = current_unwind_entry = NULL;
2665 personality_routine = 0;
2666 }
2667
2668 static void
2669 dot_body (dummy)
2670 int dummy;
2671 {
2672 unwind_prologue = 0;
2673 add_unwind_entry (output_body ());
2674 }
2675
2676 static void
2677 dot_prologue (dummy)
2678 int dummy;
2679 {
2680 unwind_prologue = 1;
2681 SKIP_WHITESPACE ();
2682 if (! is_end_of_line[(unsigned char) *input_line_pointer])
2683 {
2684 expressionS e1, e2;
2685 char sep;
2686 sep = parse_operand (&e1);
2687 if (sep != ',')
2688 as_bad ("No second operand to .prologue");
2689 sep = parse_operand (&e2);
2690
2691 if (e1.X_op == O_constant)
2692 {
2693 if (e2.X_op == O_constant)
2694 {
2695 int mask = e1.X_add_number;
2696 int reg = e2.X_add_number;
2697 add_unwind_entry (output_prologue_gr (mask, reg));
2698 }
2699 else
2700 as_bad ("Second operand not a constant");
2701 }
2702 else
2703 as_bad ("First operand not a constant");
2704 }
2705 else
2706 add_unwind_entry (output_prologue ());
2707 }
2708
2709 static void
2710 dot_endp (dummy)
2711 int dummy;
2712 {
2713 expressionS e;
2714 unsigned char *ptr;
2715 int size;
2716 long where;
2717 segT saved_seg;
2718 subsegT saved_subseg;
2719
2720 saved_seg = now_seg;
2721 saved_subseg = now_subseg;
2722
2723 expression (&e);
2724 demand_empty_rest_of_line ();
2725
2726 insn_group_break (1, 0, 0);
2727 ia64_flush_insns ();
2728
2729 /* If there was a .handlerdata, we haven't generated an image yet. */
2730 if (unwind_info == 0)
2731 {
2732 generate_unwind_image ();
2733 }
2734
2735 subseg_set (md.last_text_seg, 0);
2736 proc_end = expr_build_dot ();
2737
2738 set_section ((char *) special_section_name[SPECIAL_SECTION_UNWIND]);
2739 ptr = frag_more (24);
2740 where = frag_now_fix () - 24;
2741
2742 /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */
2743 e.X_op = O_pseudo_fixup;
2744 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
2745 e.X_add_number = 0;
2746 e.X_add_symbol = proc_start;
2747 ia64_cons_fix_new (frag_now, where, 8, &e);
2748
2749 e.X_op = O_pseudo_fixup;
2750 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
2751 e.X_add_number = 0;
2752 e.X_add_symbol = proc_end;
2753 ia64_cons_fix_new (frag_now, where + 8, 8, &e);
2754
2755 if (unwind_info != 0)
2756 {
2757 e.X_op = O_pseudo_fixup;
2758 e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym;
2759 e.X_add_number = 0;
2760 e.X_add_symbol = unwind_info;
2761 ia64_cons_fix_new (frag_now, where + 16, 8, &e);
2762 }
2763 else
2764 md_number_to_chars (ptr + 16, 0, 8);
2765
2766 subseg_set (saved_seg, saved_subseg);
2767 proc_start = proc_end = unwind_info = 0;
2768 }
2769
2770 static void
2771 dot_template (template)
2772 int template;
2773 {
2774 CURR_SLOT.user_template = template;
2775 }
2776
2777 static void
2778 dot_regstk (dummy)
2779 int dummy;
2780 {
2781 int ins, locs, outs, rots;
2782
2783 if (is_it_end_of_statement ())
2784 ins = locs = outs = rots = 0;
2785 else
2786 {
2787 ins = get_absolute_expression ();
2788 if (*input_line_pointer++ != ',')
2789 goto err;
2790 locs = get_absolute_expression ();
2791 if (*input_line_pointer++ != ',')
2792 goto err;
2793 outs = get_absolute_expression ();
2794 if (*input_line_pointer++ != ',')
2795 goto err;
2796 rots = get_absolute_expression ();
2797 }
2798 set_regstack (ins, locs, outs, rots);
2799 return;
2800
2801 err:
2802 as_bad ("Comma expected");
2803 ignore_rest_of_line ();
2804 }
2805
2806 static void
2807 dot_rot (type)
2808 int type;
2809 {
2810 unsigned num_regs, num_alloced = 0;
2811 struct dynreg **drpp, *dr;
2812 int ch, base_reg = 0;
2813 char *name, *start;
2814 size_t len;
2815
2816 switch (type)
2817 {
2818 case DYNREG_GR: base_reg = REG_GR + 32; break;
2819 case DYNREG_FR: base_reg = REG_FR + 32; break;
2820 case DYNREG_PR: base_reg = REG_P + 16; break;
2821 default: break;
2822 }
2823
2824 /* first, remove existing names from hash table: */
2825 for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next)
2826 {
2827 hash_delete (md.dynreg_hash, dr->name);
2828 dr->num_regs = 0;
2829 }
2830
2831 drpp = &md.dynreg[type];
2832 while (1)
2833 {
2834 start = input_line_pointer;
2835 ch = get_symbol_end ();
2836 *input_line_pointer = ch;
2837 len = (input_line_pointer - start);
2838
2839 SKIP_WHITESPACE ();
2840 if (*input_line_pointer != '[')
2841 {
2842 as_bad ("Expected '['");
2843 goto err;
2844 }
2845 ++input_line_pointer; /* skip '[' */
2846
2847 num_regs = get_absolute_expression ();
2848
2849 if (*input_line_pointer++ != ']')
2850 {
2851 as_bad ("Expected ']'");
2852 goto err;
2853 }
2854 SKIP_WHITESPACE ();
2855
2856 num_alloced += num_regs;
2857 switch (type)
2858 {
2859 case DYNREG_GR:
2860 if (num_alloced > md.rot.num_regs)
2861 {
2862 as_bad ("Used more than the declared %d rotating registers",
2863 md.rot.num_regs);
2864 goto err;
2865 }
2866 break;
2867 case DYNREG_FR:
2868 if (num_alloced > 96)
2869 {
2870 as_bad ("Used more than the available 96 rotating registers");
2871 goto err;
2872 }
2873 break;
2874 case DYNREG_PR:
2875 if (num_alloced > 48)
2876 {
2877 as_bad ("Used more than the available 48 rotating registers");
2878 goto err;
2879 }
2880 break;
2881
2882 default:
2883 break;
2884 }
2885
2886 name = obstack_alloc (&notes, len + 1);
2887 memcpy (name, start, len);
2888 name[len] = '\0';
2889
2890 if (!*drpp)
2891 {
2892 *drpp = obstack_alloc (&notes, sizeof (*dr));
2893 memset (*drpp, 0, sizeof (*dr));
2894 }
2895
2896 dr = *drpp;
2897 dr->name = name;
2898 dr->num_regs = num_regs;
2899 dr->base = base_reg;
2900 drpp = &dr->next;
2901 base_reg += num_regs;
2902
2903 if (hash_insert (md.dynreg_hash, name, dr))
2904 {
2905 as_bad ("Attempt to redefine register set `%s'", name);
2906 goto err;
2907 }
2908
2909 if (*input_line_pointer != ',')
2910 break;
2911 ++input_line_pointer; /* skip comma */
2912 SKIP_WHITESPACE ();
2913 }
2914 demand_empty_rest_of_line ();
2915 return;
2916
2917 err:
2918 ignore_rest_of_line ();
2919 }
2920
2921 static void
2922 dot_byteorder (byteorder)
2923 int byteorder;
2924 {
2925 target_big_endian = byteorder;
2926 }
2927
2928 static void
2929 dot_psr (dummy)
2930 int dummy;
2931 {
2932 char *option;
2933 int ch;
2934
2935 while (1)
2936 {
2937 option = input_line_pointer;
2938 ch = get_symbol_end ();
2939 if (strcmp (option, "lsb") == 0)
2940 md.flags &= ~EF_IA_64_BE;
2941 else if (strcmp (option, "msb") == 0)
2942 md.flags |= EF_IA_64_BE;
2943 else if (strcmp (option, "abi32") == 0)
2944 md.flags &= ~EF_IA_64_ABI64;
2945 else if (strcmp (option, "abi64") == 0)
2946 md.flags |= EF_IA_64_ABI64;
2947 else
2948 as_bad ("Unknown psr option `%s'", option);
2949 *input_line_pointer = ch;
2950
2951 SKIP_WHITESPACE ();
2952 if (*input_line_pointer != ',')
2953 break;
2954
2955 ++input_line_pointer;
2956 SKIP_WHITESPACE ();
2957 }
2958 demand_empty_rest_of_line ();
2959 }
2960
2961 static void
2962 dot_alias (dummy)
2963 int dummy;
2964 {
2965 as_bad (".alias not implemented yet");
2966 }
2967
2968 static void
2969 dot_ln (dummy)
2970 int dummy;
2971 {
2972 new_logical_line (0, get_absolute_expression ());
2973 demand_empty_rest_of_line ();
2974 }
2975
2976 static char*
2977 parse_section_name ()
2978 {
2979 char *name;
2980 int len;
2981
2982 SKIP_WHITESPACE ();
2983 if (*input_line_pointer != '"')
2984 {
2985 as_bad ("Missing section name");
2986 ignore_rest_of_line ();
2987 return 0;
2988 }
2989 name = demand_copy_C_string (&len);
2990 if (!name)
2991 {
2992 ignore_rest_of_line ();
2993 return 0;
2994 }
2995 SKIP_WHITESPACE ();
2996 if (*input_line_pointer != ',')
2997 {
2998 as_bad ("Comma expected after section name");
2999 ignore_rest_of_line ();
3000 return 0;
3001 }
3002 ++input_line_pointer; /* skip comma */
3003 return name;
3004 }
3005
3006 static void
3007 dot_xdata (size)
3008 int size;
3009 {
3010 char *name = parse_section_name ();
3011 if (!name)
3012 return;
3013
3014 set_section (name);
3015 cons (size);
3016 obj_elf_previous (0);
3017 }
3018
3019 /* Why doesn't float_cons() call md_cons_align() the way cons() does? */
3020 static void
3021 stmt_float_cons (kind)
3022 int kind;
3023 {
3024 size_t size;
3025
3026 switch (kind)
3027 {
3028 case 'd': size = 8; break;
3029 case 'x': size = 10; break;
3030
3031 case 'f':
3032 default:
3033 size = 4;
3034 break;
3035 }
3036 ia64_do_align (size);
3037 float_cons (kind);
3038 }
3039
3040 static void
3041 stmt_cons_ua (size)
3042 int size;
3043 {
3044 int saved_auto_align = md.auto_align;
3045
3046 md.auto_align = 0;
3047 cons (size);
3048 md.auto_align = saved_auto_align;
3049 }
3050
3051 static void
3052 dot_xfloat_cons (kind)
3053 int kind;
3054 {
3055 char *name = parse_section_name ();
3056 if (!name)
3057 return;
3058
3059 set_section (name);
3060 stmt_float_cons (kind);
3061 obj_elf_previous (0);
3062 }
3063
3064 static void
3065 dot_xstringer (zero)
3066 int zero;
3067 {
3068 char *name = parse_section_name ();
3069 if (!name)
3070 return;
3071
3072 set_section (name);
3073 stringer (zero);
3074 obj_elf_previous (0);
3075 }
3076
3077 static void
3078 dot_xdata_ua (size)
3079 int size;
3080 {
3081 int saved_auto_align = md.auto_align;
3082 char *name = parse_section_name ();
3083 if (!name)
3084 return;
3085
3086 set_section (name);
3087 md.auto_align = 0;
3088 cons (size);
3089 md.auto_align = saved_auto_align;
3090 obj_elf_previous (0);
3091 }
3092
3093 static void
3094 dot_xfloat_cons_ua (kind)
3095 int kind;
3096 {
3097 int saved_auto_align = md.auto_align;
3098 char *name = parse_section_name ();
3099 if (!name)
3100 return;
3101
3102 set_section (name);
3103 md.auto_align = 0;
3104 stmt_float_cons (kind);
3105 md.auto_align = saved_auto_align;
3106 obj_elf_previous (0);
3107 }
3108
3109 /* .reg.val <regname>,value */
3110 static void
3111 dot_reg_val (dummy)
3112 int dummy;
3113 {
3114 expressionS reg;
3115
3116 expression (&reg);
3117 if (reg.X_op != O_register)
3118 {
3119 as_bad (_("Register name expected"));
3120 ignore_rest_of_line ();
3121 }
3122 else if (*input_line_pointer++ != ',')
3123 {
3124 as_bad (_("Comma expected"));
3125 ignore_rest_of_line ();
3126 }
3127 else
3128 {
3129 valueT value = get_absolute_expression ();
3130 int regno = reg.X_add_number;
3131 if (regno < REG_GR || regno > REG_GR+128)
3132 as_warn (_("Register value annotation ignored"));
3133 else
3134 {
3135 gr_values[regno-REG_GR].known = 1;
3136 gr_values[regno-REG_GR].value = value;
3137 gr_values[regno-REG_GR].path = md.path;
3138 }
3139 }
3140 demand_empty_rest_of_line ();
3141 }
3142
3143 /* select dv checking mode
3144 .auto
3145 .explicit
3146 .default
3147
3148 A stop is inserted when changing modes
3149 */
3150 static void
3151 dot_dv_mode (type)
3152 int type;
3153 {
3154 if (md.manual_bundling)
3155 as_warn (_("Directive invalid within a bundle"));
3156
3157 if (type == 'E' || type == 'A')
3158 md.mode_explicitly_set = 0;
3159 else
3160 md.mode_explicitly_set = 1;
3161
3162 md.detect_dv = 1;
3163 switch (type)
3164 {
3165 case 'A':
3166 case 'a':
3167 if (md.explicit_mode)
3168 insn_group_break (1, 0, 0);
3169 md.explicit_mode = 0;
3170 break;
3171 case 'E':
3172 case 'e':
3173 if (!md.explicit_mode)
3174 insn_group_break (1, 0, 0);
3175 md.explicit_mode = 1;
3176 break;
3177 default:
3178 case 'd':
3179 if (md.explicit_mode != md.default_explicit_mode)
3180 insn_group_break (1, 0, 0);
3181 md.explicit_mode = md.default_explicit_mode;
3182 md.mode_explicitly_set = 0;
3183 break;
3184 }
3185 }
3186
3187 static void
3188 print_prmask (mask)
3189 valueT mask;
3190 {
3191 int regno;
3192 char *comma = "";
3193 for (regno = 0;regno < 64;regno++)
3194 {
3195 if (mask & ((valueT)1<<regno))
3196 {
3197 fprintf (stderr, "%s p%d", comma, regno);
3198 comma = ",";
3199 }
3200 }
3201 }
3202
3203 /*
3204 .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear")
3205 .pred.rel.imply p1, p2 (also .pred.rel "imply")
3206 .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex")
3207 .pred.safe_across_calls p1 [, p2 [,...]]
3208 */
3209 static void
3210 dot_pred_rel (type)
3211 int type;
3212 {
3213 valueT mask = 0;
3214 int count = 0;
3215 int p1 = -1, p2 = -1;
3216
3217 if (type == 0)
3218 {
3219 if (*input_line_pointer != '"')
3220 {
3221 as_bad (_("Missing predicate relation type"));
3222 ignore_rest_of_line ();
3223 return;
3224 }
3225 else
3226 {
3227 int len;
3228 char *form = demand_copy_C_string (&len);
3229 if (strcmp (form, "mutex") == 0)
3230 type = 'm';
3231 else if (strcmp (form, "clear") == 0)
3232 type = 'c';
3233 else if (strcmp (form, "imply") == 0)
3234 type = 'i';
3235 else
3236 {
3237 as_bad (_("Unrecognized predicate relation type"));
3238 ignore_rest_of_line ();
3239 return;
3240 }
3241 }
3242 if (*input_line_pointer == ',')
3243 ++input_line_pointer;
3244 SKIP_WHITESPACE ();
3245 }
3246
3247 SKIP_WHITESPACE ();
3248 while (1)
3249 {
3250 valueT bit = 1;
3251 int regno;
3252
3253 if (toupper (*input_line_pointer) != 'P'
3254 || (regno = atoi (++input_line_pointer)) < 0
3255 || regno > 63)
3256 {
3257 as_bad (_("Predicate register expected"));
3258 ignore_rest_of_line ();
3259 return;
3260 }
3261 while (isdigit (*input_line_pointer))
3262 ++input_line_pointer;
3263 if (p1 == -1)
3264 p1 = regno;
3265 else if (p2 == -1)
3266 p2 = regno;
3267 bit <<= regno;
3268 if (mask & bit)
3269 as_warn (_("Duplicate predicate register ignored"));
3270 mask |= bit; count++;
3271 /* see if it's a range */
3272 if (*input_line_pointer == '-')
3273 {
3274 valueT stop = 1;
3275 ++input_line_pointer;
3276
3277 if (toupper (*input_line_pointer) != 'P'
3278 || (regno = atoi (++input_line_pointer)) < 0
3279 || regno > 63)
3280 {
3281 as_bad (_("Predicate register expected"));
3282 ignore_rest_of_line ();
3283 return;
3284 }
3285 while (isdigit (*input_line_pointer))
3286 ++input_line_pointer;
3287 stop <<= regno;
3288 if (bit >= stop)
3289 {
3290 as_bad (_("Bad register range"));
3291 ignore_rest_of_line ();
3292 return;
3293 }
3294 while (bit < stop)
3295 {
3296 bit <<= 1;
3297 mask |= bit; count++;
3298 }
3299 SKIP_WHITESPACE ();
3300 }
3301 if (*input_line_pointer != ',')
3302 break;
3303 ++input_line_pointer;
3304 SKIP_WHITESPACE ();
3305 }
3306
3307 switch (type)
3308 {
3309 case 'c':
3310 if (count == 0)
3311 mask = ~(valueT)0;
3312 clear_qp_mutex (mask);
3313 clear_qp_implies (mask, (valueT)0);
3314 break;
3315 case 'i':
3316 if (count != 2 || p1 == -1 || p2 == -1)
3317 as_bad (_("Predicate source and target required"));
3318 else if (p1 == 0 || p2 == 0)
3319 as_bad (_("Use of p0 is not valid in this context"));
3320 else
3321 add_qp_imply (p1, p2);
3322 break;
3323 case 'm':
3324 if (count < 2)
3325 {
3326 as_bad (_("At least two PR arguments expected"));
3327 break;
3328 }
3329 else if (mask & 1)
3330 {
3331 as_bad (_("Use of p0 is not valid in this context"));
3332 break;
3333 }
3334 add_qp_mutex (mask);
3335 break;
3336 case 's':
3337 /* note that we don't override any existing relations */
3338 if (count == 0)
3339 {
3340 as_bad (_("At least one PR argument expected"));
3341 break;
3342 }
3343 if (md.debug_dv)
3344 {
3345 fprintf (stderr, "Safe across calls: ");
3346 print_prmask (mask);
3347 fprintf (stderr, "\n");
3348 }
3349 qp_safe_across_calls = mask;
3350 break;
3351 }
3352 demand_empty_rest_of_line ();
3353 }
3354
3355 /* .entry label [, label [, ...]]
3356 Hint to DV code that the given labels are to be considered entry points.
3357 Otherwise, only global labels are considered entry points.
3358 */
3359 static void
3360 dot_entry (dummy)
3361 int dummy;
3362 {
3363 const char *err;
3364 char *name;
3365 int c;
3366 symbolS *symbolP;
3367
3368 do
3369 {
3370 name = input_line_pointer;
3371 c = get_symbol_end ();
3372 symbolP = symbol_find_or_make (name);
3373
3374 err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (PTR) symbolP);
3375 if (err)
3376 as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"),
3377 name, err);
3378
3379 *input_line_pointer = c;
3380 SKIP_WHITESPACE ();
3381 c = *input_line_pointer;
3382 if (c == ',')
3383 {
3384 input_line_pointer++;
3385 SKIP_WHITESPACE ();
3386 if (*input_line_pointer == '\n')
3387 c = '\n';
3388 }
3389 }
3390 while (c == ',');
3391
3392 demand_empty_rest_of_line ();
3393 }
3394
3395 /* .mem.offset offset, base
3396 "base" is used to distinguish between offsets from a different base.
3397 */
3398 static void
3399 dot_mem_offset (dummy)
3400 int dummy;
3401 {
3402 md.mem_offset.hint = 1;
3403 md.mem_offset.offset = get_absolute_expression ();
3404 if (*input_line_pointer != ',')
3405 {
3406 as_bad (_("Comma expected"));
3407 ignore_rest_of_line ();
3408 return;
3409 }
3410 ++input_line_pointer;
3411 md.mem_offset.base = get_absolute_expression ();
3412 demand_empty_rest_of_line ();
3413 }
3414
3415 /* ia64-specific pseudo-ops: */
3416 const pseudo_typeS md_pseudo_table[] =
3417 {
3418 { "radix", dot_radix, 0 },
3419 { "lcomm", s_lcomm_bytes, 1 },
3420 { "bss", dot_special_section, SPECIAL_SECTION_BSS },
3421 { "sbss", dot_special_section, SPECIAL_SECTION_SBSS },
3422 { "sdata", dot_special_section, SPECIAL_SECTION_SDATA },
3423 { "rodata", dot_special_section, SPECIAL_SECTION_RODATA },
3424 { "comment", dot_special_section, SPECIAL_SECTION_COMMENT },
3425 { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND },
3426 { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO },
3427 { "proc", dot_proc, 0 },
3428 { "body", dot_body, 0 },
3429 { "prologue", dot_prologue, 0 },
3430 { "endp", dot_endp },
3431 { "file", dwarf2_directive_file },
3432 { "loc", dwarf2_directive_loc },
3433
3434 { "fframe", dot_fframe },
3435 { "vframe", dot_vframe },
3436 { "save", dot_save },
3437 { "restore", dot_restore },
3438 { "handlerdata", dot_handlerdata },
3439 { "unwentry", dot_unwentry },
3440 { "alprp", dot_altrp },
3441 { "savesp", dot_savesp },
3442 { "savepsp", dot_savepsp },
3443 { "save.g", dot_saveg },
3444 { "save.f", dot_savef },
3445 { "save.b", dot_saveb },
3446 { "save.gf", dot_savegf },
3447 { "spill", dot_spill },
3448 { "unwabi", dot_unwabi },
3449 { "personality", dot_personality },
3450 #if 0
3451 { "estate", dot_estate },
3452 #endif
3453 { "mii", dot_template, 0x0 },
3454 { "mli", dot_template, 0x2 }, /* old format, for compatibility */
3455 { "mlx", dot_template, 0x2 },
3456 { "mmi", dot_template, 0x4 },
3457 { "mfi", dot_template, 0x6 },
3458 { "mmf", dot_template, 0x7 },
3459 { "mib", dot_template, 0x8 },
3460 { "mbb", dot_template, 0x9 },
3461 { "bbb", dot_template, 0xb },
3462 { "mmb", dot_template, 0xc },
3463 { "mfb", dot_template, 0xe },
3464 #if 0
3465 { "lb", dot_scope, 0 },
3466 { "le", dot_scope, 1 },
3467 #endif
3468 { "align", s_align_bytes, 0 },
3469 { "regstk", dot_regstk, 0 },
3470 { "rotr", dot_rot, DYNREG_GR },
3471 { "rotf", dot_rot, DYNREG_FR },
3472 { "rotp", dot_rot, DYNREG_PR },
3473 { "lsb", dot_byteorder, 0 },
3474 { "msb", dot_byteorder, 1 },
3475 { "psr", dot_psr, 0 },
3476 { "alias", dot_alias, 0 },
3477 { "ln", dot_ln, 0 }, /* source line info (for debugging) */
3478
3479 { "xdata1", dot_xdata, 1 },
3480 { "xdata2", dot_xdata, 2 },
3481 { "xdata4", dot_xdata, 4 },
3482 { "xdata8", dot_xdata, 8 },
3483 { "xreal4", dot_xfloat_cons, 'f' },
3484 { "xreal8", dot_xfloat_cons, 'd' },
3485 { "xreal10", dot_xfloat_cons, 'x' },
3486 { "xstring", dot_xstringer, 0 },
3487 { "xstringz", dot_xstringer, 1 },
3488
3489 /* unaligned versions: */
3490 { "xdata2.ua", dot_xdata_ua, 2 },
3491 { "xdata4.ua", dot_xdata_ua, 4 },
3492 { "xdata8.ua", dot_xdata_ua, 8 },
3493 { "xreal4.ua", dot_xfloat_cons_ua, 'f' },
3494 { "xreal8.ua", dot_xfloat_cons_ua, 'd' },
3495 { "xreal10.ua", dot_xfloat_cons_ua, 'x' },
3496
3497 /* annotations/DV checking support */
3498 { "entry", dot_entry, 0 },
3499 { "mem.offset", dot_mem_offset },
3500 { "pred.rel", dot_pred_rel, 0 },
3501 { "pred.rel.clear", dot_pred_rel, 'c' },
3502 { "pred.rel.imply", dot_pred_rel, 'i' },
3503 { "pred.rel.mutex", dot_pred_rel, 'm' },
3504 { "pred.safe_across_calls", dot_pred_rel, 's' },
3505 { "reg.val", dot_reg_val },
3506 { "auto", dot_dv_mode, 'a' },
3507 { "explicit", dot_dv_mode, 'e' },
3508 { "default", dot_dv_mode, 'd' },
3509
3510 { NULL, 0, 0 }
3511 };
3512
3513 static const struct pseudo_opcode
3514 {
3515 const char *name;
3516 void (*handler) (int);
3517 int arg;
3518 }
3519 pseudo_opcode[] =
3520 {
3521 /* these are more like pseudo-ops, but don't start with a dot */
3522 { "data1", cons, 1 },
3523 { "data2", cons, 2 },
3524 { "data4", cons, 4 },
3525 { "data8", cons, 8 },
3526 { "real4", stmt_float_cons, 'f' },
3527 { "real8", stmt_float_cons, 'd' },
3528 { "real10", stmt_float_cons, 'x' },
3529 { "string", stringer, 0 },
3530 { "stringz", stringer, 1 },
3531
3532 /* unaligned versions: */
3533 { "data2.ua", stmt_cons_ua, 2 },
3534 { "data4.ua", stmt_cons_ua, 4 },
3535 { "data8.ua", stmt_cons_ua, 8 },
3536 { "real4.ua", float_cons, 'f' },
3537 { "real8.ua", float_cons, 'd' },
3538 { "real10.ua", float_cons, 'x' },
3539 };
3540
3541 /* Declare a register by creating a symbol for it and entering it in
3542 the symbol table. */
3543 static symbolS*
3544 declare_register (name, regnum)
3545 const char *name;
3546 int regnum;
3547 {
3548 const char *err;
3549 symbolS *sym;
3550
3551 sym = symbol_new (name, reg_section, regnum, &zero_address_frag);
3552
3553 err = hash_insert (md.reg_hash, S_GET_NAME (sym), (PTR) sym);
3554 if (err)
3555 as_fatal ("Inserting \"%s\" into register table failed: %s",
3556 name, err);
3557
3558 return sym;
3559 }
3560
3561 static void
3562 declare_register_set (prefix, num_regs, base_regnum)
3563 const char *prefix;
3564 int num_regs;
3565 int base_regnum;
3566 {
3567 char name[8];
3568 int i;
3569
3570 for (i = 0; i < num_regs; ++i)
3571 {
3572 sprintf (name, "%s%u", prefix, i);
3573 declare_register (name, base_regnum + i);
3574 }
3575 }
3576
3577 static unsigned int
3578 operand_width (opnd)
3579 enum ia64_opnd opnd;
3580 {
3581 const struct ia64_operand *odesc = &elf64_ia64_operands[opnd];
3582 unsigned int bits = 0;
3583 int i;
3584
3585 bits = 0;
3586 for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i)
3587 bits += odesc->field[i].bits;
3588
3589 return bits;
3590 }
3591
3592 static int
3593 operand_match (idesc, index, e)
3594 const struct ia64_opcode *idesc;
3595 int index;
3596 expressionS *e;
3597 {
3598 enum ia64_opnd opnd = idesc->operands[index];
3599 int bits, relocatable = 0;
3600 struct insn_fix *fix;
3601 bfd_signed_vma val;
3602
3603 switch (opnd)
3604 {
3605 /* constants: */
3606
3607 case IA64_OPND_AR_CCV:
3608 if (e->X_op == O_register && e->X_add_number == REG_AR + 32)
3609 return 1;
3610 break;
3611
3612 case IA64_OPND_AR_PFS:
3613 if (e->X_op == O_register && e->X_add_number == REG_AR + 64)
3614 return 1;
3615 break;
3616
3617 case IA64_OPND_GR0:
3618 if (e->X_op == O_register && e->X_add_number == REG_GR + 0)
3619 return 1;
3620 break;
3621
3622 case IA64_OPND_IP:
3623 if (e->X_op == O_register && e->X_add_number == REG_IP)
3624 return 1;
3625 break;
3626
3627 case IA64_OPND_PR:
3628 if (e->X_op == O_register && e->X_add_number == REG_PR)
3629 return 1;
3630 break;
3631
3632 case IA64_OPND_PR_ROT:
3633 if (e->X_op == O_register && e->X_add_number == REG_PR_ROT)
3634 return 1;
3635 break;
3636
3637 case IA64_OPND_PSR:
3638 if (e->X_op == O_register && e->X_add_number == REG_PSR)
3639 return 1;
3640 break;
3641
3642 case IA64_OPND_PSR_L:
3643 if (e->X_op == O_register && e->X_add_number == REG_PSR_L)
3644 return 1;
3645 break;
3646
3647 case IA64_OPND_PSR_UM:
3648 if (e->X_op == O_register && e->X_add_number == REG_PSR_UM)
3649 return 1;
3650 break;
3651
3652 case IA64_OPND_C1:
3653 if (e->X_op == O_constant && e->X_add_number == 1)
3654 return 1;
3655 break;
3656
3657 case IA64_OPND_C8:
3658 if (e->X_op == O_constant && e->X_add_number == 8)
3659 return 1;
3660 break;
3661
3662 case IA64_OPND_C16:
3663 if (e->X_op == O_constant && e->X_add_number == 16)
3664 return 1;
3665 break;
3666
3667 /* register operands: */
3668
3669 case IA64_OPND_AR3:
3670 if (e->X_op == O_register && e->X_add_number >= REG_AR
3671 && e->X_add_number < REG_AR + 128)
3672 return 1;
3673 break;
3674
3675 case IA64_OPND_B1:
3676 case IA64_OPND_B2:
3677 if (e->X_op == O_register && e->X_add_number >= REG_BR
3678 && e->X_add_number < REG_BR + 8)
3679 return 1;
3680 break;
3681
3682 case IA64_OPND_CR3:
3683 if (e->X_op == O_register && e->X_add_number >= REG_CR
3684 && e->X_add_number < REG_CR + 128)
3685 return 1;
3686 break;
3687
3688 case IA64_OPND_F1:
3689 case IA64_OPND_F2:
3690 case IA64_OPND_F3:
3691 case IA64_OPND_F4:
3692 if (e->X_op == O_register && e->X_add_number >= REG_FR
3693 && e->X_add_number < REG_FR + 128)
3694 return 1;
3695 break;
3696
3697 case IA64_OPND_P1:
3698 case IA64_OPND_P2:
3699 if (e->X_op == O_register && e->X_add_number >= REG_P
3700 && e->X_add_number < REG_P + 64)
3701 return 1;
3702 break;
3703
3704 case IA64_OPND_R1:
3705 case IA64_OPND_R2:
3706 case IA64_OPND_R3:
3707 if (e->X_op == O_register && e->X_add_number >= REG_GR
3708 && e->X_add_number < REG_GR + 128)
3709 return 1;
3710 break;
3711
3712 case IA64_OPND_R3_2:
3713 if (e->X_op == O_register && e->X_add_number >= REG_GR
3714 && e->X_add_number < REG_GR + 4)
3715 return 1;
3716 break;
3717
3718 /* indirect operands: */
3719 case IA64_OPND_CPUID_R3:
3720 case IA64_OPND_DBR_R3:
3721 case IA64_OPND_DTR_R3:
3722 case IA64_OPND_ITR_R3:
3723 case IA64_OPND_IBR_R3:
3724 case IA64_OPND_MSR_R3:
3725 case IA64_OPND_PKR_R3:
3726 case IA64_OPND_PMC_R3:
3727 case IA64_OPND_PMD_R3:
3728 case IA64_OPND_RR_R3:
3729 if (e->X_op == O_index && e->X_op_symbol
3730 && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID
3731 == opnd - IA64_OPND_CPUID_R3))
3732 return 1;
3733 break;
3734
3735 case IA64_OPND_MR3:
3736 if (e->X_op == O_index && !e->X_op_symbol)
3737 return 1;
3738 break;
3739
3740 /* immediate operands: */
3741 case IA64_OPND_CNT2a:
3742 case IA64_OPND_LEN4:
3743 case IA64_OPND_LEN6:
3744 bits = operand_width (idesc->operands[index]);
3745 if (e->X_op == O_constant
3746 && (bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits))
3747 return 1;
3748 break;
3749
3750 case IA64_OPND_CNT2b:
3751 if (e->X_op == O_constant
3752 && (bfd_vma) (e->X_add_number - 1) < 3)
3753 return 1;
3754 break;
3755
3756 case IA64_OPND_CNT2c:
3757 val = e->X_add_number;
3758 if (e->X_op == O_constant
3759 && (val == 0 || val == 7 || val == 15 || val == 16))
3760 return 1;
3761 break;
3762
3763 case IA64_OPND_SOR:
3764 /* SOR must be an integer multiple of 8 */
3765 if (e->X_add_number & 0x7)
3766 break;
3767 case IA64_OPND_SOF:
3768 case IA64_OPND_SOL:
3769 if (e->X_op == O_constant &&
3770 (bfd_vma) e->X_add_number <= 96)
3771 return 1;
3772 break;
3773
3774 case IA64_OPND_IMMU62:
3775 if (e->X_op == O_constant)
3776 {
3777 if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62))
3778 return 1;
3779 }
3780 else
3781 {
3782 /* FIXME -- need 62-bit relocation type */
3783 as_bad (_("62-bit relocation not yet implemented"));
3784 }
3785 break;
3786
3787 case IA64_OPND_IMMU64:
3788 if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup
3789 || e->X_op == O_subtract)
3790 {
3791 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
3792 fix->code = BFD_RELOC_IA64_IMM64;
3793 if (e->X_op != O_subtract)
3794 {
3795 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
3796 if (e->X_op == O_pseudo_fixup)
3797 e->X_op = O_symbol;
3798 }
3799
3800 fix->opnd = idesc->operands[index];
3801 fix->expr = *e;
3802 fix->is_pcrel = 0;
3803 ++CURR_SLOT.num_fixups;
3804 return 1;
3805 }
3806 else if (e->X_op == O_constant)
3807 return 1;
3808 break;
3809
3810 case IA64_OPND_CCNT5:
3811 case IA64_OPND_CNT5:
3812 case IA64_OPND_CNT6:
3813 case IA64_OPND_CPOS6a:
3814 case IA64_OPND_CPOS6b:
3815 case IA64_OPND_CPOS6c:
3816 case IA64_OPND_IMMU2:
3817 case IA64_OPND_IMMU7a:
3818 case IA64_OPND_IMMU7b:
3819 case IA64_OPND_IMMU21:
3820 case IA64_OPND_IMMU24:
3821 case IA64_OPND_MBTYPE4:
3822 case IA64_OPND_MHTYPE8:
3823 case IA64_OPND_POS6:
3824 bits = operand_width (idesc->operands[index]);
3825 if (e->X_op == O_constant
3826 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
3827 return 1;
3828 break;
3829
3830 case IA64_OPND_IMMU9:
3831 bits = operand_width (idesc->operands[index]);
3832 if (e->X_op == O_constant
3833 && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits))
3834 {
3835 int lobits = e->X_add_number & 0x3;
3836 if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0)
3837 e->X_add_number |= (bfd_vma)0x3;
3838 return 1;
3839 }
3840 break;
3841
3842 case IA64_OPND_IMM44:
3843 /* least 16 bits must be zero */
3844 if ((e->X_add_number & 0xffff) != 0)
3845 as_warn (_("lower 16 bits of mask ignored"));
3846
3847 if (e->X_op == O_constant
3848 && ((e->X_add_number >= 0
3849 && e->X_add_number < ((bfd_vma) 1 << 44))
3850 || (e->X_add_number < 0
3851 && -e->X_add_number <= ((bfd_vma) 1 << 44))))
3852 {
3853 /* sign-extend */
3854 if (e->X_add_number >= 0
3855 && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0)
3856 {
3857 e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1);
3858 }
3859 return 1;
3860 }
3861 break;
3862
3863 case IA64_OPND_IMM17:
3864 /* bit 0 is a don't care (pr0 is hardwired to 1) */
3865 if (e->X_op == O_constant
3866 && ((e->X_add_number >= 0
3867 && e->X_add_number < ((bfd_vma) 1 << 17))
3868 || (e->X_add_number < 0
3869 && -e->X_add_number <= ((bfd_vma) 1 << 17))))
3870 {
3871 /* sign-extend */
3872 if (e->X_add_number >= 0
3873 && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0)
3874 {
3875 e->X_add_number |= ~(((bfd_vma)1 << 17) - 1);
3876 }
3877 return 1;
3878 }
3879 break;
3880
3881 case IA64_OPND_IMM14:
3882 case IA64_OPND_IMM22:
3883 relocatable = 1;
3884 case IA64_OPND_IMM1:
3885 case IA64_OPND_IMM8:
3886 case IA64_OPND_IMM8U4:
3887 case IA64_OPND_IMM8M1:
3888 case IA64_OPND_IMM8M1U4:
3889 case IA64_OPND_IMM8M1U8:
3890 case IA64_OPND_IMM9a:
3891 case IA64_OPND_IMM9b:
3892 bits = operand_width (idesc->operands[index]);
3893 if (relocatable && (e->X_op == O_symbol
3894 || e->X_op == O_subtract
3895 || e->X_op == O_pseudo_fixup))
3896 {
3897 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
3898
3899 if (idesc->operands[index] == IA64_OPND_IMM14)
3900 fix->code = BFD_RELOC_IA64_IMM14;
3901 else
3902 fix->code = BFD_RELOC_IA64_IMM22;
3903
3904 if (e->X_op != O_subtract)
3905 {
3906 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
3907 if (e->X_op == O_pseudo_fixup)
3908 e->X_op = O_symbol;
3909 }
3910
3911 fix->opnd = idesc->operands[index];
3912 fix->expr = *e;
3913 fix->is_pcrel = 0;
3914 ++CURR_SLOT.num_fixups;
3915 return 1;
3916 }
3917 else if (e->X_op != O_constant
3918 && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8))
3919 return 0;
3920
3921 if (opnd == IA64_OPND_IMM8M1U4)
3922 {
3923 /* Zero is not valid for unsigned compares that take an adjusted
3924 constant immediate range. */
3925 if (e->X_add_number == 0)
3926 return 0;
3927
3928 /* Sign-extend 32-bit unsigned numbers, so that the following range
3929 checks will work. */
3930 val = e->X_add_number;
3931 if (((val & (~(bfd_vma)0 << 32)) == 0)
3932 && ((val & ((bfd_vma)1 << 31)) != 0))
3933 val = ((val << 32) >> 32);
3934
3935 /* Check for 0x100000000. This is valid because
3936 0x100000000-1 is the same as ((uint32_t) -1). */
3937 if (val == ((bfd_signed_vma) 1 << 32))
3938 return 1;
3939
3940 val = val - 1;
3941 }
3942 else if (opnd == IA64_OPND_IMM8M1U8)
3943 {
3944 /* Zero is not valid for unsigned compares that take an adjusted
3945 constant immediate range. */
3946 if (e->X_add_number == 0)
3947 return 0;
3948
3949 /* Check for 0x10000000000000000. */
3950 if (e->X_op == O_big)
3951 {
3952 if (generic_bignum[0] == 0
3953 && generic_bignum[1] == 0
3954 && generic_bignum[2] == 0
3955 && generic_bignum[3] == 0
3956 && generic_bignum[4] == 1)
3957 return 1;
3958 else
3959 return 0;
3960 }
3961 else
3962 val = e->X_add_number - 1;
3963 }
3964 else if (opnd == IA64_OPND_IMM8M1)
3965 val = e->X_add_number - 1;
3966 else if (opnd == IA64_OPND_IMM8U4)
3967 {
3968 /* Sign-extend 32-bit unsigned numbers, so that the following range
3969 checks will work. */
3970 val = e->X_add_number;
3971 if (((val & (~(bfd_vma)0 << 32)) == 0)
3972 && ((val & ((bfd_vma)1 << 31)) != 0))
3973 val = ((val << 32) >> 32);
3974 }
3975 else
3976 val = e->X_add_number;
3977
3978 if ((val >= 0 && val < ((bfd_vma) 1 << (bits - 1)))
3979 || (val < 0 && -val <= ((bfd_vma) 1 << (bits - 1))))
3980 return 1;
3981 break;
3982
3983 case IA64_OPND_INC3:
3984 /* +/- 1, 4, 8, 16 */
3985 val = e->X_add_number;
3986 if (val < 0)
3987 val = -val;
3988 if (e->X_op == O_constant
3989 && (val == 1 || val == 4 || val == 8 || val == 16))
3990 return 1;
3991 break;
3992
3993 case IA64_OPND_TGT25:
3994 case IA64_OPND_TGT25b:
3995 case IA64_OPND_TGT25c:
3996 case IA64_OPND_TGT64:
3997 if (e->X_op == O_symbol)
3998 {
3999 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
4000 if (opnd == IA64_OPND_TGT25)
4001 fix->code = BFD_RELOC_IA64_PCREL21F;
4002 else if (opnd == IA64_OPND_TGT25b)
4003 fix->code = BFD_RELOC_IA64_PCREL21M;
4004 else if (opnd == IA64_OPND_TGT25c)
4005 fix->code = BFD_RELOC_IA64_PCREL21B;
4006 else
4007 /* FIXME -- use appropriate relocation type */
4008 as_bad (_("long branch targets not implemented"));
4009 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code);
4010 fix->opnd = idesc->operands[index];
4011 fix->expr = *e;
4012 fix->is_pcrel = 1;
4013 ++CURR_SLOT.num_fixups;
4014 return 1;
4015 }
4016 case IA64_OPND_TAG13:
4017 case IA64_OPND_TAG13b:
4018 switch (e->X_op)
4019 {
4020 case O_constant:
4021 return 1;
4022
4023 case O_symbol:
4024 fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups;
4025 fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, 0);
4026 fix->opnd = idesc->operands[index];
4027 fix->expr = *e;
4028 fix->is_pcrel = 1;
4029 ++CURR_SLOT.num_fixups;
4030 return 1;
4031
4032 default:
4033 break;
4034 }
4035 break;
4036
4037 default:
4038 break;
4039 }
4040 return 0;
4041 }
4042
4043 static int
4044 parse_operand (e)
4045 expressionS *e;
4046 {
4047 int sep = '\0';
4048
4049 memset (e, 0, sizeof (*e));
4050 e->X_op = O_absent;
4051 SKIP_WHITESPACE ();
4052 if (*input_line_pointer != '}')
4053 expression (e);
4054 sep = *input_line_pointer++;
4055
4056 if (sep == '}')
4057 {
4058 if (!md.manual_bundling)
4059 as_warn ("Found '}' when manual bundling is off");
4060 else
4061 CURR_SLOT.manual_bundling_off = 1;
4062 md.manual_bundling = 0;
4063 sep = '\0';
4064 }
4065 return sep;
4066 }
4067
4068 /* Returns the next entry in the opcode table that matches the one in
4069 IDESC, and frees the entry in IDESC. If no matching entry is
4070 found, NULL is returned instead. */
4071
4072 static struct ia64_opcode *
4073 get_next_opcode (struct ia64_opcode *idesc)
4074 {
4075 struct ia64_opcode *next = ia64_find_next_opcode (idesc);
4076 ia64_free_opcode (idesc);
4077 return next;
4078 }
4079
4080 /* Parse the operands for the opcode and find the opcode variant that
4081 matches the specified operands, or NULL if no match is possible. */
4082 static struct ia64_opcode*
4083 parse_operands (idesc)
4084 struct ia64_opcode *idesc;
4085 {
4086 int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0;
4087 int sep = 0;
4088 enum ia64_opnd expected_operand = IA64_OPND_NIL;
4089 char mnemonic[129];
4090 char *first_arg = 0, *end, *saved_input_pointer;
4091 unsigned int sof;
4092
4093 assert (strlen (idesc->name) <= 128);
4094
4095 strcpy (mnemonic, idesc->name);
4096 if (idesc->operands[2] == IA64_OPND_SOF)
4097 {
4098 /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we
4099 can't parse the first operand until we have parsed the
4100 remaining operands of the "alloc" instruction. */
4101 SKIP_WHITESPACE ();
4102 first_arg = input_line_pointer;
4103 end = strchr (input_line_pointer, '=');
4104 if (!end)
4105 {
4106 as_bad ("Expected separator `='");
4107 return 0;
4108 }
4109 input_line_pointer = end + 1;
4110 ++i;
4111 ++num_outputs;
4112 }
4113
4114 for (; i < NELEMS (CURR_SLOT.opnd); ++i)
4115 {
4116 sep = parse_operand (CURR_SLOT.opnd + i);
4117 if (CURR_SLOT.opnd[i].X_op == O_absent)
4118 break;
4119
4120 ++num_operands;
4121
4122 if (sep != '=' && sep != ',')
4123 break;
4124
4125 if (sep == '=')
4126 {
4127 if (num_outputs > 0)
4128 as_bad ("Duplicate equal sign (=) in instruction");
4129 else
4130 num_outputs = i + 1;
4131 }
4132 }
4133 if (sep != '\0')
4134 {
4135 as_bad ("Illegal operand separator `%c'", sep);
4136 return 0;
4137 }
4138
4139 if (idesc->operands[2] == IA64_OPND_SOF)
4140 {
4141 /* map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r */
4142 know (strcmp (idesc->name, "alloc") == 0);
4143 if (num_operands == 5 /* first_arg not included in this count! */
4144 && CURR_SLOT.opnd[2].X_op == O_constant
4145 && CURR_SLOT.opnd[3].X_op == O_constant
4146 && CURR_SLOT.opnd[4].X_op == O_constant
4147 && CURR_SLOT.opnd[5].X_op == O_constant)
4148 {
4149 sof = set_regstack (CURR_SLOT.opnd[2].X_add_number,
4150 CURR_SLOT.opnd[3].X_add_number,
4151 CURR_SLOT.opnd[4].X_add_number,
4152 CURR_SLOT.opnd[5].X_add_number);
4153
4154 /* now we can parse the first arg: */
4155 saved_input_pointer = input_line_pointer;
4156 input_line_pointer = first_arg;
4157 sep = parse_operand (CURR_SLOT.opnd + 0);
4158 if (sep != '=')
4159 --num_outputs; /* force error */
4160 input_line_pointer = saved_input_pointer;
4161
4162 CURR_SLOT.opnd[2].X_add_number = sof;
4163 CURR_SLOT.opnd[3].X_add_number
4164 = sof - CURR_SLOT.opnd[4].X_add_number;
4165 CURR_SLOT.opnd[4] = CURR_SLOT.opnd[5];
4166 }
4167 }
4168
4169 highest_unmatched_operand = 0;
4170 expected_operand = idesc->operands[0];
4171 for (; idesc; idesc = get_next_opcode (idesc))
4172 {
4173 if (num_outputs != idesc->num_outputs)
4174 continue; /* mismatch in # of outputs */
4175
4176 CURR_SLOT.num_fixups = 0;
4177 for (i = 0; i < num_operands && idesc->operands[i]; ++i)
4178 if (!operand_match (idesc, i, CURR_SLOT.opnd + i))
4179 break;
4180
4181 if (i != num_operands)
4182 {
4183 if (i > highest_unmatched_operand)
4184 {
4185 highest_unmatched_operand = i;
4186 expected_operand = idesc->operands[i];
4187 }
4188 continue;
4189 }
4190
4191 if (num_operands < NELEMS (idesc->operands)
4192 && idesc->operands[num_operands])
4193 continue; /* mismatch in number of arguments */
4194
4195 break;
4196 }
4197 if (!idesc)
4198 {
4199 if (expected_operand)
4200 as_bad ("Operand %u of `%s' should be %s",
4201 highest_unmatched_operand + 1, mnemonic,
4202 elf64_ia64_operands[expected_operand].desc);
4203 else
4204 as_bad ("Operand mismatch");
4205 return 0;
4206 }
4207 return idesc;
4208 }
4209
4210 static void
4211 build_insn (slot, insnp)
4212 struct slot *slot;
4213 bfd_vma *insnp;
4214 {
4215 const struct ia64_operand *odesc, *o2desc;
4216 struct ia64_opcode *idesc = slot->idesc;
4217 bfd_signed_vma insn, val;
4218 const char *err;
4219 int i;
4220
4221 insn = idesc->opcode | slot->qp_regno;
4222
4223 for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i)
4224 {
4225 if (idesc->operands[i] == IA64_OPND_IMMU64)
4226 {
4227 val = slot->opnd[i].X_add_number;
4228 *insnp++ = (val >> 22) & 0x1ffffffffffLL;
4229 insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27)
4230 | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21)
4231 | (((val >> 63) & 0x1) << 36));
4232 }
4233 else if (idesc->operands[i] == IA64_OPND_IMMU62)
4234 {
4235 val = slot->opnd[i].X_add_number & 0x3fffffffffffffffULL;
4236 if (val != slot->opnd[i].X_add_number)
4237 as_warn (_("Value truncated to 62 bits"));
4238 *insnp++ = (val >> 21) & 0x1ffffffffffLL;
4239 insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36));
4240 }
4241 else if (idesc->operands[i] == IA64_OPND_TGT64)
4242 {
4243 // FIXME -- need to implement the target address encoding properly
4244 as_bad (_("long branch target encoding not implemented"));
4245 *insnp++ = 0;
4246 }
4247 else if (slot->opnd[i].X_op == O_register
4248 || slot->opnd[i].X_op == O_constant
4249 || slot->opnd[i].X_op == O_index
4250 || slot->opnd[i].X_op == O_big)
4251 {
4252 if (slot->opnd[i].X_op == O_big)
4253 {
4254 /* This must be the value 0x10000000000000000. */
4255 assert (idesc->operands[i] == IA64_OPND_IMM8M1U8);
4256 val = 0;
4257 }
4258 else
4259 val = slot->opnd[i].X_add_number;
4260
4261 switch (idesc->operands[i])
4262 {
4263 case IA64_OPND_AR3: val -= REG_AR; break;
4264 case IA64_OPND_B1: case IA64_OPND_B2: val -= REG_BR; break;
4265 case IA64_OPND_CR3: val -= REG_CR; break;
4266 case IA64_OPND_F1: case IA64_OPND_F2:
4267 case IA64_OPND_F3: case IA64_OPND_F4: val -= REG_FR; break;
4268 case IA64_OPND_P1: case IA64_OPND_P2: val -= REG_P; break;
4269
4270 case IA64_OPND_R1: case IA64_OPND_R2:
4271 case IA64_OPND_R3: case IA64_OPND_R3_2:
4272 case IA64_OPND_CPUID_R3: case IA64_OPND_DBR_R3:
4273 case IA64_OPND_DTR_R3: case IA64_OPND_ITR_R3:
4274 case IA64_OPND_IBR_R3: case IA64_OPND_MR3:
4275 case IA64_OPND_MSR_R3: case IA64_OPND_PKR_R3:
4276 case IA64_OPND_PMC_R3: case IA64_OPND_PMD_R3:
4277 case IA64_OPND_RR_R3:
4278 val -= REG_GR;
4279 break;
4280
4281 default:
4282 break;
4283 }
4284 odesc = elf64_ia64_operands + idesc->operands[i];
4285 err = (*odesc->insert) (odesc, val, &insn);
4286 if (err)
4287 as_bad_where (slot->src_file, slot->src_line,
4288 "Bad operand value: %s", err);
4289 if (idesc->flags & IA64_OPCODE_PSEUDO)
4290 {
4291 if ((idesc->flags & IA64_OPCODE_F2_EQ_F3)
4292 && odesc == elf64_ia64_operands + IA64_OPND_F3)
4293 {
4294 o2desc = elf64_ia64_operands + IA64_OPND_F2;
4295 (*o2desc->insert) (o2desc, val, &insn);
4296
4297 }
4298 if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT)
4299 && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a
4300 || odesc == elf64_ia64_operands + IA64_OPND_POS6))
4301 {
4302 o2desc = elf64_ia64_operands + IA64_OPND_LEN6;
4303 (*o2desc->insert) (o2desc, 64 - val, &insn);
4304 }
4305 }
4306 }
4307 }
4308 *insnp = insn;
4309 }
4310
4311 static void
4312 emit_one_bundle ()
4313 {
4314 unsigned int manual_bundling_on = 0, manual_bundling_off = 0;
4315 unsigned int manual_bundling = 0;
4316 enum ia64_unit required_unit, insn_unit = 0;
4317 enum ia64_insn_type type[3], insn_type;
4318 unsigned int template, orig_template;
4319 bfd_vma insn[3] = {-1, -1, -1};
4320 struct ia64_opcode *idesc;
4321 int end_of_insn_group = 0, user_template = -1;
4322 int n, i, j, first, curr;
4323 bfd_vma t0 = 0, t1 = 0;
4324 struct label_fix *lfix;
4325 struct insn_fix *ifix;
4326 char mnemonic[16];
4327 fixS *fix;
4328 char *f;
4329
4330 first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS;
4331 know (first >= 0 & first < NUM_SLOTS);
4332 n = MIN (3, md.num_slots_in_use);
4333
4334 /* Determine template: user user_template if specified, best match
4335 otherwise: */
4336
4337 if (md.slot[first].user_template >= 0)
4338 user_template = template = md.slot[first].user_template;
4339 else
4340 {
4341 /* auto select appropriate template */
4342 memset (type, 0, sizeof (type));
4343 curr = first;
4344 for (i = 0; i < n; ++i)
4345 {
4346 type[i] = md.slot[curr].idesc->type;
4347 curr = (curr + 1) % NUM_SLOTS;
4348 }
4349 template = best_template[type[0]][type[1]][type[2]];
4350 }
4351
4352 /* initialize instructions with appropriate nops: */
4353 for (i = 0; i < 3; ++i)
4354 insn[i] = nop[ia64_templ_desc[template].exec_unit[i]];
4355
4356 f = frag_more (16);
4357
4358 /* now fill in slots with as many insns as possible: */
4359 curr = first;
4360 idesc = md.slot[curr].idesc;
4361 end_of_insn_group = 0;
4362 for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i)
4363 {
4364 if (idesc->flags & IA64_OPCODE_SLOT2)
4365 {
4366 if (manual_bundling && i != 2)
4367 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
4368 "`%s' must be last in bundle", idesc->name);
4369 else
4370 i = 2;
4371 }
4372 if (idesc->flags & IA64_OPCODE_LAST)
4373 {
4374 int required_slot, required_template;
4375
4376 /* If we need a stop bit after an M slot, our only choice is
4377 template 5 (M;;MI). If we need a stop bit after a B
4378 slot, our only choice is to place it at the end of the
4379 bundle, because the only available templates are MIB,
4380 MBB, BBB, MMB, and MFB. We don't handle anything other
4381 than M and B slots because these are the only kind of
4382 instructions that can have the IA64_OPCODE_LAST bit set. */
4383 required_template = template;
4384 switch (idesc->type)
4385 {
4386 case IA64_TYPE_M:
4387 required_slot = 0;
4388 required_template = 5;
4389 break;
4390
4391 case IA64_TYPE_B:
4392 required_slot = 2;
4393 break;
4394
4395 default:
4396 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
4397 "Internal error: don't know how to force %s to end"
4398 "of instruction group", idesc->name);
4399 required_slot = i;
4400 break;
4401 }
4402 if (manual_bundling && i != required_slot)
4403 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
4404 "`%s' must be last in instruction group",
4405 idesc->name);
4406 if (required_slot < i)
4407 /* Can't fit this instruction. */
4408 break;
4409
4410 i = required_slot;
4411 if (required_template != template)
4412 {
4413 /* If we switch the template, we need to reset the NOPs
4414 after slot i. The slot-types of the instructions ahead
4415 of i never change, so we don't need to worry about
4416 changing NOPs in front of this slot. */
4417 for (j = i; j < 3; ++j)
4418 insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]];
4419 }
4420 template = required_template;
4421 }
4422 if (curr != first && md.slot[curr].label_fixups)
4423 {
4424 if (manual_bundling_on)
4425 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
4426 "Label must be first in a bundle");
4427 /* This insn must go into the first slot of a bundle. */
4428 break;
4429 }
4430
4431 manual_bundling_on = md.slot[curr].manual_bundling_on;
4432 manual_bundling_off = md.slot[curr].manual_bundling_off;
4433
4434 if (manual_bundling_on)
4435 {
4436 if (curr == first)
4437 manual_bundling = 1;
4438 else
4439 break; /* need to start a new bundle */
4440 }
4441
4442 if (end_of_insn_group && md.num_slots_in_use >= 1)
4443 {
4444 /* We need an instruction group boundary in the middle of a
4445 bundle. See if we can switch to an other template with
4446 an appropriate boundary. */
4447
4448 orig_template = template;
4449 if (i == 1 && (user_template == 4
4450 || (user_template < 0
4451 && (ia64_templ_desc[template].exec_unit[0]
4452 == IA64_UNIT_M))))
4453 {
4454 template = 5;
4455 end_of_insn_group = 0;
4456 }
4457 else if (i == 2 && (user_template == 0
4458 || (user_template < 0
4459 && (ia64_templ_desc[template].exec_unit[1]
4460 == IA64_UNIT_I)))
4461 /* This test makes sure we don't switch the template if
4462 the next instruction is one that needs to be first in
4463 an instruction group. Since all those instructions are
4464 in the M group, there is no way such an instruction can
4465 fit in this bundle even if we switch the template. The
4466 reason we have to check for this is that otherwise we
4467 may end up generating "MI;;I M.." which has the deadly
4468 effect that the second M instruction is no longer the
4469 first in the bundle! --davidm 99/12/16 */
4470 && (idesc->flags & IA64_OPCODE_FIRST) == 0)
4471 {
4472 template = 1;
4473 end_of_insn_group = 0;
4474 }
4475 else if (curr != first)
4476 /* can't fit this insn */
4477 break;
4478
4479 if (template != orig_template)
4480 /* if we switch the template, we need to reset the NOPs
4481 after slot i. The slot-types of the instructions ahead
4482 of i never change, so we don't need to worry about
4483 changing NOPs in front of this slot. */
4484 for (j = i; j < 3; ++j)
4485 insn[j] = nop[ia64_templ_desc[template].exec_unit[j]];
4486 }
4487 required_unit = ia64_templ_desc[template].exec_unit[i];
4488
4489 /* resolve dynamic opcodes such as "break" and "nop": */
4490 if (idesc->type == IA64_TYPE_DYN)
4491 {
4492 if ((strcmp (idesc->name, "nop") == 0)
4493 || (strcmp (idesc->name, "break") == 0))
4494 insn_unit = required_unit;
4495 else if (strcmp (idesc->name, "chk.s") == 0)
4496 {
4497 insn_unit = IA64_UNIT_M;
4498 if (required_unit == IA64_UNIT_I)
4499 insn_unit = IA64_UNIT_I;
4500 }
4501 else
4502 as_fatal ("emit_one_bundle: unexpected dynamic op");
4503
4504 sprintf (mnemonic, "%s.%c", idesc->name, "?imbf??"[insn_unit]);
4505 md.slot[curr].idesc = idesc = ia64_find_opcode (mnemonic);
4506 #if 0
4507 know (!idesc->next); /* no resolved dynamic ops have collisions */
4508 #endif
4509 }
4510 else
4511 {
4512 insn_type = idesc->type;
4513 insn_unit = IA64_UNIT_NIL;
4514 switch (insn_type)
4515 {
4516 case IA64_TYPE_A:
4517 if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M)
4518 insn_unit = required_unit;
4519 break;
4520 case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break;
4521 case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break;
4522 case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break;
4523 case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break;
4524 case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break;
4525 default: break;
4526 }
4527 }
4528
4529 if (insn_unit != required_unit)
4530 {
4531 if (required_unit == IA64_UNIT_L
4532 && insn_unit == IA64_UNIT_I
4533 && !(idesc->flags & IA64_OPCODE_X_IN_MLX))
4534 {
4535 /* we got ourselves an MLX template but the current
4536 instruction isn't an X-unit, or an I-unit instruction
4537 that can go into the X slot of an MLX template. Duh. */
4538 if (md.num_slots_in_use >= NUM_SLOTS)
4539 {
4540 as_bad_where (md.slot[curr].src_file,
4541 md.slot[curr].src_line,
4542 "`%s' can't go in X slot of "
4543 "MLX template", idesc->name);
4544 /* drop this insn so we don't livelock: */
4545 --md.num_slots_in_use;
4546 }
4547 break;
4548 }
4549 continue; /* try next slot */
4550 }
4551
4552 if (debug_type == DEBUG_DWARF2)
4553 {
4554 bfd_vma addr;
4555
4556 addr = frag_now->fr_address + frag_now_fix () - 16 + 1*i;
4557 dwarf2_gen_line_info (addr, &md.slot[curr].debug_line);
4558 }
4559
4560 build_insn (md.slot + curr, insn + i);
4561
4562 /* Set slot counts for unwind records. */
4563 while (md.slot[curr].unwind_record)
4564 {
4565 md.slot[curr].unwind_record->slot_number = (unsigned long) (f + i);
4566 md.slot[curr].unwind_record = md.slot[curr].unwind_record->next;
4567 }
4568 if (required_unit == IA64_UNIT_L)
4569 {
4570 know (i == 1);
4571 /* skip one slot for long/X-unit instructions */
4572 ++i;
4573 }
4574 --md.num_slots_in_use;
4575
4576 /* now is a good time to fix up the labels for this insn: */
4577 for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next)
4578 {
4579 S_SET_VALUE (lfix->sym, frag_now_fix () - 16);
4580 symbol_set_frag (lfix->sym, frag_now);
4581 }
4582
4583 for (j = 0; j < md.slot[curr].num_fixups; ++j)
4584 {
4585 ifix = md.slot[curr].fixup + j;
4586 fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 4,
4587 &ifix->expr, ifix->is_pcrel, ifix->code);
4588 fix->tc_fix_data.opnd = ifix->opnd;
4589 fix->fx_plt = (fix->fx_r_type == BFD_RELOC_IA64_PLTOFF22);
4590 fix->fx_file = md.slot[curr].src_file;
4591 fix->fx_line = md.slot[curr].src_line;
4592 }
4593
4594 end_of_insn_group = md.slot[curr].end_of_insn_group;
4595
4596 /* clear slot: */
4597 ia64_free_opcode (md.slot[curr].idesc);
4598 memset (md.slot + curr, 0, sizeof (md.slot[curr]));
4599 md.slot[curr].user_template = -1;
4600
4601 if (manual_bundling_off)
4602 {
4603 manual_bundling = 0;
4604 break;
4605 }
4606 curr = (curr + 1) % NUM_SLOTS;
4607 idesc = md.slot[curr].idesc;
4608 }
4609 if (manual_bundling)
4610 {
4611 if (md.num_slots_in_use > 0)
4612 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
4613 "`%s' does not fit into %s template",
4614 idesc->name, ia64_templ_desc[template].name);
4615 else
4616 as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line,
4617 "Missing '}' at end of file");
4618 }
4619 know (md.num_slots_in_use < NUM_SLOTS);
4620
4621 t0 = end_of_insn_group | (template << 1) | (insn[0] << 5) | (insn[1] << 46);
4622 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
4623
4624 md_number_to_chars (f + 0, t0, 8);
4625 md_number_to_chars (f + 8, t1, 8);
4626 }
4627
4628 int
4629 md_parse_option (c, arg)
4630 int c;
4631 char *arg;
4632 {
4633 /* Switches from the Intel assembler. */
4634 switch (c)
4635 {
4636 case 'M':
4637 if (strcmp (arg, "ilp64") == 0
4638 || strcmp (arg, "lp64") == 0
4639 || strcmp (arg, "p64") == 0)
4640 {
4641 md.flags |= EF_IA_64_ABI64;
4642 }
4643 else if (strcmp (arg, "ilp32") == 0)
4644 {
4645 md.flags &= ~EF_IA_64_ABI64;
4646 }
4647 else if (strcmp (arg, "le") == 0)
4648 {
4649 md.flags &= ~EF_IA_64_BE;
4650 }
4651 else if (strcmp (arg, "be") == 0)
4652 {
4653 md.flags |= EF_IA_64_BE;
4654 }
4655 else
4656 return 0;
4657 break;
4658
4659 case 'N':
4660 if (strcmp (arg, "so") == 0)
4661 {
4662 /* Suppress signon message. */
4663 }
4664 else if (strcmp (arg, "pi") == 0)
4665 {
4666 /* Reject privileged instructions. FIXME */
4667 }
4668 else if (strcmp (arg, "us") == 0)
4669 {
4670 /* Allow union of signed and unsigned range. FIXME */
4671 }
4672 else if (strcmp (arg, "close_fcalls") == 0)
4673 {
4674 /* Do not resolve global function calls. */
4675 }
4676 else
4677 return 0;
4678 break;
4679
4680 case 'C':
4681 /* temp[="prefix"] Insert temporary labels into the object file
4682 symbol table prefixed by "prefix".
4683 Default prefix is ":temp:".
4684 */
4685 break;
4686
4687 case 'a':
4688 /* ??? Conflicts with gas' listing option. */
4689 /* indirect=<tgt> Assume unannotated indirect branches behavior
4690 according to <tgt> --
4691 exit: branch out from the current context (default)
4692 labels: all labels in context may be branch targets
4693 */
4694 break;
4695
4696 case 'x':
4697 /* -X conflicts with an ignored option, use -x instead */
4698 md.detect_dv = 1;
4699 if (!arg || strcmp (arg, "explicit") == 0)
4700 {
4701 /* set default mode to explicit */
4702 md.default_explicit_mode = 1;
4703 break;
4704 }
4705 else if (strcmp (arg, "auto") == 0)
4706 {
4707 md.default_explicit_mode = 0;
4708 }
4709 else if (strcmp (arg, "debug") == 0)
4710 {
4711 md.debug_dv = 1;
4712 }
4713 else if (strcmp (arg, "debugx") == 0)
4714 {
4715 md.default_explicit_mode = 1;
4716 md.debug_dv = 1;
4717 }
4718 else
4719 {
4720 as_bad (_("Unrecognized option '-x%s'"), arg);
4721 }
4722 break;
4723
4724 case 'S':
4725 /* nops Print nops statistics. */
4726 break;
4727
4728 default:
4729 return 0;
4730 }
4731
4732 return 1;
4733 }
4734
4735 void
4736 md_show_usage (stream)
4737 FILE *stream;
4738 {
4739 fputs(_("\
4740 IA-64 options:\n\
4741 -Milp32|-Milp64|-Mlp64|-Mp64 select data model (default -Mlp64)\n\
4742 -Mle | -Mbe select little- or big-endian byte order (default -Mle)\n\
4743 -x | -xexplicit turn on dependency violation checking (default)\n\
4744 -xauto automagically remove dependency violations\n\
4745 -xdebug debug dependency violation checker\n"),
4746 stream);
4747 }
4748
4749 static inline int
4750 match (int templ, int type, int slot)
4751 {
4752 enum ia64_unit unit;
4753 int result;
4754
4755 unit = ia64_templ_desc[templ].exec_unit[slot];
4756 switch (type)
4757 {
4758 case IA64_TYPE_DYN: result = 1; break; /* for nop and break */
4759 case IA64_TYPE_A:
4760 result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M);
4761 break;
4762 case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break;
4763 case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break;
4764 case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break;
4765 case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break;
4766 case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break;
4767 default: result = 0; break;
4768 }
4769 return result;
4770 }
4771
4772 /* This function is called once, at assembler startup time. It sets
4773 up all the tables, etc. that the MD part of the assembler will need
4774 that can be determined before arguments are parsed. */
4775 void
4776 md_begin ()
4777 {
4778 int i, j, k, t, total, ar_base, cr_base, goodness, best, regnum;
4779 const char *err;
4780 char name[8];
4781
4782 md.auto_align = 1;
4783 md.explicit_mode = md.default_explicit_mode;
4784
4785 bfd_set_section_alignment (stdoutput, text_section, 4);
4786
4787 target_big_endian = 0;
4788 pseudo_func[FUNC_FPTR_RELATIVE].u.sym =
4789 symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE,
4790 &zero_address_frag);
4791
4792 pseudo_func[FUNC_GP_RELATIVE].u.sym =
4793 symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE,
4794 &zero_address_frag);
4795
4796 pseudo_func[FUNC_LT_RELATIVE].u.sym =
4797 symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE,
4798 &zero_address_frag);
4799
4800 pseudo_func[FUNC_PLT_RELATIVE].u.sym =
4801 symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE,
4802 &zero_address_frag);
4803
4804 pseudo_func[FUNC_SEC_RELATIVE].u.sym =
4805 symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE,
4806 &zero_address_frag);
4807
4808 pseudo_func[FUNC_SEG_RELATIVE].u.sym =
4809 symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE,
4810 &zero_address_frag);
4811
4812 pseudo_func[FUNC_LTV_RELATIVE].u.sym =
4813 symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE,
4814 &zero_address_frag);
4815
4816 pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym =
4817 symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE,
4818 &zero_address_frag);
4819
4820 /* compute the table of best templates: */
4821 for (i = 0; i < IA64_NUM_TYPES; ++i)
4822 for (j = 0; j < IA64_NUM_TYPES; ++j)
4823 for (k = 0; k < IA64_NUM_TYPES; ++k)
4824 {
4825 best = 0;
4826 for (t = 0; t < NELEMS (ia64_templ_desc); ++t)
4827 {
4828 goodness = 0;
4829 if (match (t, i, 0))
4830 {
4831 if (match (t, j, 1))
4832 {
4833 if (match (t, k, 2))
4834 goodness = 3;
4835 else
4836 goodness = 2;
4837 }
4838 else if (match (t, j, 2))
4839 goodness = 2;
4840 else
4841 goodness = 1;
4842 }
4843 else if (match (t, i, 1))
4844 {
4845 if (match (t, j, 2))
4846 goodness = 2;
4847 else
4848 goodness = 1;
4849 }
4850 else if (match (t, i, 2))
4851 goodness = 1;
4852
4853 if (goodness > best)
4854 {
4855 best = goodness;
4856 best_template[i][j][k] = t;
4857 }
4858 }
4859 }
4860
4861 for (i = 0; i < NUM_SLOTS; ++i)
4862 md.slot[i].user_template = -1;
4863
4864 md.pseudo_hash = hash_new ();
4865 for (i = 0; i < NELEMS (pseudo_opcode); ++i)
4866 {
4867 err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name,
4868 (void *) (pseudo_opcode + i));
4869 if (err)
4870 as_fatal ("ia64.md_begin: can't hash `%s': %s",
4871 pseudo_opcode[i].name, err);
4872 }
4873
4874 md.reg_hash = hash_new ();
4875 md.dynreg_hash = hash_new ();
4876 md.const_hash = hash_new ();
4877 md.entry_hash = hash_new ();
4878
4879 /* general registers: */
4880
4881 total = 128;
4882 for (i = 0; i < total; ++i)
4883 {
4884 sprintf (name, "r%d", i - REG_GR);
4885 md.regsym[i] = declare_register (name, i);
4886 }
4887
4888 /* floating point registers: */
4889 total += 128;
4890 for (; i < total; ++i)
4891 {
4892 sprintf (name, "f%d", i - REG_FR);
4893 md.regsym[i] = declare_register (name, i);
4894 }
4895
4896 /* application registers: */
4897 total += 128;
4898 ar_base = i;
4899 for (; i < total; ++i)
4900 {
4901 sprintf (name, "ar%d", i - REG_AR);
4902 md.regsym[i] = declare_register (name, i);
4903 }
4904
4905 /* control registers: */
4906 total += 128;
4907 cr_base = i;
4908 for (; i < total; ++i)
4909 {
4910 sprintf (name, "cr%d", i - REG_CR);
4911 md.regsym[i] = declare_register (name, i);
4912 }
4913
4914 /* predicate registers: */
4915 total += 64;
4916 for (; i < total; ++i)
4917 {
4918 sprintf (name, "p%d", i - REG_P);
4919 md.regsym[i] = declare_register (name, i);
4920 }
4921
4922 /* branch registers: */
4923 total += 8;
4924 for (; i < total; ++i)
4925 {
4926 sprintf (name, "b%d", i - REG_BR);
4927 md.regsym[i] = declare_register (name, i);
4928 }
4929
4930 md.regsym[REG_IP] = declare_register ("ip", REG_IP);
4931 md.regsym[REG_CFM] = declare_register ("cfm", REG_CFM);
4932 md.regsym[REG_PR] = declare_register ("pr", REG_PR);
4933 md.regsym[REG_PR_ROT] = declare_register ("pr.rot", REG_PR_ROT);
4934 md.regsym[REG_PSR] = declare_register ("psr", REG_PSR);
4935 md.regsym[REG_PSR_L] = declare_register ("psr.l", REG_PSR_L);
4936 md.regsym[REG_PSR_UM] = declare_register ("psr.um", REG_PSR_UM);
4937
4938 for (i = 0; i < NELEMS (indirect_reg); ++i)
4939 {
4940 regnum = indirect_reg[i].regnum;
4941 md.regsym[regnum] = declare_register (indirect_reg[i].name, regnum);
4942 }
4943
4944 /* define synonyms for application registers: */
4945 for (i = REG_AR; i < REG_AR + NELEMS (ar); ++i)
4946 md.regsym[i] = declare_register (ar[i - REG_AR].name,
4947 REG_AR + ar[i - REG_AR].regnum);
4948
4949 /* define synonyms for control registers: */
4950 for (i = REG_CR; i < REG_CR + NELEMS (cr); ++i)
4951 md.regsym[i] = declare_register (cr[i - REG_CR].name,
4952 REG_CR + cr[i - REG_CR].regnum);
4953
4954 declare_register ("gp", REG_GR + 1);
4955 declare_register ("sp", REG_GR + 12);
4956 declare_register ("rp", REG_BR + 0);
4957
4958 declare_register_set ("ret", 4, REG_GR + 8);
4959 declare_register_set ("farg", 8, REG_FR + 8);
4960 declare_register_set ("fret", 8, REG_FR + 8);
4961
4962 for (i = 0; i < NELEMS (const_bits); ++i)
4963 {
4964 err = hash_insert (md.const_hash, const_bits[i].name,
4965 (PTR) (const_bits + i));
4966 if (err)
4967 as_fatal ("Inserting \"%s\" into constant hash table failed: %s",
4968 name, err);
4969 }
4970
4971 /* Default to 64-bit mode. */
4972 md.flags = EF_IA_64_ABI64;
4973
4974 md.mem_offset.hint = 0;
4975 md.path = 0;
4976 md.maxpaths = 0;
4977 md.entry_labels = NULL;
4978 }
4979
4980 void
4981 ia64_end_of_source ()
4982 {
4983 /* terminate insn group upon reaching end of file: */
4984 insn_group_break (1, 0, 0);
4985
4986 /* emits slots we haven't written yet: */
4987 ia64_flush_insns ();
4988
4989 bfd_set_private_flags (stdoutput, md.flags);
4990
4991 if (debug_type == DEBUG_DWARF2)
4992 dwarf2_finish ();
4993
4994 md.mem_offset.hint = 0;
4995 }
4996
4997 void
4998 ia64_start_line ()
4999 {
5000 md.qp.X_op = O_absent;
5001
5002 if (ignore_input ())
5003 return;
5004
5005 if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';')
5006 {
5007 if (md.detect_dv && !md.explicit_mode)
5008 as_warn (_("Explicit stops are ignored in auto mode"));
5009 else
5010 insn_group_break (1, 0, 0);
5011 }
5012 }
5013
5014 int
5015 ia64_unrecognized_line (ch)
5016 int ch;
5017 {
5018 switch (ch)
5019 {
5020 case '(':
5021 expression (&md.qp);
5022 if (*input_line_pointer++ != ')')
5023 {
5024 as_bad ("Expected ')'");
5025 return 0;
5026 }
5027 if (md.qp.X_op != O_register)
5028 {
5029 as_bad ("Qualifying predicate expected");
5030 return 0;
5031 }
5032 if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64)
5033 {
5034 as_bad ("Predicate register expected");
5035 return 0;
5036 }
5037 return 1;
5038
5039 case '{':
5040 if (md.manual_bundling)
5041 as_warn ("Found '{' when manual bundling is already turned on");
5042 else
5043 CURR_SLOT.manual_bundling_on = 1;
5044 md.manual_bundling = 1;
5045
5046 /* bundling is only acceptable in explicit mode
5047 or when in default automatic mode */
5048 if (md.detect_dv && !md.explicit_mode)
5049 {
5050 if (!md.mode_explicitly_set
5051 && !md.default_explicit_mode)
5052 dot_dv_mode ('E');
5053 else
5054 as_warn (_("Found '{' after explicit switch to automatic mode"));
5055 }
5056 return 1;
5057
5058 case '}':
5059 if (!md.manual_bundling)
5060 as_warn ("Found '}' when manual bundling is off");
5061 else
5062 PREV_SLOT.manual_bundling_off = 1;
5063 md.manual_bundling = 0;
5064
5065 /* switch back to automatic mode, if applicable */
5066 if (md.detect_dv
5067 && md.explicit_mode
5068 && !md.mode_explicitly_set
5069 && !md.default_explicit_mode)
5070 dot_dv_mode ('A');
5071
5072 /* Allow '{' to follow on the same line. We also allow ";;", but that
5073 happens automatically because ';' is an end of line marker. */
5074 SKIP_WHITESPACE ();
5075 if (input_line_pointer[0] == '{')
5076 {
5077 input_line_pointer++;
5078 return ia64_unrecognized_line ('{');
5079 }
5080
5081 demand_empty_rest_of_line ();
5082 return 1;
5083
5084 default:
5085 break;
5086 }
5087 return 0; /* not a valid line */
5088 }
5089
5090 void
5091 ia64_frob_label (sym)
5092 struct symbol *sym;
5093 {
5094 struct label_fix *fix;
5095
5096 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
5097 {
5098 md.last_text_seg = now_seg;
5099 fix = obstack_alloc (&notes, sizeof (*fix));
5100 fix->sym = sym;
5101 fix->next = CURR_SLOT.label_fixups;
5102 CURR_SLOT.label_fixups = fix;
5103
5104 /* keep track of how many code entry points we've seen */
5105 if (md.path == md.maxpaths)
5106 {
5107 md.maxpaths += 20;
5108 md.entry_labels = (const char **)
5109 xrealloc ((void *)md.entry_labels, md.maxpaths * sizeof (char *));
5110 }
5111 md.entry_labels[md.path++] = S_GET_NAME (sym);
5112 }
5113 }
5114
5115 void
5116 ia64_flush_pending_output ()
5117 {
5118 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
5119 {
5120 /* ??? This causes many unnecessary stop bits to be emitted.
5121 Unfortunately, it isn't clear if it is safe to remove this. */
5122 insn_group_break (1, 0, 0);
5123 ia64_flush_insns ();
5124 }
5125 }
5126
5127 /* Do ia64-specific expression optimization. All that's done here is
5128 to transform index expressions that are either due to the indexing
5129 of rotating registers or due to the indexing of indirect register
5130 sets. */
5131 int
5132 ia64_optimize_expr (l, op, r)
5133 expressionS *l;
5134 operatorT op;
5135 expressionS *r;
5136 {
5137 unsigned num_regs;
5138
5139 if (op == O_index)
5140 {
5141 if (l->X_op == O_register && r->X_op == O_constant)
5142 {
5143 num_regs = (l->X_add_number >> 16);
5144 if ((unsigned) r->X_add_number >= num_regs)
5145 {
5146 if (!num_regs)
5147 as_bad ("No current frame");
5148 else
5149 as_bad ("Index out of range 0..%u", num_regs - 1);
5150 r->X_add_number = 0;
5151 }
5152 l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number;
5153 return 1;
5154 }
5155 else if (l->X_op == O_register && r->X_op == O_register)
5156 {
5157 if (l->X_add_number < IND_CPUID || l->X_add_number > IND_RR
5158 || l->X_add_number == IND_MEM)
5159 {
5160 as_bad ("Indirect register set name expected");
5161 l->X_add_number = IND_CPUID;
5162 }
5163 l->X_op = O_index;
5164 l->X_op_symbol = md.regsym[l->X_add_number];
5165 l->X_add_number = r->X_add_number;
5166 return 1;
5167 }
5168 }
5169 return 0;
5170 }
5171
5172 int
5173 ia64_parse_name (name, e)
5174 char *name;
5175 expressionS *e;
5176 {
5177 struct const_desc *cdesc;
5178 struct dynreg *dr = 0;
5179 unsigned int regnum;
5180 struct symbol *sym;
5181 char *end;
5182
5183 /* first see if NAME is a known register name: */
5184 sym = hash_find (md.reg_hash, name);
5185 if (sym)
5186 {
5187 e->X_op = O_register;
5188 e->X_add_number = S_GET_VALUE (sym);
5189 return 1;
5190 }
5191
5192 cdesc = hash_find (md.const_hash, name);
5193 if (cdesc)
5194 {
5195 e->X_op = O_constant;
5196 e->X_add_number = cdesc->value;
5197 return 1;
5198 }
5199
5200 /* check for inN, locN, or outN: */
5201 switch (name[0])
5202 {
5203 case 'i':
5204 if (name[1] == 'n' && isdigit (name[2]))
5205 {
5206 dr = &md.in;
5207 name += 2;
5208 }
5209 break;
5210
5211 case 'l':
5212 if (name[1] == 'o' && name[2] == 'c' && isdigit (name[3]))
5213 {
5214 dr = &md.loc;
5215 name += 3;
5216 }
5217 break;
5218
5219 case 'o':
5220 if (name[1] == 'u' && name[2] == 't' && isdigit (name[3]))
5221 {
5222 dr = &md.out;
5223 name += 3;
5224 }
5225 break;
5226
5227 default:
5228 break;
5229 }
5230
5231 if (dr)
5232 {
5233 /* the name is inN, locN, or outN; parse the register number: */
5234 regnum = strtoul (name, &end, 10);
5235 if (end > name && *end == '\0')
5236 {
5237 if ((unsigned) regnum >= dr->num_regs)
5238 {
5239 if (!dr->num_regs)
5240 as_bad ("No current frame");
5241 else
5242 as_bad ("Register number out of range 0..%u", dr->num_regs-1);
5243 regnum = 0;
5244 }
5245 e->X_op = O_register;
5246 e->X_add_number = dr->base + regnum;
5247 return 1;
5248 }
5249 }
5250
5251 if ((dr = hash_find (md.dynreg_hash, name)))
5252 {
5253 /* We've got ourselves the name of a rotating register set.
5254 Store the base register number in the low 16 bits of
5255 X_add_number and the size of the register set in the top 16
5256 bits. */
5257 e->X_op = O_register;
5258 e->X_add_number = dr->base | (dr->num_regs << 16);
5259 return 1;
5260 }
5261 return 0;
5262 }
5263
5264 /* Remove the '#' suffix that indicates a symbol as opposed to a register. */
5265
5266 char *
5267 ia64_canonicalize_symbol_name (name)
5268 char *name;
5269 {
5270 size_t len = strlen(name);
5271 if (len > 1 && name[len-1] == '#')
5272 name[len-1] = '\0';
5273 return name;
5274 }
5275
5276 static int
5277 is_conditional_branch (idesc)
5278 struct ia64_opcode *idesc;
5279 {
5280 return (strncmp (idesc->name, "br", 2) == 0
5281 && (strcmp (idesc->name, "br") == 0
5282 || strncmp (idesc->name, "br.cond", 7) == 0
5283 || strncmp (idesc->name, "br.call", 7) == 0
5284 || strncmp (idesc->name, "br.ret", 6) == 0
5285 || strcmp (idesc->name, "brl") == 0
5286 || strncmp (idesc->name, "brl.cond", 7) == 0
5287 || strncmp (idesc->name, "brl.call", 7) == 0
5288 || strncmp (idesc->name, "brl.ret", 6) == 0));
5289 }
5290
5291 /* Return whether the given opcode is a taken branch. If there's any doubt,
5292 returns zero */
5293 static int
5294 is_taken_branch (idesc)
5295 struct ia64_opcode *idesc;
5296 {
5297 return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0)
5298 || strncmp (idesc->name, "br.ia", 5) == 0);
5299 }
5300
5301 /* Return whether the given opcode is an interruption or rfi. If there's any
5302 doubt, returns zero */
5303 static int
5304 is_interruption_or_rfi (idesc)
5305 struct ia64_opcode *idesc;
5306 {
5307 if (strcmp (idesc->name, "rfi") == 0)
5308 return 1;
5309 return 0;
5310 }
5311
5312 /* Returns the index of the given dependency in the opcode's list of chks, or
5313 -1 if there is no dependency. */
5314 static int
5315 depends_on (depind, idesc)
5316 int depind;
5317 struct ia64_opcode *idesc;
5318 {
5319 int i;
5320 const struct ia64_opcode_dependency *dep = idesc->dependencies;
5321 for (i = 0;i < dep->nchks; i++)
5322 {
5323 if (depind == DEP(dep->chks[i]))
5324 return i;
5325 }
5326 return -1;
5327 }
5328
5329 /* Determine a set of specific resources used for a particular resource
5330 class. Returns the number of specific resources identified For those
5331 cases which are not determinable statically, the resource returned is
5332 marked nonspecific.
5333
5334 Meanings of value in 'NOTE':
5335 1) only read/write when the register number is explicitly encoded in the
5336 insn.
5337 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only
5338 accesses CFM when qualifying predicate is in the rotating region.
5339 3) general register value is used to specify an indirect register; not
5340 determinable statically.
5341 4) only read the given resource when bits 7:0 of the indirect index
5342 register value does not match the register number of the resource; not
5343 determinable statically.
5344 5) all rules are implementation specific.
5345 6) only when both the index specified by the reader and the index specified
5346 by the writer have the same value in bits 63:61; not determinable
5347 statically.
5348 7) only access the specified resource when the corresponding mask bit is
5349 set
5350 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is
5351 only read when these insns reference FR2-31
5352 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only
5353 written when these insns write FR32-127
5354 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the
5355 instruction
5356 11) The target predicates are written independently of PR[qp], but source
5357 registers are only read if PR[qp] is true. Since the state of PR[qp]
5358 cannot statically be determined, all source registers are marked used.
5359 12) This insn only reads the specified predicate register when that
5360 register is the PR[qp].
5361 13) This reference to ld-c only applies to teh GR whose value is loaded
5362 with data returned from memory, not the post-incremented address register.
5363 14) The RSE resource includes the implementation-specific RSE internal
5364 state resources. At least one (and possibly more) of these resources are
5365 read by each instruction listed in IC:rse-readers. At least one (and
5366 possibly more) of these resources are written by each insn listed in
5367 IC:rse-writers.
5368 15+16) Represents reserved instructions, which the assembler does not
5369 generate.
5370
5371 Memory resources (i.e. locations in memory) are *not* marked or tracked by
5372 this code; there are no dependency violations based on memory access.
5373
5374 */
5375
5376 #define MAX_SPECS 256
5377 #define DV_CHK 1
5378 #define DV_REG 0
5379
5380 static int
5381 specify_resource (dep, idesc, type, specs, note, path)
5382 const struct ia64_dependency *dep;
5383 struct ia64_opcode *idesc;
5384 int type; /* is this a DV chk or a DV reg? */
5385 struct rsrc specs[MAX_SPECS]; /* returned specific resources */
5386 int note; /* resource note for this insn's usage */
5387 int path; /* which execution path to examine */
5388 {
5389 int count = 0;
5390 int i;
5391 int rsrc_write = 0;
5392 struct rsrc tmpl;
5393
5394 if (dep->mode == IA64_DV_WAW
5395 || (dep->mode == IA64_DV_RAW && type == DV_REG)
5396 || (dep->mode == IA64_DV_WAR && type == DV_CHK))
5397 rsrc_write = 1;
5398
5399 /* template for any resources we identify */
5400 tmpl.dependency = dep;
5401 tmpl.note = note;
5402 tmpl.insn_srlz = tmpl.data_srlz = 0;
5403 tmpl.qp_regno = CURR_SLOT.qp_regno;
5404 tmpl.link_to_qp_branch = 1;
5405 tmpl.mem_offset.hint = 0;
5406 tmpl.specific = 1;
5407 tmpl.index = 0;
5408
5409 #define UNHANDLED \
5410 as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \
5411 dep->name, idesc->name, (rsrc_write?"write":"read"), note)
5412 #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path)
5413
5414 /* we don't need to track these */
5415 if (dep->semantics == IA64_DVS_NONE)
5416 return 0;
5417
5418 switch (dep->specifier)
5419 {
5420 case IA64_RS_AR_K:
5421 if (note == 1)
5422 {
5423 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
5424 {
5425 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
5426 if (regno >= 0 && regno <= 7)
5427 {
5428 specs[count] = tmpl;
5429 specs[count++].index = regno;
5430 }
5431 }
5432 }
5433 else if (note == 0)
5434 {
5435 for(i=0;i < 8;i++)
5436 {
5437 specs[count] = tmpl;
5438 specs[count++].index = i;
5439 }
5440 }
5441 else
5442 {
5443 UNHANDLED;
5444 }
5445 break;
5446
5447 case IA64_RS_AR_UNAT:
5448 /* This is a mov =AR or mov AR= instruction. */
5449 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
5450 {
5451 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
5452 if (regno == AR_UNAT)
5453 {
5454 specs[count++] = tmpl;
5455 }
5456 }
5457 else
5458 {
5459 /* This is a spill/fill, or other instruction that modifies the
5460 unat register. */
5461
5462 /* Unless we can determine the specific bits used, mark the whole
5463 thing; bits 8:3 of the memory address indicate the bit used in
5464 UNAT. The .mem.offset hint may be used to eliminate a small
5465 subset of conflicts. */
5466 specs[count] = tmpl;
5467 if (md.mem_offset.hint)
5468 {
5469 if (md.debug_dv)
5470 fprintf (stderr, " Using hint for spill/fill\n");
5471 /* the index isn't actually used, just set it to something
5472 approximating the bit index */
5473 specs[count].index = (md.mem_offset.offset >> 3) & 0x3F;
5474 specs[count].mem_offset.hint = 1;
5475 specs[count].mem_offset.offset = md.mem_offset.offset;
5476 specs[count++].mem_offset.base = md.mem_offset.base;
5477 }
5478 else
5479 {
5480 specs[count++].specific = 0;
5481 }
5482 }
5483 break;
5484
5485 case IA64_RS_AR:
5486 if (note == 1)
5487 {
5488 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
5489 {
5490 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
5491 if ((regno >= 8 && regno <= 15)
5492 || (regno >= 20 && regno <= 23)
5493 || (regno >= 31 && regno <= 39)
5494 || (regno >= 41 && regno <= 47)
5495 || (regno >= 67 && regno <= 111))
5496 {
5497 specs[count] = tmpl;
5498 specs[count++].index = regno;
5499 }
5500 }
5501 }
5502 else
5503 {
5504 UNHANDLED;
5505 }
5506 break;
5507
5508 case IA64_RS_ARb:
5509 if (note == 1)
5510 {
5511 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
5512 {
5513 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
5514 if ((regno >= 48 && regno <= 63)
5515 || (regno >= 112 && regno <= 127))
5516 {
5517 specs[count] = tmpl;
5518 specs[count++].index = regno;
5519 }
5520 }
5521 }
5522 else if (note == 0)
5523 {
5524 for (i=48;i < 64;i++)
5525 {
5526 specs[count] = tmpl;
5527 specs[count++].index = i;
5528 }
5529 for (i=112;i < 128;i++)
5530 {
5531 specs[count] = tmpl;
5532 specs[count++].index = i;
5533 }
5534 }
5535 else
5536 {
5537 UNHANDLED;
5538 }
5539 break;
5540
5541 case IA64_RS_BR:
5542 if (note != 1)
5543 {
5544 UNHANDLED;
5545 }
5546 else
5547 {
5548 if (rsrc_write)
5549 {
5550 for (i=0;i < idesc->num_outputs;i++)
5551 if (idesc->operands[i] == IA64_OPND_B1
5552 || idesc->operands[i] == IA64_OPND_B2)
5553 {
5554 specs[count] = tmpl;
5555 specs[count++].index =
5556 CURR_SLOT.opnd[i].X_add_number - REG_BR;
5557 }
5558 }
5559 else
5560 {
5561 for (i = idesc->num_outputs;i < NELEMS(idesc->operands);i++)
5562 if (idesc->operands[i] == IA64_OPND_B1
5563 || idesc->operands[i] == IA64_OPND_B2)
5564 {
5565 specs[count] = tmpl;
5566 specs[count++].index =
5567 CURR_SLOT.opnd[i].X_add_number - REG_BR;
5568 }
5569 }
5570 }
5571 break;
5572
5573 case IA64_RS_CPUID: /* four or more registers */
5574 if (note == 3)
5575 {
5576 if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3)
5577 {
5578 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
5579 if (regno >= 0 && regno < NELEMS(gr_values)
5580 && KNOWN(regno))
5581 {
5582 specs[count] = tmpl;
5583 specs[count++].index = gr_values[regno].value & 0xFF;
5584 }
5585 else
5586 {
5587 specs[count] = tmpl;
5588 specs[count++].specific = 0;
5589 }
5590 }
5591 }
5592 else
5593 {
5594 UNHANDLED;
5595 }
5596 break;
5597
5598 case IA64_RS_DBR: /* four or more registers */
5599 if (note == 3)
5600 {
5601 if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3)
5602 {
5603 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
5604 if (regno >= 0 && regno < NELEMS(gr_values)
5605 && KNOWN(regno))
5606 {
5607 specs[count] = tmpl;
5608 specs[count++].index = gr_values[regno].value & 0xFF;
5609 }
5610 else
5611 {
5612 specs[count] = tmpl;
5613 specs[count++].specific = 0;
5614 }
5615 }
5616 }
5617 else if (note == 0 && !rsrc_write)
5618 {
5619 specs[count] = tmpl;
5620 specs[count++].specific = 0;
5621 }
5622 else
5623 {
5624 UNHANDLED;
5625 }
5626 break;
5627
5628 case IA64_RS_IBR: /* four or more registers */
5629 if (note == 3)
5630 {
5631 if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3)
5632 {
5633 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
5634 if (regno >= 0 && regno < NELEMS(gr_values)
5635 && KNOWN(regno))
5636 {
5637 specs[count] = tmpl;
5638 specs[count++].index = gr_values[regno].value & 0xFF;
5639 }
5640 else
5641 {
5642 specs[count] = tmpl;
5643 specs[count++].specific = 0;
5644 }
5645 }
5646 }
5647 else
5648 {
5649 UNHANDLED;
5650 }
5651 break;
5652
5653 case IA64_RS_MSR:
5654 if (note == 5)
5655 {
5656 /* These are implementation specific. Force all references to
5657 conflict with all other references. */
5658 specs[count] = tmpl;
5659 specs[count++].specific = 0;
5660 }
5661 else
5662 {
5663 UNHANDLED;
5664 }
5665 break;
5666
5667 case IA64_RS_PKR: /* 16 or more registers */
5668 if (note == 3 || note == 4)
5669 {
5670 if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3)
5671 {
5672 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
5673 if (regno >= 0 && regno < NELEMS(gr_values)
5674 && KNOWN(regno))
5675 {
5676 if (note == 3)
5677 {
5678 specs[count] = tmpl;
5679 specs[count++].index = gr_values[regno].value & 0xFF;
5680 }
5681 else for (i=0;i < NELEMS(gr_values);i++)
5682 {
5683 /* uses all registers *except* the one in R3 */
5684 if (i != (gr_values[regno].value & 0xFF))
5685 {
5686 specs[count] = tmpl;
5687 specs[count++].index = i;
5688 }
5689 }
5690 }
5691 else
5692 {
5693 specs[count] = tmpl;
5694 specs[count++].specific = 0;
5695 }
5696 }
5697 }
5698 else if (note == 0)
5699 {
5700 /* probe et al. */
5701 specs[count] = tmpl;
5702 specs[count++].specific = 0;
5703 }
5704 break;
5705
5706 case IA64_RS_PMC: /* four or more registers */
5707 if (note == 3)
5708 {
5709 if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3
5710 || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3))
5711
5712 {
5713 int index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write)
5714 ? 1 : !rsrc_write);
5715 int regno = CURR_SLOT.opnd[index].X_add_number - REG_GR;
5716 if (regno >= 0 && regno < NELEMS(gr_values)
5717 && KNOWN(regno))
5718 {
5719 specs[count] = tmpl;
5720 specs[count++].index = gr_values[regno].value & 0xFF;
5721 }
5722 else
5723 {
5724 specs[count] = tmpl;
5725 specs[count++].specific = 0;
5726 }
5727 }
5728 }
5729 else
5730 {
5731 UNHANDLED;
5732 }
5733 break;
5734
5735 case IA64_RS_PMD: /* four or more registers */
5736 if (note == 3)
5737 {
5738 if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3)
5739 {
5740 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
5741 if (regno >= 0 && regno < NELEMS(gr_values)
5742 && KNOWN(regno))
5743 {
5744 specs[count] = tmpl;
5745 specs[count++].index = gr_values[regno].value & 0xFF;
5746 }
5747 else
5748 {
5749 specs[count] = tmpl;
5750 specs[count++].specific = 0;
5751 }
5752 }
5753 }
5754 else
5755 {
5756 UNHANDLED;
5757 }
5758 break;
5759
5760 case IA64_RS_RR: /* eight registers */
5761 if (note == 6)
5762 {
5763 if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3)
5764 {
5765 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR;
5766 if (regno >= 0 && regno < NELEMS(gr_values)
5767 && KNOWN(regno))
5768 {
5769 specs[count] = tmpl;
5770 specs[count++].index = (gr_values[regno].value >> 61) & 0x7;
5771 }
5772 else
5773 {
5774 specs[count] = tmpl;
5775 specs[count++].specific = 0;
5776 }
5777 }
5778 }
5779 else if (note == 0 && !rsrc_write)
5780 {
5781 specs[count] = tmpl;
5782 specs[count++].specific = 0;
5783 }
5784 else
5785 {
5786 UNHANDLED;
5787 }
5788 break;
5789
5790 case IA64_RS_CR_IRR:
5791 if (note == 0)
5792 {
5793 /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */
5794 int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR;
5795 if (rsrc_write
5796 && idesc->operands[1] == IA64_OPND_CR3
5797 && regno == CR_IVR)
5798 {
5799 for(i=0;i < 4;i++)
5800 {
5801 specs[count] = tmpl;
5802 specs[count++].index = CR_IRR0 + i;
5803 }
5804 }
5805 }
5806 else if (note == 1)
5807 {
5808 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
5809 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
5810 && regno >= CR_IRR0
5811 && regno <= CR_IRR3)
5812 {
5813 specs[count] = tmpl;
5814 specs[count++].index = regno;
5815 }
5816 }
5817 else
5818 {
5819 UNHANDLED;
5820 }
5821 break;
5822
5823 case IA64_RS_CR_LRR:
5824 if (note != 1)
5825 {
5826 UNHANDLED;
5827 }
5828 else
5829 {
5830 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
5831 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3
5832 && (regno == CR_LRR0 || regno == CR_LRR1))
5833 {
5834 specs[count] = tmpl;
5835 specs[count++].index = regno;
5836 }
5837 }
5838 break;
5839
5840 case IA64_RS_CR:
5841 if (note == 1)
5842 {
5843 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
5844 {
5845 specs[count] = tmpl;
5846 specs[count++].index =
5847 CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
5848 }
5849 }
5850 else
5851 {
5852 UNHANDLED;
5853 }
5854 break;
5855
5856 case IA64_RS_FR:
5857 case IA64_RS_FRb:
5858 if (note != 1)
5859 {
5860 UNHANDLED;
5861 }
5862 else if (rsrc_write)
5863 {
5864 if (dep->specifier == IA64_RS_FRb
5865 && idesc->operands[0] == IA64_OPND_F1)
5866 {
5867 specs[count] = tmpl;
5868 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR;
5869 }
5870 }
5871 else
5872 {
5873 for (i=idesc->num_outputs;i < NELEMS(idesc->operands);i++)
5874 {
5875 if (idesc->operands[i] == IA64_OPND_F2
5876 || idesc->operands[i] == IA64_OPND_F3
5877 || idesc->operands[i] == IA64_OPND_F4)
5878 {
5879 specs[count] = tmpl;
5880 specs[count++].index =
5881 CURR_SLOT.opnd[i].X_add_number - REG_FR;
5882 }
5883 }
5884 }
5885 break;
5886
5887 case IA64_RS_GR:
5888 if (note == 13)
5889 {
5890 /* This reference applies only to the GR whose value is loaded with
5891 data returned from memory */
5892 specs[count] = tmpl;
5893 specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR;
5894 }
5895 else if (note == 1)
5896 {
5897 if (rsrc_write)
5898 {
5899 for (i=0;i < idesc->num_outputs;i++)
5900 {
5901 if (idesc->operands[i] == IA64_OPND_R1
5902 || idesc->operands[i] == IA64_OPND_R2
5903 || idesc->operands[i] == IA64_OPND_R3)
5904 {
5905 specs[count] = tmpl;
5906 specs[count++].index =
5907 CURR_SLOT.opnd[i].X_add_number - REG_GR;
5908 }
5909 }
5910 }
5911 else
5912 {
5913 /* Look for anything that reads a GR */
5914 for (i=0;i < NELEMS(idesc->operands);i++)
5915 {
5916 if (idesc->operands[i] == IA64_OPND_MR3
5917 || idesc->operands[i] == IA64_OPND_CPUID_R3
5918 || idesc->operands[i] == IA64_OPND_DBR_R3
5919 || idesc->operands[i] == IA64_OPND_IBR_R3
5920 || idesc->operands[i] == IA64_OPND_MSR_R3
5921 || idesc->operands[i] == IA64_OPND_PKR_R3
5922 || idesc->operands[i] == IA64_OPND_PMC_R3
5923 || idesc->operands[i] == IA64_OPND_PMD_R3
5924 || idesc->operands[i] == IA64_OPND_RR_R3
5925 || ((i >= idesc->num_outputs)
5926 && (idesc->operands[i] == IA64_OPND_R1
5927 || idesc->operands[i] == IA64_OPND_R2
5928 || idesc->operands[i] == IA64_OPND_R3)))
5929 {
5930 specs[count] = tmpl;
5931 specs[count++].index =
5932 CURR_SLOT.opnd[i].X_add_number - REG_GR;
5933 }
5934 }
5935 }
5936 }
5937 else
5938 {
5939 UNHANDLED;
5940 }
5941 break;
5942
5943 case IA64_RS_PR:
5944 if (note == 0)
5945 {
5946 if (idesc->operands[0] == IA64_OPND_PR_ROT)
5947 {
5948 for (i=16;i < 63;i++)
5949 {
5950 specs[count] = tmpl;
5951 specs[count++].index = i;
5952 }
5953 }
5954 else
5955 {
5956 for (i=1;i < 63;i++)
5957 {
5958 specs[count] = tmpl;
5959 specs[count++].index = i;
5960 }
5961 }
5962 }
5963 else if (note == 7)
5964 {
5965 valueT mask = 0;
5966 /* mark only those registers indicated by the mask */
5967 if (rsrc_write
5968 && idesc->operands[0] == IA64_OPND_PR)
5969 {
5970 mask = CURR_SLOT.opnd[2].X_add_number;
5971 if (mask & ((valueT)1<<16))
5972 mask |= ~(valueT)0xffff;
5973 for (i=1;i < 63;i++)
5974 {
5975 if (mask & ((valueT)1<<i))
5976 {
5977 specs[count] = tmpl;
5978 specs[count++].index = i;
5979 }
5980 }
5981 }
5982 else if (rsrc_write
5983 && idesc->operands[0] == IA64_OPND_PR_ROT)
5984 {
5985 for (i=16;i < 63;i++)
5986 {
5987 specs[count] = tmpl;
5988 specs[count++].index = i;
5989 }
5990 }
5991 else
5992 {
5993 UNHANDLED;
5994 }
5995 }
5996 else if (note == 11) /* note 11 implies note 1 as well */
5997 {
5998 if (rsrc_write)
5999 {
6000 for (i=0;i < idesc->num_outputs;i++)
6001 {
6002 if (idesc->operands[i] == IA64_OPND_P1
6003 || idesc->operands[i] == IA64_OPND_P2)
6004 {
6005 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
6006 if (regno != 0)
6007 {
6008 specs[count] = tmpl;
6009 specs[count++].index = regno;
6010 }
6011 }
6012 }
6013 }
6014 else
6015 {
6016 UNHANDLED;
6017 }
6018 }
6019 else if (note == 12)
6020 {
6021 if (CURR_SLOT.qp_regno != 0)
6022 {
6023 specs[count] = tmpl;
6024 specs[count++].index = CURR_SLOT.qp_regno;
6025 }
6026 }
6027 else if (note == 1)
6028 {
6029 if (rsrc_write)
6030 {
6031 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
6032 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
6033 if ((idesc->operands[0] == IA64_OPND_P1
6034 || idesc->operands[0] == IA64_OPND_P2)
6035 && p1 != 0 && p1 != 63)
6036 {
6037 specs[count] = tmpl;
6038 specs[count++].index = p1;
6039 }
6040 if ((idesc->operands[1] == IA64_OPND_P1
6041 || idesc->operands[1] == IA64_OPND_P2)
6042 && p2 != 0 && p2 != 63)
6043 {
6044 specs[count] = tmpl;
6045 specs[count++].index = p2;
6046 }
6047 }
6048 else
6049 {
6050 if (CURR_SLOT.qp_regno != 0)
6051 {
6052 specs[count] = tmpl;
6053 specs[count++].index = CURR_SLOT.qp_regno;
6054 }
6055 if (idesc->operands[1] == IA64_OPND_PR)
6056 {
6057 for (i=1;i < 63;i++)
6058 {
6059 specs[count] = tmpl;
6060 specs[count++].index = i;
6061 }
6062 }
6063 }
6064 }
6065 else
6066 {
6067 UNHANDLED;
6068 }
6069 break;
6070
6071 case IA64_RS_PSR:
6072 /* Verify that the instruction is using the PSR bit indicated in
6073 dep->regindex */
6074 if (note == 0)
6075 {
6076 if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM)
6077 {
6078 if (dep->regindex < 6)
6079 {
6080 specs[count++] = tmpl;
6081 }
6082 }
6083 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR)
6084 {
6085 if (dep->regindex < 32
6086 || dep->regindex == 35
6087 || dep->regindex == 36
6088 || (!rsrc_write && dep->regindex == PSR_CPL))
6089 {
6090 specs[count++] = tmpl;
6091 }
6092 }
6093 else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L)
6094 {
6095 if (dep->regindex < 32
6096 || dep->regindex == 35
6097 || dep->regindex == 36
6098 || (rsrc_write && dep->regindex == PSR_CPL))
6099 {
6100 specs[count++] = tmpl;
6101 }
6102 }
6103 else
6104 {
6105 /* Several PSR bits have very specific dependencies. */
6106 switch (dep->regindex)
6107 {
6108 default:
6109 specs[count++] = tmpl;
6110 break;
6111 case PSR_IC:
6112 if (rsrc_write)
6113 {
6114 specs[count++] = tmpl;
6115 }
6116 else
6117 {
6118 /* Only certain CR accesses use PSR.ic */
6119 if (idesc->operands[0] == IA64_OPND_CR3
6120 || idesc->operands[1] == IA64_OPND_CR3)
6121 {
6122 int index =
6123 ((idesc->operands[0] == IA64_OPND_CR3)
6124 ? 0 : 1);
6125 int regno =
6126 CURR_SLOT.opnd[index].X_add_number - REG_CR;
6127
6128 switch (regno)
6129 {
6130 default:
6131 break;
6132 case CR_ITIR:
6133 case CR_IFS:
6134 case CR_IIM:
6135 case CR_IIP:
6136 case CR_IPSR:
6137 case CR_ISR:
6138 case CR_IFA:
6139 case CR_IHA:
6140 case CR_IIPA:
6141 specs[count++] = tmpl;
6142 break;
6143 }
6144 }
6145 }
6146 break;
6147 case PSR_CPL:
6148 if (rsrc_write)
6149 {
6150 specs[count++] = tmpl;
6151 }
6152 else
6153 {
6154 /* Only some AR accesses use cpl */
6155 if (idesc->operands[0] == IA64_OPND_AR3
6156 || idesc->operands[1] == IA64_OPND_AR3)
6157 {
6158 int index =
6159 ((idesc->operands[0] == IA64_OPND_AR3)
6160 ? 0 : 1);
6161 int regno =
6162 CURR_SLOT.opnd[index].X_add_number - REG_AR;
6163
6164 if (regno == AR_ITC
6165 || (index == 0
6166 && (regno == AR_ITC
6167 || regno == AR_RSC
6168 || (regno >= AR_K0
6169 && regno <= AR_K7))))
6170 {
6171 specs[count++] = tmpl;
6172 }
6173 }
6174 else
6175 {
6176 specs[count++] = tmpl;
6177 }
6178 break;
6179 }
6180 }
6181 }
6182 }
6183 else if (note == 7)
6184 {
6185 valueT mask = 0;
6186 if (idesc->operands[0] == IA64_OPND_IMMU24)
6187 {
6188 mask = CURR_SLOT.opnd[0].X_add_number;
6189 }
6190 else
6191 {
6192 UNHANDLED;
6193 }
6194 if (mask & ((valueT)1<<dep->regindex))
6195 {
6196 specs[count++] = tmpl;
6197 }
6198 }
6199 else if (note == 8)
6200 {
6201 int min = dep->regindex == PSR_DFL ? 2 : 32;
6202 int max = dep->regindex == PSR_DFL ? 31 : 127;
6203 /* dfh is read on FR32-127; dfl is read on FR2-31 */
6204 for (i=0;i < NELEMS(idesc->operands);i++)
6205 {
6206 if (idesc->operands[i] == IA64_OPND_F1
6207 || idesc->operands[i] == IA64_OPND_F2
6208 || idesc->operands[i] == IA64_OPND_F3
6209 || idesc->operands[i] == IA64_OPND_F4)
6210 {
6211 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
6212 if (reg >= min && reg <= max)
6213 {
6214 specs[count++] = tmpl;
6215 }
6216 }
6217 }
6218 }
6219 else if (note == 9)
6220 {
6221 int min = dep->regindex == PSR_MFL ? 2 : 32;
6222 int max = dep->regindex == PSR_MFL ? 31 : 127;
6223 /* mfh is read on writes to FR32-127; mfl is read on writes to
6224 FR2-31 */
6225 for (i=0;i < idesc->num_outputs;i++)
6226 {
6227 if (idesc->operands[i] == IA64_OPND_F1)
6228 {
6229 int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR;
6230 if (reg >= min && reg <= max)
6231 {
6232 specs[count++] = tmpl;
6233 }
6234 }
6235 }
6236 }
6237 else if (note == 10)
6238 {
6239 for (i=0;i < NELEMS(idesc->operands);i++)
6240 {
6241 if (idesc->operands[i] == IA64_OPND_R1
6242 || idesc->operands[i] == IA64_OPND_R2
6243 || idesc->operands[i] == IA64_OPND_R3)
6244 {
6245 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
6246 if (regno >= 16 && regno <= 31)
6247 {
6248 specs[count++] = tmpl;
6249 }
6250 }
6251 }
6252 }
6253 else
6254 {
6255 UNHANDLED;
6256 }
6257 break;
6258
6259 case IA64_RS_AR_FPSR:
6260 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3)
6261 {
6262 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
6263 if (regno == AR_FPSR)
6264 {
6265 specs[count++] = tmpl;
6266 }
6267 }
6268 else
6269 {
6270 specs[count++] = tmpl;
6271 }
6272 break;
6273
6274 case IA64_RS_ARX:
6275 /* Handle all AR[REG] resources */
6276 if (note == 0 || note == 1)
6277 {
6278 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR;
6279 if (idesc->operands[!rsrc_write] == IA64_OPND_AR3
6280 && regno == dep->regindex)
6281 {
6282 specs[count++] = tmpl;
6283 }
6284 /* other AR[REG] resources may be affected by AR accesses */
6285 else if (idesc->operands[0] == IA64_OPND_AR3)
6286 {
6287 /* AR[] writes */
6288 regno = CURR_SLOT.opnd[0].X_add_number - REG_AR;
6289 switch (dep->regindex)
6290 {
6291 default:
6292 break;
6293 case AR_BSP:
6294 case AR_RNAT:
6295 if (regno == AR_BSPSTORE)
6296 {
6297 specs[count++] = tmpl;
6298 }
6299 case AR_RSC:
6300 if (!rsrc_write &&
6301 (regno == AR_BSPSTORE
6302 || regno == AR_RNAT))
6303 {
6304 specs[count++] = tmpl;
6305 }
6306 break;
6307 }
6308 }
6309 else if (idesc->operands[1] == IA64_OPND_AR3)
6310 {
6311 /* AR[] reads */
6312 regno = CURR_SLOT.opnd[1].X_add_number - REG_AR;
6313 switch (dep->regindex)
6314 {
6315 default:
6316 break;
6317 case AR_RSC:
6318 if (regno == AR_BSPSTORE || regno == AR_RNAT)
6319 {
6320 specs[count++] = tmpl;
6321 }
6322 break;
6323 }
6324 }
6325 else
6326 {
6327 specs[count++] = tmpl;
6328 }
6329 }
6330 else
6331 {
6332 UNHANDLED;
6333 }
6334 break;
6335
6336 case IA64_RS_CRX:
6337 /* Handle all CR[REG] resources */
6338 if (note == 0 || note == 1)
6339 {
6340 if (idesc->operands[!rsrc_write] == IA64_OPND_CR3)
6341 {
6342 int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR;
6343 if (regno == dep->regindex)
6344 {
6345 specs[count++] = tmpl;
6346 }
6347 else if (!rsrc_write)
6348 {
6349 /* Reads from CR[IVR] affect other resources. */
6350 if (regno == CR_IVR)
6351 {
6352 if ((dep->regindex >= CR_IRR0
6353 && dep->regindex <= CR_IRR3)
6354 || dep->regindex == CR_TPR)
6355 {
6356 specs[count++] = tmpl;
6357 }
6358 }
6359 }
6360 }
6361 else
6362 {
6363 specs[count++] = tmpl;
6364 }
6365 }
6366 else
6367 {
6368 UNHANDLED;
6369 }
6370 break;
6371
6372 case IA64_RS_INSERVICE:
6373 /* look for write of EOI (67) or read of IVR (65) */
6374 if ((idesc->operands[0] == IA64_OPND_CR3
6375 && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI)
6376 || (idesc->operands[1] == IA64_OPND_CR3
6377 && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR))
6378 {
6379 specs[count++] = tmpl;
6380 }
6381 break;
6382
6383 case IA64_RS_GR0:
6384 if (note == 1)
6385 {
6386 specs[count++] = tmpl;
6387 }
6388 else
6389 {
6390 UNHANDLED;
6391 }
6392 break;
6393
6394 case IA64_RS_CFM:
6395 if (note != 2)
6396 {
6397 specs[count++] = tmpl;
6398 }
6399 else
6400 {
6401 /* Check if any of the registers accessed are in the rotating region.
6402 mov to/from pr accesses CFM only when qp_regno is in the rotating
6403 region */
6404 for (i=0;i < NELEMS(idesc->operands);i++)
6405 {
6406 if (idesc->operands[i] == IA64_OPND_R1
6407 || idesc->operands[i] == IA64_OPND_R2
6408 || idesc->operands[i] == IA64_OPND_R3)
6409 {
6410 int num = CURR_SLOT.opnd[i].X_add_number - REG_GR;
6411 /* Assumes that md.rot.num_regs is always valid */
6412 if (md.rot.num_regs > 0
6413 && num > 31
6414 && num < 31 + md.rot.num_regs)
6415 {
6416 specs[count] = tmpl;
6417 specs[count++].specific = 0;
6418 }
6419 }
6420 else if (idesc->operands[i] == IA64_OPND_F1
6421 || idesc->operands[i] == IA64_OPND_F2
6422 || idesc->operands[i] == IA64_OPND_F3
6423 || idesc->operands[i] == IA64_OPND_F4)
6424 {
6425 int num = CURR_SLOT.opnd[i].X_add_number - REG_FR;
6426 if (num > 31)
6427 {
6428 specs[count] = tmpl;
6429 specs[count++].specific = 0;
6430 }
6431 }
6432 else if (idesc->operands[i] == IA64_OPND_P1
6433 || idesc->operands[i] == IA64_OPND_P2)
6434 {
6435 int num = CURR_SLOT.opnd[i].X_add_number - REG_P;
6436 if (num > 15)
6437 {
6438 specs[count] = tmpl;
6439 specs[count++].specific = 0;
6440 }
6441 }
6442 }
6443 if (CURR_SLOT.qp_regno > 15)
6444 {
6445 specs[count] = tmpl;
6446 specs[count++].specific = 0;
6447 }
6448 }
6449 break;
6450
6451 case IA64_RS_PR63:
6452 if (note == 0)
6453 {
6454 specs[count++] = tmpl;
6455 }
6456 else if (note == 11)
6457 {
6458 if ((idesc->operands[0] == IA64_OPND_P1
6459 && CURR_SLOT.opnd[0].X_add_number - REG_P == 63)
6460 || (idesc->operands[1] == IA64_OPND_P2
6461 && CURR_SLOT.opnd[1].X_add_number - REG_P == 63))
6462 {
6463 specs[count++] = tmpl;
6464 }
6465 }
6466 else if (note == 12)
6467 {
6468 if (CURR_SLOT.qp_regno == 63)
6469 {
6470 specs[count++] = tmpl;
6471 }
6472 }
6473 else if (note == 7)
6474 {
6475 valueT mask = 0;
6476 if (idesc->operands[2] == IA64_OPND_IMM17)
6477 mask = CURR_SLOT.opnd[2].X_add_number;
6478 if (mask & ((valueT)1<<63))
6479 {
6480 specs[count++] = tmpl;
6481 }
6482 }
6483 else if (note == 1)
6484 {
6485 if (rsrc_write)
6486 {
6487 for (i=0;i < idesc->num_outputs;i++)
6488 if ((idesc->operands[i] == IA64_OPND_P1
6489 || idesc->operands[i] == IA64_OPND_P2)
6490 && CURR_SLOT.opnd[i].X_add_number - REG_P == 63)
6491 {
6492 specs[count++] = tmpl;
6493 }
6494 }
6495 else
6496 {
6497 if (CURR_SLOT.qp_regno == 63)
6498 {
6499 specs[count++] = tmpl;
6500 }
6501 }
6502 }
6503 else
6504 {
6505 UNHANDLED;
6506 }
6507 break;
6508
6509 case IA64_RS_RSE:
6510 /* FIXME we can identify some individual RSE written resources, but RSE
6511 read resources have not yet been completely identified, so for now
6512 treat RSE as a single resource */
6513 if (strncmp (idesc->name, "mov", 3) == 0)
6514 {
6515 if (rsrc_write)
6516 {
6517 if (idesc->operands[0] == IA64_OPND_AR3
6518 && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE)
6519 {
6520 specs[count] = tmpl;
6521 specs[count++].index = 0; /* IA64_RSE_BSPLOAD/RNATBITINDEX */
6522 }
6523 }
6524 else
6525 {
6526 if (idesc->operands[0] == IA64_OPND_AR3)
6527 {
6528 if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE
6529 || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT)
6530 {
6531 specs[count++] = tmpl;
6532 }
6533 }
6534 else if (idesc->operands[1] == IA64_OPND_AR3)
6535 {
6536 if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP
6537 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE
6538 || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT)
6539 {
6540 specs[count++] = tmpl;
6541 }
6542 }
6543 }
6544 }
6545 else
6546 {
6547 specs[count++] = tmpl;
6548 }
6549 break;
6550
6551 case IA64_RS_ANY:
6552 /* FIXME -- do any of these need to be non-specific? */
6553 specs[count++] = tmpl;
6554 break;
6555
6556 default:
6557 as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier);
6558 break;
6559 }
6560
6561 return count;
6562 }
6563
6564 /* Clear branch flags on marked resources. This breaks the link between the
6565 QP of the marking instruction and a subsequent branch on the same QP.
6566 */
6567 static void
6568 clear_qp_branch_flag (mask)
6569 valueT mask;
6570 {
6571 int i;
6572 for (i = 0;i < regdepslen;i++)
6573 {
6574 valueT bit = ((valueT)1 << regdeps[i].qp_regno);
6575 if ((bit & mask) != 0)
6576 {
6577 regdeps[i].link_to_qp_branch = 0;
6578 }
6579 }
6580 }
6581
6582 /* Remove any mutexes which contain any of the PRs indicated in the mask.
6583
6584 Any changes to a PR clears the mutex relations which include that PR.
6585 */
6586 static void
6587 clear_qp_mutex (mask)
6588 valueT mask;
6589 {
6590 int i;
6591
6592 i = 0;
6593 while (i < qp_mutexeslen)
6594 {
6595 if ((qp_mutexes[i].prmask & mask) != 0)
6596 {
6597 if (md.debug_dv)
6598 {
6599 fprintf (stderr, " Clearing mutex relation");
6600 print_prmask (qp_mutexes[i].prmask);
6601 fprintf (stderr, "\n");
6602 }
6603 qp_mutexes[i] = qp_mutexes[--qp_mutexeslen];
6604 }
6605 else
6606 ++i;
6607 }
6608 }
6609
6610 /* Clear implies relations which contain PRs in the given masks.
6611 P1_MASK indicates the source of the implies relation, while P2_MASK
6612 indicates the implied PR.
6613 */
6614 static void
6615 clear_qp_implies (p1_mask, p2_mask)
6616 valueT p1_mask;
6617 valueT p2_mask;
6618 {
6619 int i;
6620
6621 i = 0;
6622 while (i < qp_implieslen)
6623 {
6624 if ((((valueT)1 << qp_implies[i].p1) & p1_mask) != 0
6625 || (((valueT)1 << qp_implies[i].p2) & p2_mask) != 0)
6626 {
6627 if (md.debug_dv)
6628 fprintf (stderr, "Clearing implied relation PR%d->PR%d\n",
6629 qp_implies[i].p1, qp_implies[i].p2);
6630 qp_implies[i] = qp_implies[--qp_implieslen];
6631 }
6632 else
6633 ++i;
6634 }
6635 }
6636
6637 /* add the PRs specified to the list of implied relations */
6638 static void
6639 add_qp_imply (p1, p2)
6640 int p1, p2;
6641 {
6642 valueT mask;
6643 valueT bit;
6644 int i;
6645
6646 /* p0 is not meaningful here */
6647 if (p1 == 0 || p2 == 0)
6648 abort ();
6649
6650 if (p1 == p2)
6651 return;
6652
6653 /* if it exists already, ignore it */
6654 for (i=0;i < qp_implieslen;i++)
6655 {
6656 if (qp_implies[i].p1 == p1
6657 && qp_implies[i].p2 == p2
6658 && qp_implies[i].path == md.path
6659 && !qp_implies[i].p2_branched)
6660 return;
6661 }
6662
6663 if (qp_implieslen == qp_impliestotlen)
6664 {
6665 qp_impliestotlen += 20;
6666 qp_implies = (struct qp_imply *)
6667 xrealloc ((void *)qp_implies,
6668 qp_impliestotlen * sizeof (struct qp_imply));
6669 }
6670 if (md.debug_dv)
6671 fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2);
6672 qp_implies[qp_implieslen].p1 = p1;
6673 qp_implies[qp_implieslen].p2 = p2;
6674 qp_implies[qp_implieslen].path = md.path;
6675 qp_implies[qp_implieslen++].p2_branched = 0;
6676
6677 /* Add in the implied transitive relations; for everything that p2 implies,
6678 make p1 imply that, too; for everything that implies p1, make it imply p2
6679 as well. */
6680 for (i=0;i < qp_implieslen;i++)
6681 {
6682 if (qp_implies[i].p1 == p2)
6683 add_qp_imply (p1, qp_implies[i].p2);
6684 if (qp_implies[i].p2 == p1)
6685 add_qp_imply (qp_implies[i].p1, p2);
6686 }
6687 /* Add in mutex relations implied by this implies relation; for each mutex
6688 relation containing p2, duplicate it and replace p2 with p1. */
6689 bit = (valueT)1 << p1;
6690 mask = (valueT)1 << p2;
6691 for (i=0;i < qp_mutexeslen;i++)
6692 {
6693 if (qp_mutexes[i].prmask & mask)
6694 add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit);
6695 }
6696 }
6697
6698
6699 /* Add the PRs specified in the mask to the mutex list; this means that only
6700 one of the PRs can be true at any time. PR0 should never be included in
6701 the mask. */
6702 static void
6703 add_qp_mutex (mask)
6704 valueT mask;
6705 {
6706 if (mask & 0x1)
6707 abort ();
6708
6709 if (qp_mutexeslen == qp_mutexestotlen)
6710 {
6711 qp_mutexestotlen += 20;
6712 qp_mutexes = (struct qpmutex *)
6713 xrealloc ((void *)qp_mutexes,
6714 qp_mutexestotlen * sizeof (struct qpmutex));
6715 }
6716 if (md.debug_dv)
6717 {
6718 fprintf (stderr, " Registering mutex on");
6719 print_prmask (mask);
6720 fprintf (stderr, "\n");
6721 }
6722 qp_mutexes[qp_mutexeslen].path = md.path;
6723 qp_mutexes[qp_mutexeslen++].prmask = mask;
6724 }
6725
6726 static void
6727 clear_register_values ()
6728 {
6729 int i;
6730 if (md.debug_dv)
6731 fprintf (stderr, " Clearing register values\n");
6732 for (i=1;i < NELEMS(gr_values);i++)
6733 gr_values[i].known = 0;
6734 }
6735
6736 /* Keep track of register values/changes which affect DV tracking.
6737
6738 optimization note: should add a flag to classes of insns where otherwise we
6739 have to examine a group of strings to identify them.
6740
6741 */
6742 static void
6743 note_register_values (idesc)
6744 struct ia64_opcode *idesc;
6745 {
6746 valueT qp_changemask = 0;
6747 int i;
6748
6749 /* invalidate values for registers being written to */
6750 for (i=0;i < idesc->num_outputs;i++)
6751 {
6752 if (idesc->operands[i] == IA64_OPND_R1
6753 || idesc->operands[i] == IA64_OPND_R2
6754 || idesc->operands[i] == IA64_OPND_R3)
6755 {
6756 int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR;
6757 if (regno > 0 && regno < NELEMS(gr_values))
6758 gr_values[regno].known = 0;
6759 }
6760 else if (idesc->operands[i] == IA64_OPND_P1
6761 || idesc->operands[i] == IA64_OPND_P2)
6762 {
6763 int regno = CURR_SLOT.opnd[i].X_add_number - REG_P;
6764 qp_changemask |= (valueT)1 << regno;
6765 }
6766 else if (idesc->operands[i] == IA64_OPND_PR)
6767 {
6768 if (idesc->operands[2] & (valueT)0x10000)
6769 qp_changemask = ~(valueT)0x1FFFF | idesc->operands[2];
6770 else
6771 qp_changemask = idesc->operands[2];
6772 break;
6773 }
6774 else if (idesc->operands[i] == IA64_OPND_PR_ROT)
6775 {
6776 if (idesc->operands[1] & ((valueT)1 << 43))
6777 qp_changemask = ~(valueT)0xFFFFFFFFFFF | idesc->operands[1];
6778 else
6779 qp_changemask = idesc->operands[1];
6780 qp_changemask &= ~(valueT)0xFFFF;
6781 break;
6782 }
6783 }
6784
6785 /* Always clear qp branch flags on any PR change */
6786 /* FIXME there may be exceptions for certain compares */
6787 clear_qp_branch_flag (qp_changemask);
6788
6789 /* invalidate rotating registers on insns which affect RRBs in CFM */
6790 if (idesc->flags & IA64_OPCODE_MOD_RRBS)
6791 {
6792 qp_changemask |= ~(valueT)0xFFFF;
6793 if (strcmp (idesc->name, "clrrrb.pr") != 0)
6794 {
6795 for (i=32;i < 32+md.rot.num_regs;i++)
6796 gr_values[i].known = 0;
6797 }
6798 clear_qp_mutex (qp_changemask);
6799 clear_qp_implies (qp_changemask, qp_changemask);
6800 }
6801 /* after a call, all register values are undefined, except those marked
6802 as "safe" */
6803 else if (strncmp (idesc->name, "br.call", 6) == 0
6804 || strncmp (idesc->name, "brl.call", 7) == 0)
6805 {
6806 // FIXME keep GR values which are marked as "safe_across_calls"
6807 clear_register_values ();
6808 clear_qp_mutex (~qp_safe_across_calls);
6809 clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls);
6810 clear_qp_branch_flag (~qp_safe_across_calls);
6811 }
6812 /* Look for mutex and implies relations */
6813 else if ((idesc->operands[0] == IA64_OPND_P1
6814 || idesc->operands[0] == IA64_OPND_P2)
6815 && (idesc->operands[1] == IA64_OPND_P1
6816 || idesc->operands[1] == IA64_OPND_P2))
6817 {
6818 int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P;
6819 int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P;
6820 valueT p1mask = (valueT)1 << p1;
6821 valueT p2mask = (valueT)1 << p2;
6822
6823 /* if one of the PRs is PR0, we can't really do anything */
6824 if (p1 == 0 || p2 == 0)
6825 {
6826 if (md.debug_dv)
6827 fprintf (stderr, " Ignoring PRs due to inclusion of p0\n");
6828 }
6829 /* In general, clear mutexes and implies which include P1 or P2,
6830 with the following exceptions */
6831 else if (strstr (idesc->name, ".or.andcm") != NULL)
6832 {
6833 add_qp_mutex (p1mask | p2mask);
6834 clear_qp_implies (p2mask, p1mask);
6835 }
6836 else if (strstr (idesc->name, ".and.orcm") != NULL)
6837 {
6838 add_qp_mutex (p1mask | p2mask);
6839 clear_qp_implies (p1mask, p2mask);
6840 }
6841 else if (strstr (idesc->name, ".and") != NULL)
6842 {
6843 clear_qp_implies (0, p1mask | p2mask);
6844 }
6845 else if (strstr (idesc->name, ".or") != NULL)
6846 {
6847 clear_qp_mutex (p1mask | p2mask);
6848 clear_qp_implies (p1mask | p2mask, 0);
6849 }
6850 else
6851 {
6852 clear_qp_implies (p1mask | p2mask, p1mask | p2mask);
6853 if (strstr (idesc->name, ".unc") != NULL)
6854 {
6855 add_qp_mutex (p1mask | p2mask);
6856 if (CURR_SLOT.qp_regno != 0)
6857 {
6858 add_qp_imply (CURR_SLOT.opnd[0].X_add_number - REG_P,
6859 CURR_SLOT.qp_regno);
6860 add_qp_imply (CURR_SLOT.opnd[1].X_add_number - REG_P,
6861 CURR_SLOT.qp_regno);
6862 }
6863 }
6864 else if (CURR_SLOT.qp_regno == 0)
6865 {
6866 add_qp_mutex (p1mask | p2mask);
6867 }
6868 else
6869 {
6870 clear_qp_mutex (p1mask | p2mask);
6871 }
6872 }
6873 }
6874 /* Look for mov imm insns into GRs */
6875 else if (idesc->operands[0] == IA64_OPND_R1
6876 && (idesc->operands[1] == IA64_OPND_IMM22
6877 || idesc->operands[1] == IA64_OPND_IMMU64)
6878 && (strcmp(idesc->name, "mov") == 0
6879 || strcmp(idesc->name, "movl") == 0))
6880 {
6881 int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR;
6882 if (regno > 0 && regno < NELEMS(gr_values))
6883 {
6884 gr_values[regno].known = 1;
6885 gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number;
6886 gr_values[regno].path = md.path;
6887 if (md.debug_dv)
6888 fprintf (stderr, " Know gr%d = 0x%llx\n",
6889 regno, gr_values[regno].value);
6890 }
6891 }
6892 else
6893 {
6894 clear_qp_mutex (qp_changemask);
6895 clear_qp_implies (qp_changemask, qp_changemask);
6896 }
6897 }
6898
6899 /* Return whether the given predicate registers are currently mutex */
6900 static int
6901 qp_mutex (p1, p2, path)
6902 int p1;
6903 int p2;
6904 int path;
6905 {
6906 int i;
6907 valueT mask;
6908
6909 if (p1 != p2)
6910 {
6911 mask = ((valueT)1<<p1) | (valueT)1<<p2;
6912 for (i=0;i < qp_mutexeslen;i++)
6913 {
6914 if (qp_mutexes[i].path >= path
6915 && (qp_mutexes[i].prmask & mask) == mask)
6916 return 1;
6917 }
6918 }
6919 return 0;
6920 }
6921
6922 /* Return whether the given resource is in the given insn's list of chks
6923 Return 1 if the conflict is absolutely determined, 2 if it's a potential
6924 conflict.
6925 */
6926 static int
6927 resources_match (rs, idesc, note, qp_regno, path)
6928 struct rsrc *rs;
6929 struct ia64_opcode *idesc;
6930 int note;
6931 int qp_regno;
6932 int path;
6933 {
6934 struct rsrc specs[MAX_SPECS];
6935 int count;
6936
6937 /* If the marked resource's qp_regno and the given qp_regno are mutex,
6938 we don't need to check. One exception is note 11, which indicates that
6939 target predicates are written regardless of PR[qp]. */
6940 if (qp_mutex (rs->qp_regno, qp_regno, path)
6941 && note != 11)
6942 return 0;
6943
6944 count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path);
6945 while (count-- > 0)
6946 {
6947 /* UNAT checking is a bit more specific than other resources */
6948 if (rs->dependency->specifier == IA64_RS_AR_UNAT
6949 && specs[count].mem_offset.hint
6950 && rs->mem_offset.hint)
6951 {
6952 if (rs->mem_offset.base == specs[count].mem_offset.base)
6953 {
6954 if (((rs->mem_offset.offset >> 3) & 0x3F) ==
6955 ((specs[count].mem_offset.offset >> 3) & 0x3F))
6956 return 1;
6957 else
6958 continue;
6959 }
6960 }
6961
6962 /* If either resource is not specific, conservatively assume a conflict
6963 */
6964 if (!specs[count].specific || !rs->specific)
6965 return 2;
6966 else if (specs[count].index == rs->index)
6967 return 1;
6968 }
6969 #if 0
6970 if (md.debug_dv)
6971 fprintf (stderr, " No %s conflicts\n", rs->dependency->name);
6972 #endif
6973
6974 return 0;
6975 }
6976
6977 /* Indicate an instruction group break; if INSERT_STOP is non-zero, then
6978 insert a stop to create the break. Update all resource dependencies
6979 appropriately. If QP_REGNO is non-zero, only apply the break to resources
6980 which use the same QP_REGNO and have the link_to_qp_branch flag set.
6981 If SAVE_CURRENT is non-zero, don't affect resources marked by the current
6982 instruction.
6983 */
6984
6985 static void
6986 insn_group_break (insert_stop, qp_regno, save_current)
6987 int insert_stop;
6988 int qp_regno;
6989 int save_current;
6990 {
6991 int i;
6992
6993 if (insert_stop && md.num_slots_in_use > 0)
6994 PREV_SLOT.end_of_insn_group = 1;
6995
6996 if (md.debug_dv)
6997 {
6998 fprintf (stderr, " Insn group break%s",
6999 (insert_stop ? " (w/stop)" : ""));
7000 if (qp_regno != 0)
7001 fprintf (stderr, " effective for QP=%d", qp_regno);
7002 fprintf (stderr, "\n");
7003 }
7004
7005 i = 0;
7006 while (i < regdepslen)
7007 {
7008 const struct ia64_dependency *dep = regdeps[i].dependency;
7009
7010 if (qp_regno != 0
7011 && regdeps[i].qp_regno != qp_regno)
7012 {
7013 ++i;
7014 continue;
7015 }
7016
7017 if (save_current
7018 && CURR_SLOT.src_file == regdeps[i].file
7019 && CURR_SLOT.src_line == regdeps[i].line)
7020 {
7021 ++i;
7022 continue;
7023 }
7024
7025 /* clear dependencies which are automatically cleared by a stop, or
7026 those that have reached the appropriate state of insn serialization */
7027 if (dep->semantics == IA64_DVS_IMPLIED
7028 || dep->semantics == IA64_DVS_IMPLIEDF
7029 || regdeps[i].insn_srlz == STATE_SRLZ)
7030 {
7031 print_dependency ("Removing", i);
7032 regdeps[i] = regdeps[--regdepslen];
7033 }
7034 else
7035 {
7036 if (dep->semantics == IA64_DVS_DATA
7037 || dep->semantics == IA64_DVS_INSTR
7038 || dep->semantics == IA64_DVS_SPECIFIC)
7039 {
7040 if (regdeps[i].insn_srlz == STATE_NONE)
7041 regdeps[i].insn_srlz = STATE_STOP;
7042 if (regdeps[i].data_srlz == STATE_NONE)
7043 regdeps[i].data_srlz = STATE_STOP;
7044 }
7045 ++i;
7046 }
7047 }
7048 }
7049
7050 /* Add the given resource usage spec to the list of active dependencies */
7051 static void
7052 mark_resource (idesc, dep, spec, depind, path)
7053 struct ia64_opcode *idesc;
7054 const struct ia64_dependency *dep;
7055 struct rsrc *spec;
7056 int depind;
7057 int path;
7058 {
7059 if (regdepslen == regdepstotlen)
7060 {
7061 regdepstotlen += 20;
7062 regdeps = (struct rsrc *)
7063 xrealloc ((void *)regdeps,
7064 regdepstotlen * sizeof(struct rsrc));
7065 }
7066
7067 regdeps[regdepslen] = *spec;
7068 regdeps[regdepslen].depind = depind;
7069 regdeps[regdepslen].path = path;
7070 regdeps[regdepslen].file = CURR_SLOT.src_file;
7071 regdeps[regdepslen].line = CURR_SLOT.src_line;
7072
7073 print_dependency ("Adding", regdepslen);
7074
7075 ++regdepslen;
7076 }
7077
7078 static void
7079 print_dependency (action, depind)
7080 const char *action;
7081 int depind;
7082 {
7083 if (md.debug_dv)
7084 {
7085 fprintf (stderr, " %s %s '%s'",
7086 action, dv_mode[(regdeps[depind].dependency)->mode],
7087 (regdeps[depind].dependency)->name);
7088 if (regdeps[depind].specific && regdeps[depind].index != 0)
7089 fprintf (stderr, " (%d)", regdeps[depind].index);
7090 if (regdeps[depind].mem_offset.hint)
7091 fprintf (stderr, " 0x%llx+0x%llx",
7092 regdeps[depind].mem_offset.base,
7093 regdeps[depind].mem_offset.offset);
7094 fprintf (stderr, "\n");
7095 }
7096 }
7097
7098 static void
7099 instruction_serialization ()
7100 {
7101 int i;
7102 if (md.debug_dv)
7103 fprintf (stderr, " Instruction serialization\n");
7104 for (i=0;i < regdepslen;i++)
7105 if (regdeps[i].insn_srlz == STATE_STOP)
7106 regdeps[i].insn_srlz = STATE_SRLZ;
7107 }
7108
7109 static void
7110 data_serialization ()
7111 {
7112 int i = 0;
7113 if (md.debug_dv)
7114 fprintf (stderr, " Data serialization\n");
7115 while (i < regdepslen)
7116 {
7117 if (regdeps[i].data_srlz == STATE_STOP
7118 /* Note: as of 991210, all "other" dependencies are cleared by a
7119 data serialization. This might change with new tables */
7120 || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER)
7121 {
7122 print_dependency ("Removing", i);
7123 regdeps[i] = regdeps[--regdepslen];
7124 }
7125 else
7126 ++i;
7127 }
7128 }
7129
7130 /* Insert stops and serializations as needed to avoid DVs */
7131 static void
7132 remove_marked_resource (rs)
7133 struct rsrc *rs;
7134 {
7135 switch (rs->dependency->semantics)
7136 {
7137 case IA64_DVS_SPECIFIC:
7138 if (md.debug_dv)
7139 fprintf (stderr, "Implementation-specific, assume worst case...\n");
7140 /* ...fall through... */
7141 case IA64_DVS_INSTR:
7142 if (md.debug_dv)
7143 fprintf (stderr, "Inserting instr serialization\n");
7144 if (rs->insn_srlz < STATE_STOP)
7145 insn_group_break (1, 0, 0);
7146 if (rs->insn_srlz < STATE_SRLZ)
7147 {
7148 int oldqp = CURR_SLOT.qp_regno;
7149 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
7150 /* Manually jam a srlz.i insn into the stream */
7151 CURR_SLOT.qp_regno = 0;
7152 CURR_SLOT.idesc = ia64_find_opcode ("srlz.i");
7153 instruction_serialization ();
7154 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
7155 if (++md.num_slots_in_use >= NUM_SLOTS)
7156 emit_one_bundle ();
7157 CURR_SLOT.qp_regno = oldqp;
7158 CURR_SLOT.idesc = oldidesc;
7159 }
7160 insn_group_break (1, 0, 0);
7161 break;
7162 case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all
7163 "other" types of DV are eliminated
7164 by a data serialization */
7165 case IA64_DVS_DATA:
7166 if (md.debug_dv)
7167 fprintf (stderr, "Inserting data serialization\n");
7168 if (rs->data_srlz < STATE_STOP)
7169 insn_group_break (1, 0, 0);
7170 {
7171 int oldqp = CURR_SLOT.qp_regno;
7172 struct ia64_opcode *oldidesc = CURR_SLOT.idesc;
7173 /* Manually jam a srlz.d insn into the stream */
7174 CURR_SLOT.qp_regno = 0;
7175 CURR_SLOT.idesc = ia64_find_opcode ("srlz.d");
7176 data_serialization ();
7177 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
7178 if (++md.num_slots_in_use >= NUM_SLOTS)
7179 emit_one_bundle ();
7180 CURR_SLOT.qp_regno = oldqp;
7181 CURR_SLOT.idesc = oldidesc;
7182 }
7183 break;
7184 case IA64_DVS_IMPLIED:
7185 case IA64_DVS_IMPLIEDF:
7186 if (md.debug_dv)
7187 fprintf (stderr, "Inserting stop\n");
7188 insn_group_break (1, 0, 0);
7189 break;
7190 default:
7191 break;
7192 }
7193 }
7194
7195 /* Check the resources used by the given opcode against the current dependency
7196 list.
7197
7198 The check is run once for each execution path encountered. In this case,
7199 a unique execution path is the sequence of instructions following a code
7200 entry point, e.g. the following has three execution paths, one starting
7201 at L0, one at L1, and one at L2.
7202
7203 L0: nop
7204 L1: add
7205 L2: add
7206 br.ret
7207 */
7208 static void
7209 check_dependencies (idesc)
7210 struct ia64_opcode *idesc;
7211 {
7212 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
7213 int path;
7214 int i;
7215
7216 /* Note that the number of marked resources may change within the
7217 loop if in auto mode. */
7218 i = 0;
7219 while (i < regdepslen)
7220 {
7221 struct rsrc *rs = &regdeps[i];
7222 const struct ia64_dependency *dep = rs->dependency;
7223 int chkind;
7224 int note;
7225 int start_over = 0;
7226
7227 if (dep->semantics == IA64_DVS_NONE
7228 || (chkind = depends_on (rs->depind, idesc)) == -1)
7229 {
7230 ++i; continue;
7231 }
7232
7233 note = NOTE(opdeps->chks[chkind]);
7234
7235 /* Check this resource against each execution path seen thus far */
7236 for (path=0;path <= md.path;path++)
7237 {
7238 int matchtype;
7239
7240 /* If the dependency wasn't on the path being checked, ignore it */
7241 if (rs->path < path)
7242 continue;
7243
7244 /* If the QP for this insn implies a QP which has branched, don't
7245 bother checking. Ed. NOTE: I don't think this check is terribly
7246 useful; what's the point of generating code which will only be
7247 reached if its QP is zero?
7248 This code was specifically inserted to handle the following code,
7249 based on notes from Intel's DV checking code, where p1 implies p2.
7250
7251 mov r4 = 2
7252 (p2) br.cond L
7253 (p1) mov r4 = 7
7254
7255 */
7256 if (CURR_SLOT.qp_regno != 0)
7257 {
7258 int skip = 0;
7259 int implies;
7260 for (implies=0;implies < qp_implieslen;implies++)
7261 {
7262 if (qp_implies[implies].path >= path
7263 && qp_implies[implies].p1 == CURR_SLOT.qp_regno
7264 && qp_implies[implies].p2_branched)
7265 {
7266 skip = 1;
7267 break;
7268 }
7269 }
7270 if (skip)
7271 continue;
7272 }
7273
7274 if ((matchtype = resources_match (rs, idesc, note,
7275 CURR_SLOT.qp_regno, path)) != 0)
7276 {
7277 char msg[1024];
7278 char pathmsg[256] = "";
7279 char indexmsg[256] = "";
7280 int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0);
7281
7282 if (path != 0)
7283 sprintf (pathmsg, " when entry is at label '%s'",
7284 md.entry_labels[path-1]);
7285 if (rs->specific && rs->index != 0)
7286 sprintf (indexmsg, ", specific resource number is %d",
7287 rs->index);
7288 sprintf (msg, "Use of '%s' %s %s dependency '%s' (%s)%s%s",
7289 idesc->name,
7290 (certain ? "violates" : "may violate"),
7291 dv_mode[dep->mode], dep->name,
7292 dv_sem[dep->semantics],
7293 pathmsg, indexmsg);
7294
7295 if (md.explicit_mode)
7296 {
7297 as_warn ("%s", msg);
7298 if (path < md.path)
7299 as_warn (_("Only the first path encountering the conflict "
7300 "is reported"));
7301 as_warn_where (rs->file, rs->line,
7302 _("This is the location of the "
7303 "conflicting usage"));
7304 /* Don't bother checking other paths, to avoid duplicating
7305 the same warning */
7306 break;
7307 }
7308 else
7309 {
7310 if (md.debug_dv)
7311 fprintf(stderr, "%s @ %s:%d\n", msg, rs->file, rs->line);
7312
7313 remove_marked_resource (rs);
7314
7315 /* since the set of dependencies has changed, start over */
7316 /* FIXME -- since we're removing dvs as we go, we
7317 probably don't really need to start over... */
7318 start_over = 1;
7319 break;
7320 }
7321 }
7322 }
7323 if (start_over)
7324 i = 0;
7325 else
7326 ++i;
7327 }
7328 }
7329
7330 /* register new dependencies based on the given opcode */
7331 static void
7332 mark_resources (idesc)
7333 struct ia64_opcode *idesc;
7334 {
7335 int i;
7336 const struct ia64_opcode_dependency *opdeps = idesc->dependencies;
7337 int add_only_qp_reads = 0;
7338
7339 /* A conditional branch only uses its resources if it is taken; if it is
7340 taken, we stop following that path. The other branch types effectively
7341 *always* write their resources. If it's not taken, register only QP
7342 reads. */
7343 if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc))
7344 {
7345 add_only_qp_reads = 1;
7346 }
7347
7348 if (md.debug_dv)
7349 fprintf (stderr, "Registering '%s' resource usage\n", idesc->name);
7350
7351 for (i=0;i < opdeps->nregs;i++)
7352 {
7353 const struct ia64_dependency *dep;
7354 struct rsrc specs[MAX_SPECS];
7355 int note;
7356 int path;
7357 int count;
7358
7359 dep = ia64_find_dependency (opdeps->regs[i]);
7360 note = NOTE(opdeps->regs[i]);
7361
7362 if (add_only_qp_reads
7363 && !(dep->mode == IA64_DV_WAR
7364 && (dep->specifier == IA64_RS_PR
7365 || dep->specifier == IA64_RS_PR63)))
7366 continue;
7367
7368 count = specify_resource (dep, idesc, DV_REG, specs, note, md.path);
7369
7370 #if 0
7371 if (md.debug_dv && !count)
7372 fprintf (stderr, " No %s %s usage found (path %d)\n",
7373 dv_mode[dep->mode], dep->name, md.path);
7374 #endif
7375
7376 while (count-- > 0)
7377 {
7378 mark_resource (idesc, dep, &specs[count],
7379 DEP(opdeps->regs[i]), md.path);
7380 }
7381
7382 /* The execution path may affect register values, which may in turn
7383 affect which indirect-access resources are accessed. */
7384 switch (dep->specifier)
7385 {
7386 default:
7387 break;
7388 case IA64_RS_CPUID:
7389 case IA64_RS_DBR:
7390 case IA64_RS_IBR:
7391 case IA64_RS_MSR:
7392 case IA64_RS_PKR:
7393 case IA64_RS_PMC:
7394 case IA64_RS_PMD:
7395 case IA64_RS_RR:
7396 for (path=0;path < md.path;path++)
7397 {
7398 count = specify_resource (dep, idesc, DV_REG, specs, note, path);
7399 while (count-- > 0)
7400 mark_resource (idesc, dep, &specs[count],
7401 DEP(opdeps->regs[i]), path);
7402 }
7403 break;
7404 }
7405 }
7406 }
7407
7408 /* remove dependencies when they no longer apply */
7409 static void
7410 update_dependencies (idesc)
7411 struct ia64_opcode *idesc;
7412 {
7413 int i;
7414
7415 if (strcmp (idesc->name, "srlz.i") == 0)
7416 {
7417 instruction_serialization ();
7418 }
7419 else if (strcmp (idesc->name, "srlz.d") == 0)
7420 {
7421 data_serialization ();
7422 }
7423 else if (is_interruption_or_rfi (idesc)
7424 || is_taken_branch (idesc))
7425 {
7426 /* although technically the taken branch doesn't clear dependencies
7427 which require a srlz.[id], we don't follow the branch; the next
7428 instruction is assumed to start with a clean slate */
7429 regdepslen = 0;
7430 clear_register_values ();
7431 clear_qp_mutex (~(valueT)0);
7432 clear_qp_implies (~(valueT)0, ~(valueT)0);
7433 md.path = 0;
7434 }
7435 else if (is_conditional_branch (idesc)
7436 && CURR_SLOT.qp_regno != 0)
7437 {
7438 int is_call = strstr (idesc->name, ".call") != NULL;
7439
7440 for (i=0;i < qp_implieslen;i++)
7441 {
7442 /* if the conditional branch's predicate is implied by the predicate
7443 in an existing dependency, remove that dependency */
7444 if (qp_implies[i].p2 == CURR_SLOT.qp_regno)
7445 {
7446 int depind = 0;
7447 /* note that this implied predicate takes a branch so that if
7448 a later insn generates a DV but its predicate implies this
7449 one, we can avoid the false DV warning */
7450 qp_implies[i].p2_branched = 1;
7451 while (depind < regdepslen)
7452 {
7453 if (regdeps[depind].qp_regno == qp_implies[i].p1)
7454 {
7455 print_dependency ("Removing", depind);
7456 regdeps[depind] = regdeps[--regdepslen];
7457 }
7458 else
7459 ++depind;
7460 }
7461 }
7462 }
7463 /* Any marked resources which have this same predicate should be
7464 cleared, provided that the QP hasn't been modified between the
7465 marking instruction and the branch.
7466 */
7467 if (is_call)
7468 {
7469 insn_group_break (0, CURR_SLOT.qp_regno, 1);
7470 }
7471 else
7472 {
7473 i = 0;
7474 while (i < regdepslen)
7475 {
7476 if (regdeps[i].qp_regno == CURR_SLOT.qp_regno
7477 && regdeps[i].link_to_qp_branch
7478 && (regdeps[i].file != CURR_SLOT.src_file
7479 || regdeps[i].line != CURR_SLOT.src_line))
7480 {
7481 /* Treat like a taken branch */
7482 print_dependency ("Removing", i);
7483 regdeps[i] = regdeps[--regdepslen];
7484 }
7485 else
7486 ++i;
7487 }
7488 }
7489 }
7490 }
7491
7492 /* Examine the current instruction for dependency violations. */
7493 static int
7494 check_dv (idesc)
7495 struct ia64_opcode *idesc;
7496 {
7497 if (md.debug_dv)
7498 {
7499 fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n",
7500 idesc->name, CURR_SLOT.src_line,
7501 idesc->dependencies->nchks,
7502 idesc->dependencies->nregs);
7503 }
7504
7505 /* Look through the list of currently marked resources; if the current
7506 instruction has the dependency in its chks list which uses that resource,
7507 check against the specific resources used.
7508 */
7509 check_dependencies (idesc);
7510
7511 /*
7512 Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads),
7513 then add them to the list of marked resources.
7514 */
7515 mark_resources (idesc);
7516
7517 /* There are several types of dependency semantics, and each has its own
7518 requirements for being cleared
7519
7520 Instruction serialization (insns separated by interruption, rfi, or
7521 writer + srlz.i + reader, all in separate groups) clears DVS_INSTR.
7522
7523 Data serialization (instruction serialization, or writer + srlz.d +
7524 reader, where writer and srlz.d are in separate groups) clears
7525 DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to
7526 always be the case).
7527
7528 Instruction group break (groups separated by stop, taken branch,
7529 interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF.
7530 */
7531 update_dependencies (idesc);
7532
7533 /* Sometimes, knowing a register value allows us to avoid giving a false DV
7534 warning. Keep track of as many as possible that are useful. */
7535 note_register_values (idesc);
7536
7537 /* We don't need or want this anymore. */
7538 md.mem_offset.hint = 0;
7539
7540 return 0;
7541 }
7542
7543 /* Translate one line of assembly. Pseudo ops and labels do not show
7544 here. */
7545 void
7546 md_assemble (str)
7547 char *str;
7548 {
7549 char *saved_input_line_pointer, *mnemonic;
7550 const struct pseudo_opcode *pdesc;
7551 struct ia64_opcode *idesc;
7552 unsigned char qp_regno;
7553 unsigned int flags;
7554 int ch;
7555
7556 saved_input_line_pointer = input_line_pointer;
7557 input_line_pointer = str;
7558
7559 /* extract the opcode (mnemonic): */
7560
7561 mnemonic = input_line_pointer;
7562 ch = get_symbol_end ();
7563 pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic);
7564 if (pdesc)
7565 {
7566 *input_line_pointer = ch;
7567 (*pdesc->handler) (pdesc->arg);
7568 goto done;
7569 }
7570
7571 /* find the instruction descriptor matching the arguments: */
7572
7573 idesc = ia64_find_opcode (mnemonic);
7574 *input_line_pointer = ch;
7575 if (!idesc)
7576 {
7577 as_bad ("Unknown opcode `%s'", mnemonic);
7578 goto done;
7579 }
7580
7581 idesc = parse_operands (idesc);
7582 if (!idesc)
7583 goto done;
7584
7585 /* Handle the dynamic ops we can handle now: */
7586 if (idesc->type == IA64_TYPE_DYN)
7587 {
7588 if (strcmp (idesc->name, "add") == 0)
7589 {
7590 if (CURR_SLOT.opnd[2].X_op == O_register
7591 && CURR_SLOT.opnd[2].X_add_number < 4)
7592 mnemonic = "addl";
7593 else
7594 mnemonic = "adds";
7595 idesc = ia64_find_opcode (mnemonic);
7596 #if 0
7597 know (!idesc->next);
7598 #endif
7599 }
7600 else if (strcmp (idesc->name, "mov") == 0)
7601 {
7602 enum ia64_opnd opnd1, opnd2;
7603 int rop;
7604
7605 opnd1 = idesc->operands[0];
7606 opnd2 = idesc->operands[1];
7607 if (opnd1 == IA64_OPND_AR3)
7608 rop = 0;
7609 else if (opnd2 == IA64_OPND_AR3)
7610 rop = 1;
7611 else
7612 abort ();
7613 if (CURR_SLOT.opnd[rop].X_op == O_register
7614 && ar_is_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number))
7615 mnemonic = "mov.i";
7616 else
7617 mnemonic = "mov.m";
7618 idesc = ia64_find_opcode (mnemonic);
7619 while (idesc != NULL
7620 && (idesc->operands[0] != opnd1
7621 || idesc->operands[1] != opnd2))
7622 idesc = get_next_opcode (idesc);
7623 }
7624 }
7625
7626 qp_regno = 0;
7627 if (md.qp.X_op == O_register)
7628 qp_regno = md.qp.X_add_number - REG_P;
7629
7630 flags = idesc->flags;
7631
7632 if ((flags & IA64_OPCODE_FIRST) != 0)
7633 insn_group_break (1, 0, 0);
7634
7635 if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0)
7636 {
7637 as_bad ("`%s' cannot be predicated", idesc->name);
7638 goto done;
7639 }
7640
7641 /* build the instruction: */
7642 CURR_SLOT.qp_regno = qp_regno;
7643 CURR_SLOT.idesc = idesc;
7644 as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line);
7645 if (debug_type == DEBUG_DWARF2)
7646 dwarf2_where (&CURR_SLOT.debug_line);
7647
7648 /* Add unwind entry, if there is one. */
7649 if (current_unwind_entry)
7650 {
7651 CURR_SLOT.unwind_record = current_unwind_entry;
7652 current_unwind_entry = NULL;
7653 }
7654
7655 /* check for dependency violations */
7656 if (md.detect_dv)
7657 check_dv(idesc);
7658
7659 md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS;
7660 if (++md.num_slots_in_use >= NUM_SLOTS)
7661 emit_one_bundle ();
7662
7663 if ((flags & IA64_OPCODE_LAST) != 0)
7664 insn_group_break (1, 0, 0);
7665
7666 md.last_text_seg = now_seg;
7667
7668 done:
7669 input_line_pointer = saved_input_line_pointer;
7670 }
7671
7672 /* Called when symbol NAME cannot be found in the symbol table.
7673 Should be used for dynamic valued symbols only. */
7674 symbolS*
7675 md_undefined_symbol (name)
7676 char *name;
7677 {
7678 return 0;
7679 }
7680
7681 /* Called for any expression that can not be recognized. When the
7682 function is called, `input_line_pointer' will point to the start of
7683 the expression. */
7684 void
7685 md_operand (e)
7686 expressionS *e;
7687 {
7688 enum pseudo_type pseudo_type;
7689 size_t len;
7690 int ch, i;
7691
7692 switch (*input_line_pointer)
7693 {
7694 case '@':
7695 /* find what relocation pseudo-function we're dealing with: */
7696 pseudo_type = 0;
7697 ch = *++input_line_pointer;
7698 for (i = 0; i < NELEMS (pseudo_func); ++i)
7699 if (pseudo_func[i].name && pseudo_func[i].name[0] == ch)
7700 {
7701 len = strlen (pseudo_func[i].name);
7702 if (strncmp (pseudo_func[i].name + 1,
7703 input_line_pointer + 1, len - 1) == 0
7704 && !is_part_of_name (input_line_pointer[len]))
7705 {
7706 input_line_pointer += len;
7707 pseudo_type = pseudo_func[i].type;
7708 break;
7709 }
7710 }
7711 switch (pseudo_type)
7712 {
7713 case PSEUDO_FUNC_RELOC:
7714 SKIP_WHITESPACE ();
7715 if (*input_line_pointer != '(')
7716 {
7717 as_bad ("Expected '('");
7718 goto err;
7719 }
7720 ++input_line_pointer; /* skip '(' */
7721 expression (e);
7722 if (*input_line_pointer++ != ')')
7723 {
7724 as_bad ("Missing ')'");
7725 goto err;
7726 }
7727 if (e->X_op != O_symbol)
7728 {
7729 if (e->X_op != O_pseudo_fixup)
7730 {
7731 as_bad ("Not a symbolic expression");
7732 goto err;
7733 }
7734 if (S_GET_VALUE (e->X_op_symbol) == FUNC_FPTR_RELATIVE
7735 && i == FUNC_LT_RELATIVE)
7736 i = FUNC_LT_FPTR_RELATIVE;
7737 else
7738 {
7739 as_bad ("Illegal combination of relocation functions");
7740 goto err;
7741 }
7742 }
7743 /* make sure gas doesn't get rid of local symbols that are used
7744 in relocs: */
7745 e->X_op = O_pseudo_fixup;
7746 e->X_op_symbol = pseudo_func[i].u.sym;
7747 break;
7748
7749 case PSEUDO_FUNC_CONST:
7750 e->X_op = O_constant;
7751 e->X_add_number = pseudo_func[i].u.ival;
7752 break;
7753
7754 default:
7755 as_bad ("Unknown pseudo function `%s'", input_line_pointer - 1);
7756 goto err;
7757 }
7758 break;
7759
7760 case '[':
7761 ++input_line_pointer;
7762 expression (e);
7763 if (*input_line_pointer != ']')
7764 {
7765 as_bad ("Closing bracket misssing");
7766 goto err;
7767 }
7768 else
7769 {
7770 if (e->X_op != O_register)
7771 as_bad ("Register expected as index");
7772
7773 ++input_line_pointer;
7774 e->X_op = O_index;
7775 }
7776 break;
7777
7778 default:
7779 break;
7780 }
7781 return;
7782
7783 err:
7784 ignore_rest_of_line ();
7785 }
7786
7787 /* Return 1 if it's OK to adjust a reloc by replacing the symbol with
7788 a section symbol plus some offset. For relocs involving @fptr(),
7789 directives we don't want such adjustments since we need to have the
7790 original symbol's name in the reloc. */
7791 int
7792 ia64_fix_adjustable (fix)
7793 fixS *fix;
7794 {
7795 /* Prevent all adjustments to global symbols */
7796 if (S_IS_EXTERN (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy))
7797 return 0;
7798
7799 switch (fix->fx_r_type)
7800 {
7801 case BFD_RELOC_IA64_FPTR64I:
7802 case BFD_RELOC_IA64_FPTR32MSB:
7803 case BFD_RELOC_IA64_FPTR32LSB:
7804 case BFD_RELOC_IA64_FPTR64MSB:
7805 case BFD_RELOC_IA64_FPTR64LSB:
7806 case BFD_RELOC_IA64_LTOFF_FPTR22:
7807 case BFD_RELOC_IA64_LTOFF_FPTR64I:
7808 return 0;
7809 default:
7810 break;
7811 }
7812
7813 return 1;
7814 }
7815
7816 int
7817 ia64_force_relocation (fix)
7818 fixS *fix;
7819 {
7820 switch (fix->fx_r_type)
7821 {
7822 case BFD_RELOC_IA64_FPTR64I:
7823 case BFD_RELOC_IA64_FPTR32MSB:
7824 case BFD_RELOC_IA64_FPTR32LSB:
7825 case BFD_RELOC_IA64_FPTR64MSB:
7826 case BFD_RELOC_IA64_FPTR64LSB:
7827
7828 case BFD_RELOC_IA64_LTOFF22:
7829 case BFD_RELOC_IA64_LTOFF64I:
7830 case BFD_RELOC_IA64_LTOFF_FPTR22:
7831 case BFD_RELOC_IA64_LTOFF_FPTR64I:
7832 case BFD_RELOC_IA64_PLTOFF22:
7833 case BFD_RELOC_IA64_PLTOFF64I:
7834 case BFD_RELOC_IA64_PLTOFF64MSB:
7835 case BFD_RELOC_IA64_PLTOFF64LSB:
7836 return 1;
7837
7838 default:
7839 return 0;
7840 }
7841 return 0;
7842 }
7843
7844 /* Decide from what point a pc-relative relocation is relative to,
7845 relative to the pc-relative fixup. Er, relatively speaking. */
7846 long
7847 ia64_pcrel_from_section (fix, sec)
7848 fixS *fix;
7849 segT sec;
7850 {
7851 unsigned long off = fix->fx_frag->fr_address + fix->fx_where;
7852
7853 if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE)
7854 off &= ~0xfUL;
7855
7856 return off;
7857 }
7858
7859 /* This is called whenever some data item (not an instruction) needs a
7860 fixup. We pick the right reloc code depending on the byteorder
7861 currently in effect. */
7862 void
7863 ia64_cons_fix_new (f, where, nbytes, exp)
7864 fragS *f;
7865 int where;
7866 int nbytes;
7867 expressionS *exp;
7868 {
7869 bfd_reloc_code_real_type code;
7870 fixS *fix;
7871
7872 switch (nbytes)
7873 {
7874 /* There are no reloc for 8 and 16 bit quantities, but we allow
7875 them here since they will work fine as long as the expression
7876 is fully defined at the end of the pass over the source file. */
7877 case 1: code = BFD_RELOC_8; break;
7878 case 2: code = BFD_RELOC_16; break;
7879 case 4:
7880 if (target_big_endian)
7881 code = BFD_RELOC_IA64_DIR32MSB;
7882 else
7883 code = BFD_RELOC_IA64_DIR32LSB;
7884 break;
7885
7886 case 8:
7887 if (target_big_endian)
7888 code = BFD_RELOC_IA64_DIR64MSB;
7889 else
7890 code = BFD_RELOC_IA64_DIR64LSB;
7891 break;
7892
7893 default:
7894 as_bad ("Unsupported fixup size %d", nbytes);
7895 ignore_rest_of_line ();
7896 return;
7897 }
7898 if (exp->X_op == O_pseudo_fixup)
7899 {
7900 /* ??? */
7901 exp->X_op = O_symbol;
7902 code = ia64_gen_real_reloc_type (exp->X_op_symbol, code);
7903 }
7904 fix = fix_new_exp (f, where, nbytes, exp, 0, code);
7905 /* We need to store the byte order in effect in case we're going
7906 to fix an 8 or 16 bit relocation (for which there no real
7907 relocs available). See md_apply_fix(). */
7908 fix->tc_fix_data.bigendian = target_big_endian;
7909 }
7910
7911 /* Return the actual relocation we wish to associate with the pseudo
7912 reloc described by SYM and R_TYPE. SYM should be one of the
7913 symbols in the pseudo_func array, or NULL. */
7914
7915 static bfd_reloc_code_real_type
7916 ia64_gen_real_reloc_type (sym, r_type)
7917 struct symbol *sym;
7918 bfd_reloc_code_real_type r_type;
7919 {
7920 bfd_reloc_code_real_type new = 0;
7921
7922 if (sym == NULL)
7923 {
7924 return r_type;
7925 }
7926
7927 switch (S_GET_VALUE (sym))
7928 {
7929 case FUNC_FPTR_RELATIVE:
7930 switch (r_type)
7931 {
7932 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_FPTR64I; break;
7933 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_FPTR32MSB; break;
7934 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_FPTR32LSB; break;
7935 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_FPTR64MSB; break;
7936 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_FPTR64LSB; break;
7937 default: break;
7938 }
7939 break;
7940
7941 case FUNC_GP_RELATIVE:
7942 switch (r_type)
7943 {
7944 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_GPREL22; break;
7945 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_GPREL64I; break;
7946 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_GPREL32MSB; break;
7947 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_GPREL32LSB; break;
7948 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_GPREL64MSB; break;
7949 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_GPREL64LSB; break;
7950 default: break;
7951 }
7952 break;
7953
7954 case FUNC_LT_RELATIVE:
7955 switch (r_type)
7956 {
7957 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_LTOFF22; break;
7958 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_LTOFF64I; break;
7959 default: break;
7960 }
7961 break;
7962
7963 case FUNC_PLT_RELATIVE:
7964 switch (r_type)
7965 {
7966 case BFD_RELOC_IA64_IMM22: new = BFD_RELOC_IA64_PLTOFF22; break;
7967 case BFD_RELOC_IA64_IMM64: new = BFD_RELOC_IA64_PLTOFF64I; break;
7968 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_PLTOFF64MSB;break;
7969 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_PLTOFF64LSB;break;
7970 default: break;
7971 }
7972 break;
7973
7974 case FUNC_SEC_RELATIVE:
7975 switch (r_type)
7976 {
7977 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SECREL32MSB;break;
7978 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SECREL32LSB;break;
7979 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SECREL64MSB;break;
7980 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SECREL64LSB;break;
7981 default: break;
7982 }
7983 break;
7984
7985 case FUNC_SEG_RELATIVE:
7986 switch (r_type)
7987 {
7988 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_SEGREL32MSB;break;
7989 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_SEGREL32LSB;break;
7990 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_SEGREL64MSB;break;
7991 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_SEGREL64LSB;break;
7992 default: break;
7993 }
7994 break;
7995
7996 case FUNC_LTV_RELATIVE:
7997 switch (r_type)
7998 {
7999 case BFD_RELOC_IA64_DIR32MSB: new = BFD_RELOC_IA64_LTV32MSB; break;
8000 case BFD_RELOC_IA64_DIR32LSB: new = BFD_RELOC_IA64_LTV32LSB; break;
8001 case BFD_RELOC_IA64_DIR64MSB: new = BFD_RELOC_IA64_LTV64MSB; break;
8002 case BFD_RELOC_IA64_DIR64LSB: new = BFD_RELOC_IA64_LTV64LSB; break;
8003 default: break;
8004 }
8005 break;
8006
8007 case FUNC_LT_FPTR_RELATIVE:
8008 switch (r_type)
8009 {
8010 case BFD_RELOC_IA64_IMM22:
8011 new = BFD_RELOC_IA64_LTOFF_FPTR22; break;
8012 case BFD_RELOC_IA64_IMM64:
8013 new = BFD_RELOC_IA64_LTOFF_FPTR64I; break;
8014 default:
8015 break;
8016 }
8017 break;
8018 default:
8019 abort ();
8020 }
8021 /* Hmmmm. Should this ever occur? */
8022 if (new)
8023 return new;
8024 else
8025 return r_type;
8026 }
8027
8028 /* Here is where generate the appropriate reloc for pseudo relocation
8029 functions. */
8030 void
8031 ia64_validate_fix (fix)
8032 fixS *fix;
8033 {
8034 switch (fix->fx_r_type)
8035 {
8036 case BFD_RELOC_IA64_FPTR64I:
8037 case BFD_RELOC_IA64_FPTR32MSB:
8038 case BFD_RELOC_IA64_FPTR64LSB:
8039 case BFD_RELOC_IA64_LTOFF_FPTR22:
8040 case BFD_RELOC_IA64_LTOFF_FPTR64I:
8041 if (fix->fx_offset != 0)
8042 as_bad_where (fix->fx_file, fix->fx_line,
8043 "No addend allowed in @fptr() relocation");
8044 break;
8045 default:
8046 break;
8047 }
8048
8049 return;
8050 }
8051
8052 static void
8053 fix_insn (fix, odesc, value)
8054 fixS *fix;
8055 const struct ia64_operand *odesc;
8056 valueT value;
8057 {
8058 bfd_vma insn[3], t0, t1, control_bits;
8059 const char *err;
8060 char *fixpos;
8061 long slot;
8062
8063 slot = fix->fx_where & 0x3;
8064 fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot);
8065
8066 /* bundles are always in little-endian byte order */
8067 t0 = bfd_getl64 (fixpos);
8068 t1 = bfd_getl64 (fixpos + 8);
8069 control_bits = t0 & 0x1f;
8070 insn[0] = (t0 >> 5) & 0x1ffffffffffLL;
8071 insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18);
8072 insn[2] = (t1 >> 23) & 0x1ffffffffffLL;
8073
8074 err = (*odesc->insert) (odesc, value, insn + slot);
8075 if (err)
8076 {
8077 as_bad_where (fix->fx_file, fix->fx_line, err);
8078 return;
8079 }
8080
8081 t0 = control_bits | (insn[0] << 5) | (insn[1] << 46);
8082 t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23);
8083 md_number_to_chars (fixpos + 0, t0, 8);
8084 md_number_to_chars (fixpos + 8, t1, 8);
8085
8086 }
8087
8088 /* Attempt to simplify or even eliminate a fixup. The return value is
8089 ignored; perhaps it was once meaningful, but now it is historical.
8090 To indicate that a fixup has been eliminated, set FIXP->FX_DONE.
8091
8092 If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry
8093 (if possible). */
8094 int
8095 md_apply_fix3 (fix, valuep, seg)
8096 fixS *fix;
8097 valueT *valuep;
8098 segT seg;
8099 {
8100 char *fixpos;
8101 valueT value = *valuep;
8102 int adjust = 0;
8103
8104 fixpos = fix->fx_frag->fr_literal + fix->fx_where;
8105
8106 if (fix->fx_pcrel)
8107 {
8108 switch (fix->fx_r_type)
8109 {
8110 case BFD_RELOC_IA64_DIR32MSB:
8111 fix->fx_r_type = BFD_RELOC_IA64_PCREL32MSB;
8112 adjust = 1;
8113 break;
8114
8115 case BFD_RELOC_IA64_DIR32LSB:
8116 fix->fx_r_type = BFD_RELOC_IA64_PCREL32LSB;
8117 adjust = 1;
8118 break;
8119
8120 case BFD_RELOC_IA64_DIR64MSB:
8121 fix->fx_r_type = BFD_RELOC_IA64_PCREL64MSB;
8122 adjust = 1;
8123 break;
8124
8125 case BFD_RELOC_IA64_DIR64LSB:
8126 fix->fx_r_type = BFD_RELOC_IA64_PCREL64LSB;
8127 adjust = 1;
8128 break;
8129
8130 default:
8131 break;
8132 }
8133 }
8134 if (fix->fx_addsy)
8135 {
8136 switch (fix->fx_r_type)
8137 {
8138 case 0:
8139 as_bad_where (fix->fx_file, fix->fx_line,
8140 "%s must have a constant value",
8141 elf64_ia64_operands[fix->tc_fix_data.opnd].desc);
8142 break;
8143
8144 default:
8145 break;
8146 }
8147
8148 /* ??? This is a hack copied from tc-i386.c to make PCREL relocs
8149 work. There should be a better way to handle this. */
8150 if (adjust)
8151 fix->fx_offset += fix->fx_where + fix->fx_frag->fr_address;
8152 }
8153 else if (fix->tc_fix_data.opnd == IA64_OPND_NIL)
8154 {
8155 if (fix->tc_fix_data.bigendian)
8156 number_to_chars_bigendian (fixpos, value, fix->fx_size);
8157 else
8158 number_to_chars_littleendian (fixpos, value, fix->fx_size);
8159 fix->fx_done = 1;
8160 return 1;
8161 }
8162 else
8163 {
8164 fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value);
8165 fix->fx_done = 1;
8166 return 1;
8167 }
8168 return 1;
8169 }
8170
8171 /* Generate the BFD reloc to be stuck in the object file from the
8172 fixup used internally in the assembler. */
8173 arelent*
8174 tc_gen_reloc (sec, fixp)
8175 asection *sec;
8176 fixS *fixp;
8177 {
8178 arelent *reloc;
8179
8180 reloc = xmalloc (sizeof (*reloc));
8181 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
8182 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
8183 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
8184 reloc->addend = fixp->fx_offset;
8185 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
8186
8187 if (!reloc->howto)
8188 {
8189 as_bad_where (fixp->fx_file, fixp->fx_line,
8190 "Cannot represent %s relocation in object file",
8191 bfd_get_reloc_code_name (fixp->fx_r_type));
8192 }
8193 return reloc;
8194 }
8195
8196 /* Turn a string in input_line_pointer into a floating point constant
8197 of type type, and store the appropriate bytes in *lit. The number
8198 of LITTLENUMS emitted is stored in *size. An error message is
8199 returned, or NULL on OK. */
8200
8201 #define MAX_LITTLENUMS 5
8202
8203 char*
8204 md_atof (type, lit, size)
8205 int type;
8206 char *lit;
8207 int *size;
8208 {
8209 LITTLENUM_TYPE words[MAX_LITTLENUMS];
8210 LITTLENUM_TYPE *word;
8211 char *t;
8212 int prec;
8213
8214 switch (type)
8215 {
8216 /* IEEE floats */
8217 case 'f':
8218 case 'F':
8219 case 's':
8220 case 'S':
8221 prec = 2;
8222 break;
8223
8224 case 'd':
8225 case 'D':
8226 case 'r':
8227 case 'R':
8228 prec = 4;
8229 break;
8230
8231 case 'x':
8232 case 'X':
8233 case 'p':
8234 case 'P':
8235 prec = 5;
8236 break;
8237
8238 default:
8239 *size = 0;
8240 return "Bad call to MD_ATOF()";
8241 }
8242 t = atof_ieee (input_line_pointer, type, words);
8243 if (t)
8244 input_line_pointer = t;
8245 *size = prec * sizeof (LITTLENUM_TYPE);
8246
8247 for (word = words + prec - 1; prec--;)
8248 {
8249 md_number_to_chars (lit, (long) (*word--), sizeof (LITTLENUM_TYPE));
8250 lit += sizeof (LITTLENUM_TYPE);
8251 }
8252 return 0;
8253 }
8254
8255 /* Round up a section's size to the appropriate boundary. */
8256 valueT
8257 md_section_align (seg, size)
8258 segT seg;
8259 valueT size;
8260 {
8261 int align = bfd_get_section_alignment (stdoutput, seg);
8262 valueT mask = ((valueT)1 << align) - 1;
8263
8264 return (size + mask) & ~mask;
8265 }
8266
8267 /* Handle ia64 specific semantics of the align directive. */
8268
8269 int
8270 ia64_md_do_align (n, fill, len, max)
8271 int n;
8272 const char *fill;
8273 int len;
8274 int max;
8275 {
8276 /* Fill any pending bundle with nops. */
8277 if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE)
8278 ia64_flush_insns ();
8279
8280 /* When we align code in a text section, emit a bundle of 3 nops instead of
8281 zero bytes. We can only do this if a multiple of 16 bytes was requested.
8282 N is log base 2 of the requested alignment. */
8283 if (fill == NULL
8284 && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE
8285 && n > 4)
8286 {
8287 /* Use mfi bundle of nops with no stop bits. */
8288 static const unsigned char be_nop[]
8289 = { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
8290 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0c};
8291 static const unsigned char le_nop[]
8292 = { 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
8293 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00};
8294
8295 /* Make sure we are on a 16-byte boundary, in case someone has been
8296 putting data into a text section. */
8297 frag_align (4, 0, 0);
8298
8299 if (target_big_endian)
8300 frag_align_pattern (n, be_nop, 16, max);
8301 else
8302 frag_align_pattern (n, le_nop, 16, max);
8303 return 1;
8304 }
8305
8306 return 0;
8307 }
This page took 0.467978 seconds and 5 git commands to generate.