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