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