]>
Commit | Line | Data |
---|---|---|
800eeca4 | 1 | /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture. |
6f2750fe | 2 | Copyright (C) 1998-2016 Free Software Foundation, Inc. |
800eeca4 JW |
3 | Contributed by David Mosberger-Tang <davidm@hpl.hp.com> |
4 | ||
5 | This file is part of GAS, the GNU Assembler. | |
6 | ||
7 | GAS is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
ec2655a6 | 9 | the Free Software Foundation; either version 3, or (at your option) |
800eeca4 JW |
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 | |
4b4da160 NC |
19 | the Free Software Foundation, 51 Franklin Street - Fifth Floor, |
20 | Boston, MA 02110-1301, USA. */ | |
800eeca4 JW |
21 | |
22 | /* | |
23 | TODO: | |
24 | ||
25 | - optional operands | |
26 | - directives: | |
800eeca4 JW |
27 | .eb |
28 | .estate | |
29 | .lb | |
30 | .popsection | |
31 | .previous | |
32 | .psr | |
33 | .pushsection | |
800eeca4 JW |
34 | - labels are wrong if automatic alignment is introduced |
35 | (e.g., checkout the second real10 definition in test-data.s) | |
36 | - DV-related stuff: | |
542d6675 KH |
37 | <reg>.safe_across_calls and any other DV-related directives I don't |
38 | have documentation for. | |
39 | verify mod-sched-brs reads/writes are checked/marked (and other | |
40 | notes) | |
800eeca4 JW |
41 | |
42 | */ | |
43 | ||
44 | #include "as.h" | |
3882b010 | 45 | #include "safe-ctype.h" |
800eeca4 JW |
46 | #include "dwarf2dbg.h" |
47 | #include "subsegs.h" | |
48 | ||
49 | #include "opcode/ia64.h" | |
50 | ||
51 | #include "elf/ia64.h" | |
01e1a5bc NC |
52 | #include "bfdver.h" |
53 | #include <time.h> | |
800eeca4 | 54 | |
a66d2bb7 JB |
55 | #ifdef HAVE_LIMITS_H |
56 | #include <limits.h> | |
57 | #endif | |
58 | ||
800eeca4 | 59 | #define NELEMS(a) ((int) (sizeof (a)/sizeof ((a)[0]))) |
5faa8e39 JW |
60 | |
61 | /* Some systems define MIN in, e.g., param.h. */ | |
62 | #undef MIN | |
800eeca4 JW |
63 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
64 | ||
65 | #define NUM_SLOTS 4 | |
66 | #define PREV_SLOT md.slot[(md.curr_slot + NUM_SLOTS - 1) % NUM_SLOTS] | |
67 | #define CURR_SLOT md.slot[md.curr_slot] | |
68 | ||
69 | #define O_pseudo_fixup (O_max + 1) | |
70 | ||
71 | enum special_section | |
72 | { | |
557debba | 73 | /* IA-64 ABI section pseudo-ops. */ |
800eeca4 JW |
74 | SPECIAL_SECTION_BSS = 0, |
75 | SPECIAL_SECTION_SBSS, | |
76 | SPECIAL_SECTION_SDATA, | |
77 | SPECIAL_SECTION_RODATA, | |
78 | SPECIAL_SECTION_COMMENT, | |
79 | SPECIAL_SECTION_UNWIND, | |
557debba JW |
80 | SPECIAL_SECTION_UNWIND_INFO, |
81 | /* HPUX specific section pseudo-ops. */ | |
82 | SPECIAL_SECTION_INIT_ARRAY, | |
83 | SPECIAL_SECTION_FINI_ARRAY, | |
800eeca4 JW |
84 | }; |
85 | ||
86 | enum reloc_func | |
87 | { | |
13ae64f3 JJ |
88 | FUNC_DTP_MODULE, |
89 | FUNC_DTP_RELATIVE, | |
800eeca4 JW |
90 | FUNC_FPTR_RELATIVE, |
91 | FUNC_GP_RELATIVE, | |
92 | FUNC_LT_RELATIVE, | |
fa2c7eff | 93 | FUNC_LT_RELATIVE_X, |
c67e42c9 | 94 | FUNC_PC_RELATIVE, |
800eeca4 JW |
95 | FUNC_PLT_RELATIVE, |
96 | FUNC_SEC_RELATIVE, | |
97 | FUNC_SEG_RELATIVE, | |
13ae64f3 | 98 | FUNC_TP_RELATIVE, |
800eeca4 JW |
99 | FUNC_LTV_RELATIVE, |
100 | FUNC_LT_FPTR_RELATIVE, | |
13ae64f3 JJ |
101 | FUNC_LT_DTP_MODULE, |
102 | FUNC_LT_DTP_RELATIVE, | |
103 | FUNC_LT_TP_RELATIVE, | |
3969b680 | 104 | FUNC_IPLT_RELOC, |
9d0e8497 TG |
105 | #ifdef TE_VMS |
106 | FUNC_SLOTCOUNT_RELOC, | |
107 | #endif | |
800eeca4 JW |
108 | }; |
109 | ||
110 | enum reg_symbol | |
111 | { | |
112 | REG_GR = 0, | |
113 | REG_FR = (REG_GR + 128), | |
114 | REG_AR = (REG_FR + 128), | |
115 | REG_CR = (REG_AR + 128), | |
b3e14eda L |
116 | REG_DAHR = (REG_CR + 128), |
117 | REG_P = (REG_DAHR + 8), | |
800eeca4 JW |
118 | REG_BR = (REG_P + 64), |
119 | REG_IP = (REG_BR + 8), | |
120 | REG_CFM, | |
121 | REG_PR, | |
122 | REG_PR_ROT, | |
123 | REG_PSR, | |
124 | REG_PSR_L, | |
125 | REG_PSR_UM, | |
126 | /* The following are pseudo-registers for use by gas only. */ | |
127 | IND_CPUID, | |
128 | IND_DBR, | |
129 | IND_DTR, | |
130 | IND_ITR, | |
131 | IND_IBR, | |
800eeca4 JW |
132 | IND_MSR, |
133 | IND_PKR, | |
134 | IND_PMC, | |
135 | IND_PMD, | |
b3e14eda | 136 | IND_DAHR, |
800eeca4 | 137 | IND_RR, |
542d6675 | 138 | /* The following pseudo-registers are used for unwind directives only: */ |
e0c9811a JW |
139 | REG_PSP, |
140 | REG_PRIUNAT, | |
800eeca4 JW |
141 | REG_NUM |
142 | }; | |
143 | ||
144 | enum dynreg_type | |
145 | { | |
146 | DYNREG_GR = 0, /* dynamic general purpose register */ | |
147 | DYNREG_FR, /* dynamic floating point register */ | |
148 | DYNREG_PR, /* dynamic predicate register */ | |
149 | DYNREG_NUM_TYPES | |
150 | }; | |
151 | ||
87f8eb97 JW |
152 | enum operand_match_result |
153 | { | |
154 | OPERAND_MATCH, | |
155 | OPERAND_OUT_OF_RANGE, | |
156 | OPERAND_MISMATCH | |
157 | }; | |
158 | ||
800eeca4 JW |
159 | /* On the ia64, we can't know the address of a text label until the |
160 | instructions are packed into a bundle. To handle this, we keep | |
161 | track of the list of labels that appear in front of each | |
162 | instruction. */ | |
163 | struct label_fix | |
542d6675 KH |
164 | { |
165 | struct label_fix *next; | |
166 | struct symbol *sym; | |
07a53e5c | 167 | bfd_boolean dw2_mark_labels; |
542d6675 | 168 | }; |
800eeca4 | 169 | |
9d0e8497 TG |
170 | #ifdef TE_VMS |
171 | /* An internally used relocation. */ | |
172 | #define DUMMY_RELOC_IA64_SLOTCOUNT (BFD_RELOC_UNUSED + 1) | |
173 | #endif | |
174 | ||
549f748d | 175 | /* This is the endianness of the current section. */ |
800eeca4 JW |
176 | extern int target_big_endian; |
177 | ||
549f748d JW |
178 | /* This is the default endianness. */ |
179 | static int default_big_endian = TARGET_BYTES_BIG_ENDIAN; | |
180 | ||
5a49b8ac | 181 | void (*ia64_number_to_chars) (char *, valueT, int); |
10a98291 | 182 | |
5a49b8ac AM |
183 | static void ia64_float_to_chars_bigendian (char *, LITTLENUM_TYPE *, int); |
184 | static void ia64_float_to_chars_littleendian (char *, LITTLENUM_TYPE *, int); | |
185 | ||
186 | static void (*ia64_float_to_chars) (char *, LITTLENUM_TYPE *, int); | |
10a98291 | 187 | |
35f5df7f L |
188 | static struct hash_control *alias_hash; |
189 | static struct hash_control *alias_name_hash; | |
190 | static struct hash_control *secalias_hash; | |
191 | static struct hash_control *secalias_name_hash; | |
192 | ||
2fac3d48 JB |
193 | /* List of chars besides those in app.c:symbol_chars that can start an |
194 | operand. Used to prevent the scrubber eating vital white-space. */ | |
195 | const char ia64_symbol_chars[] = "@?"; | |
196 | ||
800eeca4 JW |
197 | /* Characters which always start a comment. */ |
198 | const char comment_chars[] = ""; | |
199 | ||
200 | /* Characters which start a comment at the beginning of a line. */ | |
201 | const char line_comment_chars[] = "#"; | |
202 | ||
203 | /* Characters which may be used to separate multiple commands on a | |
204 | single line. */ | |
e4e8248d | 205 | const char line_separator_chars[] = ";{}"; |
800eeca4 JW |
206 | |
207 | /* Characters which are used to indicate an exponent in a floating | |
208 | point number. */ | |
209 | const char EXP_CHARS[] = "eE"; | |
210 | ||
211 | /* Characters which mean that a number is a floating point constant, | |
212 | as in 0d1.0. */ | |
213 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; | |
214 | ||
542d6675 | 215 | /* ia64-specific option processing: */ |
800eeca4 | 216 | |
44f5c83a | 217 | const char *md_shortopts = "m:N:x::"; |
800eeca4 JW |
218 | |
219 | struct option md_longopts[] = | |
220 | { | |
c43c2cc5 JW |
221 | #define OPTION_MCONSTANT_GP (OPTION_MD_BASE + 1) |
222 | {"mconstant-gp", no_argument, NULL, OPTION_MCONSTANT_GP}, | |
223 | #define OPTION_MAUTO_PIC (OPTION_MD_BASE + 2) | |
224 | {"mauto-pic", no_argument, NULL, OPTION_MAUTO_PIC} | |
800eeca4 JW |
225 | }; |
226 | ||
227 | size_t md_longopts_size = sizeof (md_longopts); | |
228 | ||
229 | static struct | |
230 | { | |
231 | struct hash_control *pseudo_hash; /* pseudo opcode hash table */ | |
232 | struct hash_control *reg_hash; /* register name hash table */ | |
233 | struct hash_control *dynreg_hash; /* dynamic register hash table */ | |
234 | struct hash_control *const_hash; /* constant hash table */ | |
235 | struct hash_control *entry_hash; /* code entry hint hash table */ | |
236 | ||
800eeca4 JW |
237 | /* If X_op is != O_absent, the registername for the instruction's |
238 | qualifying predicate. If NULL, p0 is assumed for instructions | |
ad4b42b4 | 239 | that are predictable. */ |
800eeca4 JW |
240 | expressionS qp; |
241 | ||
8c2fda1d L |
242 | /* Optimize for which CPU. */ |
243 | enum | |
244 | { | |
245 | itanium1, | |
246 | itanium2 | |
247 | } tune; | |
248 | ||
91d777ee L |
249 | /* What to do when hint.b is used. */ |
250 | enum | |
251 | { | |
252 | hint_b_error, | |
253 | hint_b_warning, | |
254 | hint_b_ok | |
255 | } hint_b; | |
256 | ||
800eeca4 | 257 | unsigned int |
197865e8 | 258 | manual_bundling : 1, |
800eeca4 JW |
259 | debug_dv: 1, |
260 | detect_dv: 1, | |
261 | explicit_mode : 1, /* which mode we're in */ | |
262 | default_explicit_mode : 1, /* which mode is the default */ | |
263 | mode_explicitly_set : 1, /* was the current mode explicitly set? */ | |
4d5a53ff JW |
264 | auto_align : 1, |
265 | keep_pending_output : 1; | |
800eeca4 | 266 | |
970d6792 L |
267 | /* What to do when something is wrong with unwind directives. */ |
268 | enum | |
269 | { | |
270 | unwind_check_warning, | |
271 | unwind_check_error | |
272 | } unwind_check; | |
273 | ||
800eeca4 JW |
274 | /* Each bundle consists of up to three instructions. We keep |
275 | track of four most recent instructions so we can correctly set | |
197865e8 | 276 | the end_of_insn_group for the last instruction in a bundle. */ |
800eeca4 JW |
277 | int curr_slot; |
278 | int num_slots_in_use; | |
279 | struct slot | |
280 | { | |
281 | unsigned int | |
282 | end_of_insn_group : 1, | |
283 | manual_bundling_on : 1, | |
196e8040 JW |
284 | manual_bundling_off : 1, |
285 | loc_directive_seen : 1; | |
800eeca4 JW |
286 | signed char user_template; /* user-selected template, if any */ |
287 | unsigned char qp_regno; /* qualifying predicate */ | |
288 | /* This duplicates a good fraction of "struct fix" but we | |
289 | can't use a "struct fix" instead since we can't call | |
290 | fix_new_exp() until we know the address of the instruction. */ | |
291 | int num_fixups; | |
292 | struct insn_fix | |
293 | { | |
294 | bfd_reloc_code_real_type code; | |
295 | enum ia64_opnd opnd; /* type of operand in need of fix */ | |
296 | unsigned int is_pcrel : 1; /* is operand pc-relative? */ | |
297 | expressionS expr; /* the value to be inserted */ | |
298 | } | |
299 | fixup[2]; /* at most two fixups per insn */ | |
300 | struct ia64_opcode *idesc; | |
301 | struct label_fix *label_fixups; | |
f1bcba5b | 302 | struct label_fix *tag_fixups; |
800eeca4 JW |
303 | struct unw_rec_list *unwind_record; /* Unwind directive. */ |
304 | expressionS opnd[6]; | |
3b4dbbbf | 305 | const char *src_file; |
800eeca4 JW |
306 | unsigned int src_line; |
307 | struct dwarf2_line_info debug_line; | |
308 | } | |
309 | slot[NUM_SLOTS]; | |
310 | ||
311 | segT last_text_seg; | |
312 | ||
313 | struct dynreg | |
314 | { | |
315 | struct dynreg *next; /* next dynamic register */ | |
316 | const char *name; | |
317 | unsigned short base; /* the base register number */ | |
318 | unsigned short num_regs; /* # of registers in this set */ | |
319 | } | |
320 | *dynreg[DYNREG_NUM_TYPES], in, loc, out, rot; | |
321 | ||
322 | flagword flags; /* ELF-header flags */ | |
323 | ||
324 | struct mem_offset { | |
325 | unsigned hint:1; /* is this hint currently valid? */ | |
326 | bfd_vma offset; /* mem.offset offset */ | |
327 | bfd_vma base; /* mem.offset base */ | |
328 | } mem_offset; | |
329 | ||
330 | int path; /* number of alt. entry points seen */ | |
331 | const char **entry_labels; /* labels of all alternate paths in | |
542d6675 | 332 | the current DV-checking block. */ |
800eeca4 | 333 | int maxpaths; /* size currently allocated for |
542d6675 | 334 | entry_labels */ |
557debba JW |
335 | |
336 | int pointer_size; /* size in bytes of a pointer */ | |
337 | int pointer_size_shift; /* shift size of a pointer for alignment */ | |
8b84be9d JB |
338 | |
339 | symbolS *indregsym[IND_RR - IND_CPUID + 1]; | |
800eeca4 JW |
340 | } |
341 | md; | |
342 | ||
f6fe78d6 JW |
343 | /* These are not const, because they are modified to MMI for non-itanium1 |
344 | targets below. */ | |
345 | /* MFI bundle of nops. */ | |
346 | static unsigned char le_nop[16] = | |
347 | { | |
348 | 0x0c, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, | |
349 | 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00 | |
350 | }; | |
351 | /* MFI bundle of nops with stop-bit. */ | |
352 | static unsigned char le_nop_stop[16] = | |
353 | { | |
354 | 0x0d, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, | |
355 | 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00 | |
356 | }; | |
357 | ||
542d6675 | 358 | /* application registers: */ |
800eeca4 | 359 | |
e0c9811a JW |
360 | #define AR_K0 0 |
361 | #define AR_K7 7 | |
362 | #define AR_RSC 16 | |
363 | #define AR_BSP 17 | |
364 | #define AR_BSPSTORE 18 | |
365 | #define AR_RNAT 19 | |
d8ca90b5 JB |
366 | #define AR_FCR 21 |
367 | #define AR_EFLAG 24 | |
368 | #define AR_CSD 25 | |
369 | #define AR_SSD 26 | |
370 | #define AR_CFLG 27 | |
371 | #define AR_FSR 28 | |
372 | #define AR_FIR 29 | |
373 | #define AR_FDR 30 | |
374 | #define AR_CCV 32 | |
e0c9811a JW |
375 | #define AR_UNAT 36 |
376 | #define AR_FPSR 40 | |
377 | #define AR_ITC 44 | |
4f8631b1 | 378 | #define AR_RUC 45 |
e0c9811a JW |
379 | #define AR_PFS 64 |
380 | #define AR_LC 65 | |
d8ca90b5 | 381 | #define AR_EC 66 |
800eeca4 JW |
382 | |
383 | static const struct | |
384 | { | |
385 | const char *name; | |
8b84be9d | 386 | unsigned int regnum; |
800eeca4 JW |
387 | } |
388 | ar[] = | |
389 | { | |
d8ca90b5 JB |
390 | {"ar.k0", AR_K0}, {"ar.k1", AR_K0 + 1}, |
391 | {"ar.k2", AR_K0 + 2}, {"ar.k3", AR_K0 + 3}, | |
392 | {"ar.k4", AR_K0 + 4}, {"ar.k5", AR_K0 + 5}, | |
393 | {"ar.k6", AR_K0 + 6}, {"ar.k7", AR_K7}, | |
394 | {"ar.rsc", AR_RSC}, {"ar.bsp", AR_BSP}, | |
395 | {"ar.bspstore", AR_BSPSTORE}, {"ar.rnat", AR_RNAT}, | |
396 | {"ar.fcr", AR_FCR}, {"ar.eflag", AR_EFLAG}, | |
397 | {"ar.csd", AR_CSD}, {"ar.ssd", AR_SSD}, | |
398 | {"ar.cflg", AR_CFLG}, {"ar.fsr", AR_FSR}, | |
399 | {"ar.fir", AR_FIR}, {"ar.fdr", AR_FDR}, | |
400 | {"ar.ccv", AR_CCV}, {"ar.unat", AR_UNAT}, | |
401 | {"ar.fpsr", AR_FPSR}, {"ar.itc", AR_ITC}, | |
4f8631b1 L |
402 | {"ar.ruc", AR_RUC}, {"ar.pfs", AR_PFS}, |
403 | {"ar.lc", AR_LC}, {"ar.ec", AR_EC}, | |
800eeca4 JW |
404 | }; |
405 | ||
d8ca90b5 JB |
406 | /* control registers: */ |
407 | ||
408 | #define CR_DCR 0 | |
409 | #define CR_ITM 1 | |
410 | #define CR_IVA 2 | |
411 | #define CR_PTA 8 | |
412 | #define CR_GPTA 9 | |
800eeca4 JW |
413 | #define CR_IPSR 16 |
414 | #define CR_ISR 17 | |
415 | #define CR_IIP 19 | |
416 | #define CR_IFA 20 | |
417 | #define CR_ITIR 21 | |
418 | #define CR_IIPA 22 | |
419 | #define CR_IFS 23 | |
420 | #define CR_IIM 24 | |
421 | #define CR_IHA 25 | |
1ca35711 L |
422 | #define CR_IIB0 26 |
423 | #define CR_IIB1 27 | |
d8ca90b5 | 424 | #define CR_LID 64 |
800eeca4 JW |
425 | #define CR_IVR 65 |
426 | #define CR_TPR 66 | |
427 | #define CR_EOI 67 | |
428 | #define CR_IRR0 68 | |
429 | #define CR_IRR3 71 | |
d8ca90b5 JB |
430 | #define CR_ITV 72 |
431 | #define CR_PMV 73 | |
432 | #define CR_CMCV 74 | |
800eeca4 JW |
433 | #define CR_LRR0 80 |
434 | #define CR_LRR1 81 | |
435 | ||
800eeca4 JW |
436 | static const struct |
437 | { | |
438 | const char *name; | |
8b84be9d | 439 | unsigned int regnum; |
800eeca4 JW |
440 | } |
441 | cr[] = | |
442 | { | |
d8ca90b5 JB |
443 | {"cr.dcr", CR_DCR}, |
444 | {"cr.itm", CR_ITM}, | |
445 | {"cr.iva", CR_IVA}, | |
446 | {"cr.pta", CR_PTA}, | |
447 | {"cr.gpta", CR_GPTA}, | |
448 | {"cr.ipsr", CR_IPSR}, | |
449 | {"cr.isr", CR_ISR}, | |
450 | {"cr.iip", CR_IIP}, | |
451 | {"cr.ifa", CR_IFA}, | |
452 | {"cr.itir", CR_ITIR}, | |
453 | {"cr.iipa", CR_IIPA}, | |
454 | {"cr.ifs", CR_IFS}, | |
455 | {"cr.iim", CR_IIM}, | |
456 | {"cr.iha", CR_IHA}, | |
1ca35711 L |
457 | {"cr.iib0", CR_IIB0}, |
458 | {"cr.iib1", CR_IIB1}, | |
d8ca90b5 JB |
459 | {"cr.lid", CR_LID}, |
460 | {"cr.ivr", CR_IVR}, | |
461 | {"cr.tpr", CR_TPR}, | |
462 | {"cr.eoi", CR_EOI}, | |
463 | {"cr.irr0", CR_IRR0}, | |
464 | {"cr.irr1", CR_IRR0 + 1}, | |
465 | {"cr.irr2", CR_IRR0 + 2}, | |
466 | {"cr.irr3", CR_IRR3}, | |
467 | {"cr.itv", CR_ITV}, | |
468 | {"cr.pmv", CR_PMV}, | |
469 | {"cr.cmcv", CR_CMCV}, | |
470 | {"cr.lrr0", CR_LRR0}, | |
471 | {"cr.lrr1", CR_LRR1} | |
800eeca4 JW |
472 | }; |
473 | ||
474 | #define PSR_MFL 4 | |
475 | #define PSR_IC 13 | |
476 | #define PSR_DFL 18 | |
477 | #define PSR_CPL 32 | |
478 | ||
479 | static const struct const_desc | |
480 | { | |
481 | const char *name; | |
482 | valueT value; | |
483 | } | |
484 | const_bits[] = | |
485 | { | |
542d6675 | 486 | /* PSR constant masks: */ |
800eeca4 JW |
487 | |
488 | /* 0: reserved */ | |
489 | {"psr.be", ((valueT) 1) << 1}, | |
490 | {"psr.up", ((valueT) 1) << 2}, | |
491 | {"psr.ac", ((valueT) 1) << 3}, | |
492 | {"psr.mfl", ((valueT) 1) << 4}, | |
493 | {"psr.mfh", ((valueT) 1) << 5}, | |
494 | /* 6-12: reserved */ | |
495 | {"psr.ic", ((valueT) 1) << 13}, | |
496 | {"psr.i", ((valueT) 1) << 14}, | |
497 | {"psr.pk", ((valueT) 1) << 15}, | |
498 | /* 16: reserved */ | |
499 | {"psr.dt", ((valueT) 1) << 17}, | |
500 | {"psr.dfl", ((valueT) 1) << 18}, | |
501 | {"psr.dfh", ((valueT) 1) << 19}, | |
502 | {"psr.sp", ((valueT) 1) << 20}, | |
503 | {"psr.pp", ((valueT) 1) << 21}, | |
504 | {"psr.di", ((valueT) 1) << 22}, | |
505 | {"psr.si", ((valueT) 1) << 23}, | |
506 | {"psr.db", ((valueT) 1) << 24}, | |
507 | {"psr.lp", ((valueT) 1) << 25}, | |
508 | {"psr.tb", ((valueT) 1) << 26}, | |
509 | {"psr.rt", ((valueT) 1) << 27}, | |
510 | /* 28-31: reserved */ | |
511 | /* 32-33: cpl (current privilege level) */ | |
512 | {"psr.is", ((valueT) 1) << 34}, | |
513 | {"psr.mc", ((valueT) 1) << 35}, | |
514 | {"psr.it", ((valueT) 1) << 36}, | |
515 | {"psr.id", ((valueT) 1) << 37}, | |
516 | {"psr.da", ((valueT) 1) << 38}, | |
517 | {"psr.dd", ((valueT) 1) << 39}, | |
518 | {"psr.ss", ((valueT) 1) << 40}, | |
519 | /* 41-42: ri (restart instruction) */ | |
520 | {"psr.ed", ((valueT) 1) << 43}, | |
521 | {"psr.bn", ((valueT) 1) << 44}, | |
522 | }; | |
523 | ||
542d6675 | 524 | /* indirect register-sets/memory: */ |
800eeca4 JW |
525 | |
526 | static const struct | |
527 | { | |
528 | const char *name; | |
8b84be9d | 529 | unsigned int regnum; |
800eeca4 JW |
530 | } |
531 | indirect_reg[] = | |
532 | { | |
533 | { "CPUID", IND_CPUID }, | |
534 | { "cpuid", IND_CPUID }, | |
535 | { "dbr", IND_DBR }, | |
536 | { "dtr", IND_DTR }, | |
537 | { "itr", IND_ITR }, | |
538 | { "ibr", IND_IBR }, | |
539 | { "msr", IND_MSR }, | |
540 | { "pkr", IND_PKR }, | |
541 | { "pmc", IND_PMC }, | |
542 | { "pmd", IND_PMD }, | |
b3e14eda | 543 | { "dahr", IND_DAHR }, |
800eeca4 JW |
544 | { "rr", IND_RR }, |
545 | }; | |
546 | ||
547 | /* Pseudo functions used to indicate relocation types (these functions | |
548 | start with an at sign (@). */ | |
549 | static struct | |
550 | { | |
551 | const char *name; | |
552 | enum pseudo_type | |
553 | { | |
554 | PSEUDO_FUNC_NONE, | |
555 | PSEUDO_FUNC_RELOC, | |
556 | PSEUDO_FUNC_CONST, | |
e0c9811a | 557 | PSEUDO_FUNC_REG, |
800eeca4 JW |
558 | PSEUDO_FUNC_FLOAT |
559 | } | |
560 | type; | |
561 | union | |
562 | { | |
563 | unsigned long ival; | |
564 | symbolS *sym; | |
565 | } | |
566 | u; | |
567 | } | |
568 | pseudo_func[] = | |
569 | { | |
542d6675 | 570 | /* reloc pseudo functions (these must come first!): */ |
13ae64f3 JJ |
571 | { "dtpmod", PSEUDO_FUNC_RELOC, { 0 } }, |
572 | { "dtprel", PSEUDO_FUNC_RELOC, { 0 } }, | |
2434f565 JW |
573 | { "fptr", PSEUDO_FUNC_RELOC, { 0 } }, |
574 | { "gprel", PSEUDO_FUNC_RELOC, { 0 } }, | |
575 | { "ltoff", PSEUDO_FUNC_RELOC, { 0 } }, | |
fa2c7eff | 576 | { "ltoffx", PSEUDO_FUNC_RELOC, { 0 } }, |
2434f565 JW |
577 | { "pcrel", PSEUDO_FUNC_RELOC, { 0 } }, |
578 | { "pltoff", PSEUDO_FUNC_RELOC, { 0 } }, | |
579 | { "secrel", PSEUDO_FUNC_RELOC, { 0 } }, | |
580 | { "segrel", PSEUDO_FUNC_RELOC, { 0 } }, | |
13ae64f3 | 581 | { "tprel", PSEUDO_FUNC_RELOC, { 0 } }, |
2434f565 | 582 | { "ltv", PSEUDO_FUNC_RELOC, { 0 } }, |
16a48f83 JB |
583 | { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_FPTR_RELATIVE */ |
584 | { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_DTP_MODULE */ | |
585 | { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_DTP_RELATIVE */ | |
586 | { NULL, 0, { 0 } }, /* placeholder for FUNC_LT_TP_RELATIVE */ | |
3969b680 | 587 | { "iplt", PSEUDO_FUNC_RELOC, { 0 } }, |
9d0e8497 TG |
588 | #ifdef TE_VMS |
589 | { "slotcount", PSEUDO_FUNC_RELOC, { 0 } }, | |
590 | #endif | |
800eeca4 | 591 | |
542d6675 | 592 | /* mbtype4 constants: */ |
800eeca4 JW |
593 | { "alt", PSEUDO_FUNC_CONST, { 0xa } }, |
594 | { "brcst", PSEUDO_FUNC_CONST, { 0x0 } }, | |
595 | { "mix", PSEUDO_FUNC_CONST, { 0x8 } }, | |
596 | { "rev", PSEUDO_FUNC_CONST, { 0xb } }, | |
597 | { "shuf", PSEUDO_FUNC_CONST, { 0x9 } }, | |
598 | ||
542d6675 | 599 | /* fclass constants: */ |
bf3ca999 | 600 | { "nat", PSEUDO_FUNC_CONST, { 0x100 } }, |
800eeca4 JW |
601 | { "qnan", PSEUDO_FUNC_CONST, { 0x080 } }, |
602 | { "snan", PSEUDO_FUNC_CONST, { 0x040 } }, | |
603 | { "pos", PSEUDO_FUNC_CONST, { 0x001 } }, | |
604 | { "neg", PSEUDO_FUNC_CONST, { 0x002 } }, | |
605 | { "zero", PSEUDO_FUNC_CONST, { 0x004 } }, | |
606 | { "unorm", PSEUDO_FUNC_CONST, { 0x008 } }, | |
607 | { "norm", PSEUDO_FUNC_CONST, { 0x010 } }, | |
608 | { "inf", PSEUDO_FUNC_CONST, { 0x020 } }, | |
bf3ca999 TW |
609 | |
610 | { "natval", PSEUDO_FUNC_CONST, { 0x100 } }, /* old usage */ | |
e0c9811a | 611 | |
c10d9d8f JW |
612 | /* hint constants: */ |
613 | { "pause", PSEUDO_FUNC_CONST, { 0x0 } }, | |
b3e14eda L |
614 | { "priority", PSEUDO_FUNC_CONST, { 0x1 } }, |
615 | ||
616 | /* tf constants: */ | |
617 | { "clz", PSEUDO_FUNC_CONST, { 32 } }, | |
618 | { "mpy", PSEUDO_FUNC_CONST, { 33 } }, | |
619 | { "datahints", PSEUDO_FUNC_CONST, { 34 } }, | |
c10d9d8f | 620 | |
542d6675 | 621 | /* unwind-related constants: */ |
041340ad JW |
622 | { "svr4", PSEUDO_FUNC_CONST, { ELFOSABI_NONE } }, |
623 | { "hpux", PSEUDO_FUNC_CONST, { ELFOSABI_HPUX } }, | |
624 | { "nt", PSEUDO_FUNC_CONST, { 2 } }, /* conflicts w/ELFOSABI_NETBSD */ | |
9c55345c | 625 | { "linux", PSEUDO_FUNC_CONST, { ELFOSABI_GNU } }, |
041340ad JW |
626 | { "freebsd", PSEUDO_FUNC_CONST, { ELFOSABI_FREEBSD } }, |
627 | { "openvms", PSEUDO_FUNC_CONST, { ELFOSABI_OPENVMS } }, | |
628 | { "nsk", PSEUDO_FUNC_CONST, { ELFOSABI_NSK } }, | |
e0c9811a | 629 | |
542d6675 | 630 | /* unwind-related registers: */ |
e0c9811a | 631 | { "priunat",PSEUDO_FUNC_REG, { REG_PRIUNAT } } |
800eeca4 JW |
632 | }; |
633 | ||
542d6675 | 634 | /* 41-bit nop opcodes (one per unit): */ |
800eeca4 JW |
635 | static const bfd_vma nop[IA64_NUM_UNITS] = |
636 | { | |
637 | 0x0000000000LL, /* NIL => break 0 */ | |
638 | 0x0008000000LL, /* I-unit nop */ | |
639 | 0x0008000000LL, /* M-unit nop */ | |
640 | 0x4000000000LL, /* B-unit nop */ | |
641 | 0x0008000000LL, /* F-unit nop */ | |
5d5e6db9 | 642 | 0x0000000000LL, /* L-"unit" nop immediate */ |
800eeca4 JW |
643 | 0x0008000000LL, /* X-unit nop */ |
644 | }; | |
645 | ||
646 | /* Can't be `const' as it's passed to input routines (which have the | |
647 | habit of setting temporary sentinels. */ | |
648 | static char special_section_name[][20] = | |
649 | { | |
650 | {".bss"}, {".sbss"}, {".sdata"}, {".rodata"}, {".comment"}, | |
557debba JW |
651 | {".IA_64.unwind"}, {".IA_64.unwind_info"}, |
652 | {".init_array"}, {".fini_array"} | |
800eeca4 JW |
653 | }; |
654 | ||
655 | /* The best template for a particular sequence of up to three | |
656 | instructions: */ | |
657 | #define N IA64_NUM_TYPES | |
658 | static unsigned char best_template[N][N][N]; | |
659 | #undef N | |
660 | ||
661 | /* Resource dependencies currently in effect */ | |
662 | static struct rsrc { | |
663 | int depind; /* dependency index */ | |
664 | const struct ia64_dependency *dependency; /* actual dependency */ | |
665 | unsigned specific:1, /* is this a specific bit/regno? */ | |
666 | link_to_qp_branch:1; /* will a branch on the same QP clear it?*/ | |
667 | int index; /* specific regno/bit within dependency */ | |
668 | int note; /* optional qualifying note (0 if none) */ | |
669 | #define STATE_NONE 0 | |
670 | #define STATE_STOP 1 | |
671 | #define STATE_SRLZ 2 | |
672 | int insn_srlz; /* current insn serialization state */ | |
673 | int data_srlz; /* current data serialization state */ | |
674 | int qp_regno; /* qualifying predicate for this usage */ | |
3b4dbbbf | 675 | const char *file; /* what file marked this dependency */ |
2434f565 | 676 | unsigned int line; /* what line marked this dependency */ |
800eeca4 | 677 | struct mem_offset mem_offset; /* optional memory offset hint */ |
7484b8e6 | 678 | enum { CMP_NONE, CMP_OR, CMP_AND } cmp_type; /* OR or AND compare? */ |
800eeca4 JW |
679 | int path; /* corresponding code entry index */ |
680 | } *regdeps = NULL; | |
681 | static int regdepslen = 0; | |
682 | static int regdepstotlen = 0; | |
683 | static const char *dv_mode[] = { "RAW", "WAW", "WAR" }; | |
684 | static const char *dv_sem[] = { "none", "implied", "impliedf", | |
139368c9 | 685 | "data", "instr", "specific", "stop", "other" }; |
7484b8e6 | 686 | static const char *dv_cmp_type[] = { "none", "OR", "AND" }; |
800eeca4 JW |
687 | |
688 | /* Current state of PR mutexation */ | |
689 | static struct qpmutex { | |
690 | valueT prmask; | |
691 | int path; | |
692 | } *qp_mutexes = NULL; /* QP mutex bitmasks */ | |
693 | static int qp_mutexeslen = 0; | |
694 | static int qp_mutexestotlen = 0; | |
197865e8 | 695 | static valueT qp_safe_across_calls = 0; |
800eeca4 JW |
696 | |
697 | /* Current state of PR implications */ | |
698 | static struct qp_imply { | |
699 | unsigned p1:6; | |
700 | unsigned p2:6; | |
701 | unsigned p2_branched:1; | |
702 | int path; | |
703 | } *qp_implies = NULL; | |
704 | static int qp_implieslen = 0; | |
705 | static int qp_impliestotlen = 0; | |
706 | ||
197865e8 KH |
707 | /* Keep track of static GR values so that indirect register usage can |
708 | sometimes be tracked. */ | |
800eeca4 JW |
709 | static struct gr { |
710 | unsigned known:1; | |
711 | int path; | |
712 | valueT value; | |
a66d2bb7 JB |
713 | } gr_values[128] = { |
714 | { | |
715 | 1, | |
716 | #ifdef INT_MAX | |
717 | INT_MAX, | |
718 | #else | |
719 | (((1 << (8 * sizeof(gr_values->path) - 2)) - 1) << 1) + 1, | |
720 | #endif | |
721 | 0 | |
722 | } | |
723 | }; | |
800eeca4 | 724 | |
9545c4ce L |
725 | /* Remember the alignment frag. */ |
726 | static fragS *align_frag; | |
727 | ||
800eeca4 JW |
728 | /* These are the routines required to output the various types of |
729 | unwind records. */ | |
730 | ||
f5a30c2e JW |
731 | /* A slot_number is a frag address plus the slot index (0-2). We use the |
732 | frag address here so that if there is a section switch in the middle of | |
733 | a function, then instructions emitted to a different section are not | |
734 | counted. Since there may be more than one frag for a function, this | |
735 | means we also need to keep track of which frag this address belongs to | |
736 | so we can compute inter-frag distances. This also nicely solves the | |
737 | problem with nops emitted for align directives, which can't easily be | |
738 | counted, but can easily be derived from frag sizes. */ | |
739 | ||
800eeca4 JW |
740 | typedef struct unw_rec_list { |
741 | unwind_record r; | |
e0c9811a | 742 | unsigned long slot_number; |
f5a30c2e | 743 | fragS *slot_frag; |
800eeca4 JW |
744 | struct unw_rec_list *next; |
745 | } unw_rec_list; | |
746 | ||
2434f565 | 747 | #define SLOT_NUM_NOT_SET (unsigned)-1 |
800eeca4 | 748 | |
6290819d NC |
749 | /* Linked list of saved prologue counts. A very poor |
750 | implementation of a map from label numbers to prologue counts. */ | |
751 | typedef struct label_prologue_count | |
752 | { | |
753 | struct label_prologue_count *next; | |
754 | unsigned long label_number; | |
755 | unsigned int prologue_count; | |
756 | } label_prologue_count; | |
757 | ||
5656b6b8 JB |
758 | typedef struct proc_pending |
759 | { | |
760 | symbolS *sym; | |
761 | struct proc_pending *next; | |
762 | } proc_pending; | |
763 | ||
e0c9811a JW |
764 | static struct |
765 | { | |
e0c9811a JW |
766 | /* Maintain a list of unwind entries for the current function. */ |
767 | unw_rec_list *list; | |
768 | unw_rec_list *tail; | |
800eeca4 | 769 | |
ad4b42b4 | 770 | /* Any unwind entries that should be attached to the current slot |
e0c9811a JW |
771 | that an insn is being constructed for. */ |
772 | unw_rec_list *current_entry; | |
800eeca4 | 773 | |
e0c9811a | 774 | /* These are used to create the unwind table entry for this function. */ |
5656b6b8 | 775 | proc_pending proc_pending; |
e0c9811a JW |
776 | symbolS *info; /* pointer to unwind info */ |
777 | symbolS *personality_routine; | |
91a2ae2a RH |
778 | segT saved_text_seg; |
779 | subsegT saved_text_subseg; | |
780 | unsigned int force_unwind_entry : 1; /* force generation of unwind entry? */ | |
800eeca4 | 781 | |
e0c9811a | 782 | /* TRUE if processing unwind directives in a prologue region. */ |
75e09913 JB |
783 | unsigned int prologue : 1; |
784 | unsigned int prologue_mask : 4; | |
e4e8248d | 785 | unsigned int prologue_gr : 7; |
75e09913 JB |
786 | unsigned int body : 1; |
787 | unsigned int insn : 1; | |
33d01f33 | 788 | unsigned int prologue_count; /* number of .prologues seen so far */ |
6290819d NC |
789 | /* Prologue counts at previous .label_state directives. */ |
790 | struct label_prologue_count * saved_prologue_counts; | |
ba825241 JB |
791 | |
792 | /* List of split up .save-s. */ | |
793 | unw_p_record *pending_saves; | |
e0c9811a | 794 | } unwind; |
800eeca4 | 795 | |
9f9a069e JW |
796 | /* The input value is a negated offset from psp, and specifies an address |
797 | psp - offset. The encoded value is psp + 16 - (4 * offset). Thus we | |
798 | must add 16 and divide by 4 to get the encoded value. */ | |
799 | ||
800 | #define ENCODED_PSP_OFFSET(OFFSET) (((OFFSET) + 16) / 4) | |
801 | ||
5a49b8ac | 802 | typedef void (*vbyte_func) (int, char *, char *); |
800eeca4 | 803 | |
0234cb7c | 804 | /* Forward declarations: */ |
5a49b8ac | 805 | static void dot_alias (int); |
cd42ff9c | 806 | static int parse_operand_and_eval (expressionS *, int); |
5a49b8ac AM |
807 | static void emit_one_bundle (void); |
808 | static bfd_reloc_code_real_type ia64_gen_real_reloc_type (struct symbol *, | |
809 | bfd_reloc_code_real_type); | |
810 | static void insn_group_break (int, int, int); | |
811 | static void add_qp_mutex (valueT); | |
812 | static void add_qp_imply (int, int); | |
813 | static void clear_qp_mutex (valueT); | |
814 | static void clear_qp_implies (valueT, valueT); | |
815 | static void print_dependency (const char *, int); | |
816 | static void instruction_serialization (void); | |
817 | static void data_serialization (void); | |
818 | static void output_R3_format (vbyte_func, unw_record_type, unsigned long); | |
819 | static void output_B3_format (vbyte_func, unsigned long, unsigned long); | |
820 | static void output_B4_format (vbyte_func, unw_record_type, unsigned long); | |
821 | static void free_saved_prologue_counts (void); | |
91a2ae2a | 822 | |
652ca075 | 823 | /* Determine if application register REGNUM resides only in the integer |
800eeca4 JW |
824 | unit (as opposed to the memory unit). */ |
825 | static int | |
652ca075 | 826 | ar_is_only_in_integer_unit (int reg) |
800eeca4 JW |
827 | { |
828 | reg -= REG_AR; | |
652ca075 L |
829 | return reg >= 64 && reg <= 111; |
830 | } | |
800eeca4 | 831 | |
3739860c | 832 | /* Determine if application register REGNUM resides only in the memory |
652ca075 L |
833 | unit (as opposed to the integer unit). */ |
834 | static int | |
835 | ar_is_only_in_memory_unit (int reg) | |
836 | { | |
837 | reg -= REG_AR; | |
838 | return reg >= 0 && reg <= 47; | |
800eeca4 JW |
839 | } |
840 | ||
841 | /* Switch to section NAME and create section if necessary. It's | |
842 | rather ugly that we have to manipulate input_line_pointer but I | |
843 | don't see any other way to accomplish the same thing without | |
844 | changing obj-elf.c (which may be the Right Thing, in the end). */ | |
845 | static void | |
5a49b8ac | 846 | set_section (char *name) |
800eeca4 JW |
847 | { |
848 | char *saved_input_line_pointer; | |
849 | ||
850 | saved_input_line_pointer = input_line_pointer; | |
851 | input_line_pointer = name; | |
852 | obj_elf_section (0); | |
853 | input_line_pointer = saved_input_line_pointer; | |
854 | } | |
855 | ||
d61a78a7 RH |
856 | /* Map 's' to SHF_IA_64_SHORT. */ |
857 | ||
01e1a5bc | 858 | bfd_vma |
5a49b8ac | 859 | ia64_elf_section_letter (int letter, char **ptr_msg) |
d61a78a7 RH |
860 | { |
861 | if (letter == 's') | |
862 | return SHF_IA_64_SHORT; | |
711ef82f L |
863 | else if (letter == 'o') |
864 | return SHF_LINK_ORDER; | |
01e1a5bc NC |
865 | #ifdef TE_VMS |
866 | else if (letter == 'O') | |
867 | return SHF_IA_64_VMS_OVERLAID; | |
868 | else if (letter == 'g') | |
869 | return SHF_IA_64_VMS_GLOBAL; | |
870 | #endif | |
d61a78a7 | 871 | |
8f3bae45 | 872 | *ptr_msg = _("bad .section directive: want a,o,s,w,x,M,S,G,T in string"); |
711ef82f | 873 | return -1; |
d61a78a7 RH |
874 | } |
875 | ||
800eeca4 JW |
876 | /* Map SHF_IA_64_SHORT to SEC_SMALL_DATA. */ |
877 | ||
878 | flagword | |
5a49b8ac | 879 | ia64_elf_section_flags (flagword flags, |
01e1a5bc | 880 | bfd_vma attr, |
5a49b8ac | 881 | int type ATTRIBUTE_UNUSED) |
800eeca4 JW |
882 | { |
883 | if (attr & SHF_IA_64_SHORT) | |
884 | flags |= SEC_SMALL_DATA; | |
885 | return flags; | |
886 | } | |
887 | ||
91a2ae2a | 888 | int |
5a49b8ac | 889 | ia64_elf_section_type (const char *str, size_t len) |
91a2ae2a | 890 | { |
1cd8ff38 | 891 | #define STREQ(s) ((len == sizeof (s) - 1) && (strncmp (str, s, sizeof (s) - 1) == 0)) |
40449e9f | 892 | |
1cd8ff38 | 893 | if (STREQ (ELF_STRING_ia64_unwind_info)) |
91a2ae2a RH |
894 | return SHT_PROGBITS; |
895 | ||
1cd8ff38 | 896 | if (STREQ (ELF_STRING_ia64_unwind_info_once)) |
579f31ac JJ |
897 | return SHT_PROGBITS; |
898 | ||
1cd8ff38 | 899 | if (STREQ (ELF_STRING_ia64_unwind)) |
91a2ae2a RH |
900 | return SHT_IA_64_UNWIND; |
901 | ||
1cd8ff38 | 902 | if (STREQ (ELF_STRING_ia64_unwind_once)) |
579f31ac JJ |
903 | return SHT_IA_64_UNWIND; |
904 | ||
711ef82f L |
905 | if (STREQ ("unwind")) |
906 | return SHT_IA_64_UNWIND; | |
907 | ||
91a2ae2a | 908 | return -1; |
1cd8ff38 | 909 | #undef STREQ |
91a2ae2a RH |
910 | } |
911 | ||
800eeca4 | 912 | static unsigned int |
5a49b8ac AM |
913 | set_regstack (unsigned int ins, |
914 | unsigned int locs, | |
915 | unsigned int outs, | |
916 | unsigned int rots) | |
800eeca4 | 917 | { |
542d6675 KH |
918 | /* Size of frame. */ |
919 | unsigned int sof; | |
800eeca4 JW |
920 | |
921 | sof = ins + locs + outs; | |
922 | if (sof > 96) | |
923 | { | |
ad4b42b4 | 924 | as_bad (_("Size of frame exceeds maximum of 96 registers")); |
800eeca4 JW |
925 | return 0; |
926 | } | |
927 | if (rots > sof) | |
928 | { | |
ad4b42b4 | 929 | as_warn (_("Size of rotating registers exceeds frame size")); |
800eeca4 JW |
930 | return 0; |
931 | } | |
932 | md.in.base = REG_GR + 32; | |
933 | md.loc.base = md.in.base + ins; | |
934 | md.out.base = md.loc.base + locs; | |
935 | ||
936 | md.in.num_regs = ins; | |
937 | md.loc.num_regs = locs; | |
938 | md.out.num_regs = outs; | |
939 | md.rot.num_regs = rots; | |
940 | return sof; | |
941 | } | |
942 | ||
943 | void | |
5a49b8ac | 944 | ia64_flush_insns (void) |
800eeca4 JW |
945 | { |
946 | struct label_fix *lfix; | |
947 | segT saved_seg; | |
948 | subsegT saved_subseg; | |
b44b1b85 | 949 | unw_rec_list *ptr; |
07a53e5c | 950 | bfd_boolean mark; |
800eeca4 JW |
951 | |
952 | if (!md.last_text_seg) | |
953 | return; | |
954 | ||
955 | saved_seg = now_seg; | |
956 | saved_subseg = now_subseg; | |
957 | ||
958 | subseg_set (md.last_text_seg, 0); | |
959 | ||
960 | while (md.num_slots_in_use > 0) | |
961 | emit_one_bundle (); /* force out queued instructions */ | |
962 | ||
963 | /* In case there are labels following the last instruction, resolve | |
07a53e5c RH |
964 | those now. */ |
965 | mark = FALSE; | |
800eeca4 JW |
966 | for (lfix = CURR_SLOT.label_fixups; lfix; lfix = lfix->next) |
967 | { | |
07a53e5c RH |
968 | symbol_set_value_now (lfix->sym); |
969 | mark |= lfix->dw2_mark_labels; | |
800eeca4 | 970 | } |
07a53e5c | 971 | if (mark) |
f1bcba5b | 972 | { |
07a53e5c RH |
973 | dwarf2_where (&CURR_SLOT.debug_line); |
974 | CURR_SLOT.debug_line.flags |= DWARF2_FLAG_BASIC_BLOCK; | |
975 | dwarf2_gen_line_info (frag_now_fix (), &CURR_SLOT.debug_line); | |
661ba50f | 976 | dwarf2_consume_line_info (); |
f1bcba5b | 977 | } |
07a53e5c RH |
978 | CURR_SLOT.label_fixups = 0; |
979 | ||
980 | for (lfix = CURR_SLOT.tag_fixups; lfix; lfix = lfix->next) | |
981 | symbol_set_value_now (lfix->sym); | |
f1bcba5b | 982 | CURR_SLOT.tag_fixups = 0; |
800eeca4 | 983 | |
b44b1b85 | 984 | /* In case there are unwind directives following the last instruction, |
5738bc24 JW |
985 | resolve those now. We only handle prologue, body, and endp directives |
986 | here. Give an error for others. */ | |
b44b1b85 JW |
987 | for (ptr = unwind.current_entry; ptr; ptr = ptr->next) |
988 | { | |
9c59842f | 989 | switch (ptr->r.type) |
b44b1b85 | 990 | { |
9c59842f JW |
991 | case prologue: |
992 | case prologue_gr: | |
993 | case body: | |
994 | case endp: | |
b44b1b85 JW |
995 | ptr->slot_number = (unsigned long) frag_more (0); |
996 | ptr->slot_frag = frag_now; | |
9c59842f JW |
997 | break; |
998 | ||
999 | /* Allow any record which doesn't have a "t" field (i.e., | |
1000 | doesn't relate to a particular instruction). */ | |
1001 | case unwabi: | |
1002 | case br_gr: | |
1003 | case copy_state: | |
1004 | case fr_mem: | |
1005 | case frgr_mem: | |
1006 | case gr_gr: | |
1007 | case gr_mem: | |
1008 | case label_state: | |
1009 | case rp_br: | |
1010 | case spill_base: | |
1011 | case spill_mask: | |
1012 | /* nothing */ | |
1013 | break; | |
1014 | ||
1015 | default: | |
1016 | as_bad (_("Unwind directive not followed by an instruction.")); | |
1017 | break; | |
b44b1b85 | 1018 | } |
b44b1b85 JW |
1019 | } |
1020 | unwind.current_entry = NULL; | |
1021 | ||
800eeca4 | 1022 | subseg_set (saved_seg, saved_subseg); |
f1bcba5b JW |
1023 | |
1024 | if (md.qp.X_op == O_register) | |
ad4b42b4 | 1025 | as_bad (_("qualifying predicate not followed by instruction")); |
800eeca4 JW |
1026 | } |
1027 | ||
d9201763 L |
1028 | static void |
1029 | ia64_do_align (int nbytes) | |
800eeca4 JW |
1030 | { |
1031 | char *saved_input_line_pointer = input_line_pointer; | |
1032 | ||
1033 | input_line_pointer = ""; | |
1034 | s_align_bytes (nbytes); | |
1035 | input_line_pointer = saved_input_line_pointer; | |
1036 | } | |
1037 | ||
1038 | void | |
5a49b8ac | 1039 | ia64_cons_align (int nbytes) |
800eeca4 JW |
1040 | { |
1041 | if (md.auto_align) | |
1042 | { | |
1043 | char *saved_input_line_pointer = input_line_pointer; | |
1044 | input_line_pointer = ""; | |
1045 | s_align_bytes (nbytes); | |
1046 | input_line_pointer = saved_input_line_pointer; | |
1047 | } | |
1048 | } | |
1049 | ||
2b0bc501 TG |
1050 | #ifdef TE_VMS |
1051 | ||
1052 | /* .vms_common section, symbol, size, alignment */ | |
1053 | ||
1054 | static void | |
1055 | obj_elf_vms_common (int ignore ATTRIBUTE_UNUSED) | |
1056 | { | |
1057 | char *sec_name; | |
1058 | char *sym_name; | |
1059 | char c; | |
1060 | offsetT size; | |
1061 | offsetT cur_size; | |
1062 | offsetT temp; | |
1063 | symbolS *symbolP; | |
1064 | segT current_seg = now_seg; | |
1065 | subsegT current_subseg = now_subseg; | |
1066 | offsetT log_align; | |
1067 | ||
1068 | /* Section name. */ | |
1069 | sec_name = obj_elf_section_name (); | |
1070 | if (sec_name == NULL) | |
1071 | return; | |
1072 | ||
1073 | /* Symbol name. */ | |
1074 | SKIP_WHITESPACE (); | |
1075 | if (*input_line_pointer == ',') | |
1076 | { | |
1077 | input_line_pointer++; | |
1078 | SKIP_WHITESPACE (); | |
1079 | } | |
1080 | else | |
1081 | { | |
1082 | as_bad (_("expected ',' after section name")); | |
1083 | ignore_rest_of_line (); | |
1084 | return; | |
1085 | } | |
1086 | ||
d02603dc | 1087 | c = get_symbol_name (&sym_name); |
2b0bc501 TG |
1088 | |
1089 | if (input_line_pointer == sym_name) | |
1090 | { | |
d02603dc | 1091 | (void) restore_line_pointer (c); |
2b0bc501 TG |
1092 | as_bad (_("expected symbol name")); |
1093 | ignore_rest_of_line (); | |
1094 | return; | |
1095 | } | |
1096 | ||
1097 | symbolP = symbol_find_or_make (sym_name); | |
d02603dc | 1098 | (void) restore_line_pointer (c); |
2b0bc501 TG |
1099 | |
1100 | if ((S_IS_DEFINED (symbolP) || symbol_equated_p (symbolP)) | |
1101 | && !S_IS_COMMON (symbolP)) | |
1102 | { | |
1103 | as_bad (_("Ignoring attempt to re-define symbol")); | |
1104 | ignore_rest_of_line (); | |
1105 | return; | |
1106 | } | |
1107 | ||
1108 | /* Symbol size. */ | |
1109 | SKIP_WHITESPACE (); | |
1110 | if (*input_line_pointer == ',') | |
1111 | { | |
1112 | input_line_pointer++; | |
1113 | SKIP_WHITESPACE (); | |
1114 | } | |
1115 | else | |
1116 | { | |
1117 | as_bad (_("expected ',' after symbol name")); | |
1118 | ignore_rest_of_line (); | |
1119 | return; | |
1120 | } | |
1121 | ||
1122 | temp = get_absolute_expression (); | |
1123 | size = temp; | |
1124 | size &= ((offsetT) 2 << (stdoutput->arch_info->bits_per_address - 1)) - 1; | |
1125 | if (temp != size) | |
1126 | { | |
1127 | as_warn (_("size (%ld) out of range, ignored"), (long) temp); | |
1128 | ignore_rest_of_line (); | |
1129 | return; | |
1130 | } | |
1131 | ||
1132 | /* Alignment. */ | |
1133 | SKIP_WHITESPACE (); | |
1134 | if (*input_line_pointer == ',') | |
1135 | { | |
1136 | input_line_pointer++; | |
1137 | SKIP_WHITESPACE (); | |
1138 | } | |
1139 | else | |
1140 | { | |
1141 | as_bad (_("expected ',' after symbol size")); | |
1142 | ignore_rest_of_line (); | |
1143 | return; | |
1144 | } | |
1145 | ||
1146 | log_align = get_absolute_expression (); | |
1147 | ||
1148 | demand_empty_rest_of_line (); | |
1149 | ||
1150 | obj_elf_change_section | |
1151 | (sec_name, SHT_NOBITS, | |
1152 | SHF_ALLOC | SHF_WRITE | SHF_IA_64_VMS_OVERLAID | SHF_IA_64_VMS_GLOBAL, | |
1153 | 0, NULL, 1, 0); | |
1154 | ||
1155 | S_SET_VALUE (symbolP, 0); | |
1156 | S_SET_SIZE (symbolP, size); | |
1157 | S_SET_EXTERNAL (symbolP); | |
1158 | S_SET_SEGMENT (symbolP, now_seg); | |
1159 | ||
1160 | symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT; | |
1161 | ||
1162 | record_alignment (now_seg, log_align); | |
1163 | ||
1164 | cur_size = bfd_section_size (stdoutput, now_seg); | |
1165 | if ((int) size > cur_size) | |
1166 | { | |
1167 | char *pfrag | |
1168 | = frag_var (rs_fill, 1, 1, (relax_substateT)0, NULL, | |
1169 | (valueT)size - (valueT)cur_size, NULL); | |
1170 | *pfrag = 0; | |
1171 | bfd_section_size (stdoutput, now_seg) = size; | |
1172 | } | |
1173 | ||
1174 | /* Switch back to current segment. */ | |
1175 | subseg_set (current_seg, current_subseg); | |
1176 | ||
1177 | #ifdef md_elf_section_change_hook | |
1178 | md_elf_section_change_hook (); | |
1179 | #endif | |
1180 | } | |
1181 | ||
1182 | #endif /* TE_VMS */ | |
1183 | ||
800eeca4 | 1184 | /* Output COUNT bytes to a memory location. */ |
2132e3a3 | 1185 | static char *vbyte_mem_ptr = NULL; |
800eeca4 | 1186 | |
5a49b8ac AM |
1187 | static void |
1188 | output_vbyte_mem (int count, char *ptr, char *comment ATTRIBUTE_UNUSED) | |
800eeca4 JW |
1189 | { |
1190 | int x; | |
1191 | if (vbyte_mem_ptr == NULL) | |
1192 | abort (); | |
1193 | ||
1194 | if (count == 0) | |
1195 | return; | |
1196 | for (x = 0; x < count; x++) | |
1197 | *(vbyte_mem_ptr++) = ptr[x]; | |
1198 | } | |
1199 | ||
1200 | /* Count the number of bytes required for records. */ | |
1201 | static int vbyte_count = 0; | |
5a49b8ac AM |
1202 | static void |
1203 | count_output (int count, | |
1204 | char *ptr ATTRIBUTE_UNUSED, | |
1205 | char *comment ATTRIBUTE_UNUSED) | |
800eeca4 JW |
1206 | { |
1207 | vbyte_count += count; | |
1208 | } | |
1209 | ||
1210 | static void | |
5a49b8ac | 1211 | output_R1_format (vbyte_func f, unw_record_type rtype, int rlen) |
800eeca4 | 1212 | { |
e0c9811a | 1213 | int r = 0; |
800eeca4 JW |
1214 | char byte; |
1215 | if (rlen > 0x1f) | |
1216 | { | |
1217 | output_R3_format (f, rtype, rlen); | |
1218 | return; | |
1219 | } | |
197865e8 | 1220 | |
e0c9811a JW |
1221 | if (rtype == body) |
1222 | r = 1; | |
1223 | else if (rtype != prologue) | |
ad4b42b4 | 1224 | as_bad (_("record type is not valid")); |
e0c9811a | 1225 | |
800eeca4 JW |
1226 | byte = UNW_R1 | (r << 5) | (rlen & 0x1f); |
1227 | (*f) (1, &byte, NULL); | |
1228 | } | |
1229 | ||
1230 | static void | |
5a49b8ac | 1231 | output_R2_format (vbyte_func f, int mask, int grsave, unsigned long rlen) |
800eeca4 JW |
1232 | { |
1233 | char bytes[20]; | |
1234 | int count = 2; | |
1235 | mask = (mask & 0x0f); | |
1236 | grsave = (grsave & 0x7f); | |
1237 | ||
1238 | bytes[0] = (UNW_R2 | (mask >> 1)); | |
1239 | bytes[1] = (((mask & 0x01) << 7) | grsave); | |
1240 | count += output_leb128 (bytes + 2, rlen, 0); | |
1241 | (*f) (count, bytes, NULL); | |
1242 | } | |
1243 | ||
1244 | static void | |
5a49b8ac | 1245 | output_R3_format (vbyte_func f, unw_record_type rtype, unsigned long rlen) |
800eeca4 | 1246 | { |
e0c9811a | 1247 | int r = 0, count; |
800eeca4 JW |
1248 | char bytes[20]; |
1249 | if (rlen <= 0x1f) | |
1250 | { | |
1251 | output_R1_format (f, rtype, rlen); | |
1252 | return; | |
1253 | } | |
197865e8 | 1254 | |
e0c9811a JW |
1255 | if (rtype == body) |
1256 | r = 1; | |
1257 | else if (rtype != prologue) | |
ad4b42b4 | 1258 | as_bad (_("record type is not valid")); |
800eeca4 JW |
1259 | bytes[0] = (UNW_R3 | r); |
1260 | count = output_leb128 (bytes + 1, rlen, 0); | |
1261 | (*f) (count + 1, bytes, NULL); | |
1262 | } | |
1263 | ||
1264 | static void | |
5a49b8ac | 1265 | output_P1_format (vbyte_func f, int brmask) |
800eeca4 JW |
1266 | { |
1267 | char byte; | |
1268 | byte = UNW_P1 | (brmask & 0x1f); | |
1269 | (*f) (1, &byte, NULL); | |
1270 | } | |
1271 | ||
1272 | static void | |
5a49b8ac | 1273 | output_P2_format (vbyte_func f, int brmask, int gr) |
800eeca4 JW |
1274 | { |
1275 | char bytes[2]; | |
1276 | brmask = (brmask & 0x1f); | |
1277 | bytes[0] = UNW_P2 | (brmask >> 1); | |
1278 | bytes[1] = (((brmask & 1) << 7) | gr); | |
1279 | (*f) (2, bytes, NULL); | |
1280 | } | |
1281 | ||
1282 | static void | |
5a49b8ac | 1283 | output_P3_format (vbyte_func f, unw_record_type rtype, int reg) |
800eeca4 JW |
1284 | { |
1285 | char bytes[2]; | |
e0c9811a | 1286 | int r = 0; |
800eeca4 JW |
1287 | reg = (reg & 0x7f); |
1288 | switch (rtype) | |
542d6675 | 1289 | { |
800eeca4 JW |
1290 | case psp_gr: |
1291 | r = 0; | |
1292 | break; | |
1293 | case rp_gr: | |
1294 | r = 1; | |
1295 | break; | |
1296 | case pfs_gr: | |
1297 | r = 2; | |
1298 | break; | |
1299 | case preds_gr: | |
1300 | r = 3; | |
1301 | break; | |
1302 | case unat_gr: | |
1303 | r = 4; | |
1304 | break; | |
1305 | case lc_gr: | |
1306 | r = 5; | |
1307 | break; | |
1308 | case rp_br: | |
1309 | r = 6; | |
1310 | break; | |
1311 | case rnat_gr: | |
1312 | r = 7; | |
1313 | break; | |
1314 | case bsp_gr: | |
1315 | r = 8; | |
1316 | break; | |
1317 | case bspstore_gr: | |
1318 | r = 9; | |
1319 | break; | |
1320 | case fpsr_gr: | |
1321 | r = 10; | |
1322 | break; | |
1323 | case priunat_gr: | |
1324 | r = 11; | |
1325 | break; | |
1326 | default: | |
ad4b42b4 | 1327 | as_bad (_("Invalid record type for P3 format.")); |
542d6675 | 1328 | } |
800eeca4 JW |
1329 | bytes[0] = (UNW_P3 | (r >> 1)); |
1330 | bytes[1] = (((r & 1) << 7) | reg); | |
1331 | (*f) (2, bytes, NULL); | |
1332 | } | |
1333 | ||
800eeca4 | 1334 | static void |
5a49b8ac | 1335 | output_P4_format (vbyte_func f, unsigned char *imask, unsigned long imask_size) |
800eeca4 | 1336 | { |
e0c9811a | 1337 | imask[0] = UNW_P4; |
2132e3a3 | 1338 | (*f) (imask_size, (char *) imask, NULL); |
800eeca4 JW |
1339 | } |
1340 | ||
1341 | static void | |
5a49b8ac | 1342 | output_P5_format (vbyte_func f, int grmask, unsigned long frmask) |
800eeca4 JW |
1343 | { |
1344 | char bytes[4]; | |
1345 | grmask = (grmask & 0x0f); | |
1346 | ||
1347 | bytes[0] = UNW_P5; | |
1348 | bytes[1] = ((grmask << 4) | ((frmask & 0x000f0000) >> 16)); | |
1349 | bytes[2] = ((frmask & 0x0000ff00) >> 8); | |
1350 | bytes[3] = (frmask & 0x000000ff); | |
1351 | (*f) (4, bytes, NULL); | |
1352 | } | |
1353 | ||
1354 | static void | |
5a49b8ac | 1355 | output_P6_format (vbyte_func f, unw_record_type rtype, int rmask) |
800eeca4 JW |
1356 | { |
1357 | char byte; | |
e0c9811a | 1358 | int r = 0; |
197865e8 | 1359 | |
e0c9811a JW |
1360 | if (rtype == gr_mem) |
1361 | r = 1; | |
1362 | else if (rtype != fr_mem) | |
ad4b42b4 | 1363 | as_bad (_("Invalid record type for format P6")); |
800eeca4 JW |
1364 | byte = (UNW_P6 | (r << 4) | (rmask & 0x0f)); |
1365 | (*f) (1, &byte, NULL); | |
1366 | } | |
1367 | ||
1368 | static void | |
5a49b8ac AM |
1369 | output_P7_format (vbyte_func f, |
1370 | unw_record_type rtype, | |
1371 | unsigned long w1, | |
1372 | unsigned long w2) | |
800eeca4 JW |
1373 | { |
1374 | char bytes[20]; | |
1375 | int count = 1; | |
e0c9811a | 1376 | int r = 0; |
800eeca4 JW |
1377 | count += output_leb128 (bytes + 1, w1, 0); |
1378 | switch (rtype) | |
1379 | { | |
542d6675 KH |
1380 | case mem_stack_f: |
1381 | r = 0; | |
1382 | count += output_leb128 (bytes + count, w2 >> 4, 0); | |
1383 | break; | |
1384 | case mem_stack_v: | |
1385 | r = 1; | |
1386 | break; | |
1387 | case spill_base: | |
1388 | r = 2; | |
1389 | break; | |
1390 | case psp_sprel: | |
1391 | r = 3; | |
1392 | break; | |
1393 | case rp_when: | |
1394 | r = 4; | |
1395 | break; | |
1396 | case rp_psprel: | |
1397 | r = 5; | |
1398 | break; | |
1399 | case pfs_when: | |
1400 | r = 6; | |
1401 | break; | |
1402 | case pfs_psprel: | |
1403 | r = 7; | |
1404 | break; | |
1405 | case preds_when: | |
1406 | r = 8; | |
1407 | break; | |
1408 | case preds_psprel: | |
1409 | r = 9; | |
1410 | break; | |
1411 | case lc_when: | |
1412 | r = 10; | |
1413 | break; | |
1414 | case lc_psprel: | |
1415 | r = 11; | |
1416 | break; | |
1417 | case unat_when: | |
1418 | r = 12; | |
1419 | break; | |
1420 | case unat_psprel: | |
1421 | r = 13; | |
1422 | break; | |
1423 | case fpsr_when: | |
1424 | r = 14; | |
1425 | break; | |
1426 | case fpsr_psprel: | |
1427 | r = 15; | |
1428 | break; | |
1429 | default: | |
1430 | break; | |
800eeca4 JW |
1431 | } |
1432 | bytes[0] = (UNW_P7 | r); | |
1433 | (*f) (count, bytes, NULL); | |
1434 | } | |
1435 | ||
1436 | static void | |
5a49b8ac | 1437 | output_P8_format (vbyte_func f, unw_record_type rtype, unsigned long t) |
800eeca4 JW |
1438 | { |
1439 | char bytes[20]; | |
e0c9811a | 1440 | int r = 0; |
800eeca4 JW |
1441 | int count = 2; |
1442 | bytes[0] = UNW_P8; | |
1443 | switch (rtype) | |
1444 | { | |
542d6675 KH |
1445 | case rp_sprel: |
1446 | r = 1; | |
1447 | break; | |
1448 | case pfs_sprel: | |
1449 | r = 2; | |
1450 | break; | |
1451 | case preds_sprel: | |
1452 | r = 3; | |
1453 | break; | |
1454 | case lc_sprel: | |
1455 | r = 4; | |
1456 | break; | |
1457 | case unat_sprel: | |
1458 | r = 5; | |
1459 | break; | |
1460 | case fpsr_sprel: | |
1461 | r = 6; | |
1462 | break; | |
1463 | case bsp_when: | |
1464 | r = 7; | |
1465 | break; | |
1466 | case bsp_psprel: | |
1467 | r = 8; | |
1468 | break; | |
1469 | case bsp_sprel: | |
1470 | r = 9; | |
1471 | break; | |
1472 | case bspstore_when: | |
1473 | r = 10; | |
1474 | break; | |
1475 | case bspstore_psprel: | |
1476 | r = 11; | |
1477 | break; | |
1478 | case bspstore_sprel: | |
1479 | r = 12; | |
1480 | break; | |
1481 | case rnat_when: | |
1482 | r = 13; | |
1483 | break; | |
1484 | case rnat_psprel: | |
1485 | r = 14; | |
1486 | break; | |
1487 | case rnat_sprel: | |
1488 | r = 15; | |
1489 | break; | |
1490 | case priunat_when_gr: | |
1491 | r = 16; | |
1492 | break; | |
1493 | case priunat_psprel: | |
1494 | r = 17; | |
1495 | break; | |
1496 | case priunat_sprel: | |
1497 | r = 18; | |
1498 | break; | |
1499 | case priunat_when_mem: | |
1500 | r = 19; | |
1501 | break; | |
1502 | default: | |
1503 | break; | |
800eeca4 JW |
1504 | } |
1505 | bytes[1] = r; | |
1506 | count += output_leb128 (bytes + 2, t, 0); | |
1507 | (*f) (count, bytes, NULL); | |
1508 | } | |
1509 | ||
1510 | static void | |
5a49b8ac | 1511 | output_P9_format (vbyte_func f, int grmask, int gr) |
800eeca4 JW |
1512 | { |
1513 | char bytes[3]; | |
1514 | bytes[0] = UNW_P9; | |
1515 | bytes[1] = (grmask & 0x0f); | |
1516 | bytes[2] = (gr & 0x7f); | |
1517 | (*f) (3, bytes, NULL); | |
1518 | } | |
1519 | ||
1520 | static void | |
5a49b8ac | 1521 | output_P10_format (vbyte_func f, int abi, int context) |
800eeca4 JW |
1522 | { |
1523 | char bytes[3]; | |
1524 | bytes[0] = UNW_P10; | |
1525 | bytes[1] = (abi & 0xff); | |
1526 | bytes[2] = (context & 0xff); | |
1527 | (*f) (3, bytes, NULL); | |
1528 | } | |
1529 | ||
1530 | static void | |
5a49b8ac | 1531 | output_B1_format (vbyte_func f, unw_record_type rtype, unsigned long label) |
800eeca4 JW |
1532 | { |
1533 | char byte; | |
e0c9811a | 1534 | int r = 0; |
197865e8 | 1535 | if (label > 0x1f) |
800eeca4 JW |
1536 | { |
1537 | output_B4_format (f, rtype, label); | |
1538 | return; | |
1539 | } | |
e0c9811a JW |
1540 | if (rtype == copy_state) |
1541 | r = 1; | |
1542 | else if (rtype != label_state) | |
ad4b42b4 | 1543 | as_bad (_("Invalid record type for format B1")); |
800eeca4 JW |
1544 | |
1545 | byte = (UNW_B1 | (r << 5) | (label & 0x1f)); | |
1546 | (*f) (1, &byte, NULL); | |
1547 | } | |
1548 | ||
1549 | static void | |
5a49b8ac | 1550 | output_B2_format (vbyte_func f, unsigned long ecount, unsigned long t) |
800eeca4 JW |
1551 | { |
1552 | char bytes[20]; | |
1553 | int count = 1; | |
1554 | if (ecount > 0x1f) | |
1555 | { | |
1556 | output_B3_format (f, ecount, t); | |
1557 | return; | |
1558 | } | |
1559 | bytes[0] = (UNW_B2 | (ecount & 0x1f)); | |
1560 | count += output_leb128 (bytes + 1, t, 0); | |
1561 | (*f) (count, bytes, NULL); | |
1562 | } | |
1563 | ||
1564 | static void | |
5a49b8ac | 1565 | output_B3_format (vbyte_func f, unsigned long ecount, unsigned long t) |
800eeca4 JW |
1566 | { |
1567 | char bytes[20]; | |
1568 | int count = 1; | |
1569 | if (ecount <= 0x1f) | |
1570 | { | |
1571 | output_B2_format (f, ecount, t); | |
1572 | return; | |
1573 | } | |
1574 | bytes[0] = UNW_B3; | |
1575 | count += output_leb128 (bytes + 1, t, 0); | |
1576 | count += output_leb128 (bytes + count, ecount, 0); | |
1577 | (*f) (count, bytes, NULL); | |
1578 | } | |
1579 | ||
1580 | static void | |
5a49b8ac | 1581 | output_B4_format (vbyte_func f, unw_record_type rtype, unsigned long label) |
800eeca4 JW |
1582 | { |
1583 | char bytes[20]; | |
e0c9811a | 1584 | int r = 0; |
800eeca4 | 1585 | int count = 1; |
197865e8 | 1586 | if (label <= 0x1f) |
800eeca4 JW |
1587 | { |
1588 | output_B1_format (f, rtype, label); | |
1589 | return; | |
1590 | } | |
197865e8 | 1591 | |
e0c9811a JW |
1592 | if (rtype == copy_state) |
1593 | r = 1; | |
1594 | else if (rtype != label_state) | |
ad4b42b4 | 1595 | as_bad (_("Invalid record type for format B1")); |
800eeca4 JW |
1596 | |
1597 | bytes[0] = (UNW_B4 | (r << 3)); | |
1598 | count += output_leb128 (bytes + 1, label, 0); | |
1599 | (*f) (count, bytes, NULL); | |
1600 | } | |
1601 | ||
1602 | static char | |
5a49b8ac | 1603 | format_ab_reg (int ab, int reg) |
800eeca4 JW |
1604 | { |
1605 | int ret; | |
e0c9811a | 1606 | ab = (ab & 3); |
800eeca4 | 1607 | reg = (reg & 0x1f); |
e0c9811a | 1608 | ret = (ab << 5) | reg; |
800eeca4 JW |
1609 | return ret; |
1610 | } | |
1611 | ||
1612 | static void | |
5a49b8ac AM |
1613 | output_X1_format (vbyte_func f, |
1614 | unw_record_type rtype, | |
1615 | int ab, | |
1616 | int reg, | |
1617 | unsigned long t, | |
1618 | unsigned long w1) | |
800eeca4 JW |
1619 | { |
1620 | char bytes[20]; | |
e0c9811a | 1621 | int r = 0; |
800eeca4 JW |
1622 | int count = 2; |
1623 | bytes[0] = UNW_X1; | |
197865e8 | 1624 | |
e0c9811a JW |
1625 | if (rtype == spill_sprel) |
1626 | r = 1; | |
1627 | else if (rtype != spill_psprel) | |
ad4b42b4 | 1628 | as_bad (_("Invalid record type for format X1")); |
e0c9811a | 1629 | bytes[1] = ((r << 7) | format_ab_reg (ab, reg)); |
800eeca4 JW |
1630 | count += output_leb128 (bytes + 2, t, 0); |
1631 | count += output_leb128 (bytes + count, w1, 0); | |
1632 | (*f) (count, bytes, NULL); | |
1633 | } | |
1634 | ||
1635 | static void | |
5a49b8ac AM |
1636 | output_X2_format (vbyte_func f, |
1637 | int ab, | |
1638 | int reg, | |
1639 | int x, | |
1640 | int y, | |
1641 | int treg, | |
1642 | unsigned long t) | |
800eeca4 JW |
1643 | { |
1644 | char bytes[20]; | |
800eeca4 JW |
1645 | int count = 3; |
1646 | bytes[0] = UNW_X2; | |
e0c9811a | 1647 | bytes[1] = (((x & 1) << 7) | format_ab_reg (ab, reg)); |
800eeca4 JW |
1648 | bytes[2] = (((y & 1) << 7) | (treg & 0x7f)); |
1649 | count += output_leb128 (bytes + 3, t, 0); | |
1650 | (*f) (count, bytes, NULL); | |
1651 | } | |
1652 | ||
1653 | static void | |
5a49b8ac AM |
1654 | output_X3_format (vbyte_func f, |
1655 | unw_record_type rtype, | |
1656 | int qp, | |
1657 | int ab, | |
1658 | int reg, | |
1659 | unsigned long t, | |
1660 | unsigned long w1) | |
800eeca4 JW |
1661 | { |
1662 | char bytes[20]; | |
e0c9811a | 1663 | int r = 0; |
800eeca4 | 1664 | int count = 3; |
e0c9811a JW |
1665 | bytes[0] = UNW_X3; |
1666 | ||
1667 | if (rtype == spill_sprel_p) | |
1668 | r = 1; | |
1669 | else if (rtype != spill_psprel_p) | |
ad4b42b4 | 1670 | as_bad (_("Invalid record type for format X3")); |
800eeca4 | 1671 | bytes[1] = ((r << 7) | (qp & 0x3f)); |
e0c9811a | 1672 | bytes[2] = format_ab_reg (ab, reg); |
800eeca4 JW |
1673 | count += output_leb128 (bytes + 3, t, 0); |
1674 | count += output_leb128 (bytes + count, w1, 0); | |
1675 | (*f) (count, bytes, NULL); | |
1676 | } | |
1677 | ||
1678 | static void | |
5a49b8ac AM |
1679 | output_X4_format (vbyte_func f, |
1680 | int qp, | |
1681 | int ab, | |
1682 | int reg, | |
1683 | int x, | |
1684 | int y, | |
1685 | int treg, | |
1686 | unsigned long t) | |
800eeca4 JW |
1687 | { |
1688 | char bytes[20]; | |
800eeca4 | 1689 | int count = 4; |
e0c9811a | 1690 | bytes[0] = UNW_X4; |
800eeca4 | 1691 | bytes[1] = (qp & 0x3f); |
e0c9811a | 1692 | bytes[2] = (((x & 1) << 7) | format_ab_reg (ab, reg)); |
800eeca4 JW |
1693 | bytes[3] = (((y & 1) << 7) | (treg & 0x7f)); |
1694 | count += output_leb128 (bytes + 4, t, 0); | |
1695 | (*f) (count, bytes, NULL); | |
1696 | } | |
1697 | ||
ba825241 JB |
1698 | /* This function checks whether there are any outstanding .save-s and |
1699 | discards them if so. */ | |
1700 | ||
1701 | static void | |
1702 | check_pending_save (void) | |
1703 | { | |
1704 | if (unwind.pending_saves) | |
1705 | { | |
1706 | unw_rec_list *cur, *prev; | |
1707 | ||
ad4b42b4 | 1708 | as_warn (_("Previous .save incomplete")); |
ba825241 JB |
1709 | for (cur = unwind.list, prev = NULL; cur; ) |
1710 | if (&cur->r.record.p == unwind.pending_saves) | |
1711 | { | |
1712 | if (prev) | |
1713 | prev->next = cur->next; | |
1714 | else | |
1715 | unwind.list = cur->next; | |
1716 | if (cur == unwind.tail) | |
1717 | unwind.tail = prev; | |
1718 | if (cur == unwind.current_entry) | |
1719 | unwind.current_entry = cur->next; | |
1720 | /* Don't free the first discarded record, it's being used as | |
1721 | terminator for (currently) br_gr and gr_gr processing, and | |
1722 | also prevents leaving a dangling pointer to it in its | |
1723 | predecessor. */ | |
1724 | cur->r.record.p.grmask = 0; | |
1725 | cur->r.record.p.brmask = 0; | |
1726 | cur->r.record.p.frmask = 0; | |
1727 | prev = cur->r.record.p.next; | |
1728 | cur->r.record.p.next = NULL; | |
1729 | cur = prev; | |
1730 | break; | |
1731 | } | |
1732 | else | |
1733 | { | |
1734 | prev = cur; | |
1735 | cur = cur->next; | |
1736 | } | |
1737 | while (cur) | |
1738 | { | |
1739 | prev = cur; | |
1740 | cur = cur->r.record.p.next; | |
1741 | free (prev); | |
1742 | } | |
1743 | unwind.pending_saves = NULL; | |
1744 | } | |
1745 | } | |
1746 | ||
800eeca4 | 1747 | /* This function allocates a record list structure, and initializes fields. */ |
542d6675 | 1748 | |
800eeca4 | 1749 | static unw_rec_list * |
197865e8 | 1750 | alloc_record (unw_record_type t) |
800eeca4 JW |
1751 | { |
1752 | unw_rec_list *ptr; | |
1753 | ptr = xmalloc (sizeof (*ptr)); | |
ba825241 | 1754 | memset (ptr, 0, sizeof (*ptr)); |
800eeca4 JW |
1755 | ptr->slot_number = SLOT_NUM_NOT_SET; |
1756 | ptr->r.type = t; | |
1757 | return ptr; | |
1758 | } | |
1759 | ||
5738bc24 JW |
1760 | /* Dummy unwind record used for calculating the length of the last prologue or |
1761 | body region. */ | |
1762 | ||
1763 | static unw_rec_list * | |
5a49b8ac | 1764 | output_endp (void) |
5738bc24 JW |
1765 | { |
1766 | unw_rec_list *ptr = alloc_record (endp); | |
1767 | return ptr; | |
1768 | } | |
1769 | ||
800eeca4 | 1770 | static unw_rec_list * |
5a49b8ac | 1771 | output_prologue (void) |
800eeca4 JW |
1772 | { |
1773 | unw_rec_list *ptr = alloc_record (prologue); | |
e0c9811a | 1774 | memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask)); |
800eeca4 JW |
1775 | return ptr; |
1776 | } | |
1777 | ||
1778 | static unw_rec_list * | |
5a49b8ac | 1779 | output_prologue_gr (unsigned int saved_mask, unsigned int reg) |
800eeca4 JW |
1780 | { |
1781 | unw_rec_list *ptr = alloc_record (prologue_gr); | |
e0c9811a JW |
1782 | memset (&ptr->r.record.r.mask, 0, sizeof (ptr->r.record.r.mask)); |
1783 | ptr->r.record.r.grmask = saved_mask; | |
800eeca4 JW |
1784 | ptr->r.record.r.grsave = reg; |
1785 | return ptr; | |
1786 | } | |
1787 | ||
1788 | static unw_rec_list * | |
5a49b8ac | 1789 | output_body (void) |
800eeca4 JW |
1790 | { |
1791 | unw_rec_list *ptr = alloc_record (body); | |
1792 | return ptr; | |
1793 | } | |
1794 | ||
1795 | static unw_rec_list * | |
5a49b8ac | 1796 | output_mem_stack_f (unsigned int size) |
800eeca4 JW |
1797 | { |
1798 | unw_rec_list *ptr = alloc_record (mem_stack_f); | |
1799 | ptr->r.record.p.size = size; | |
1800 | return ptr; | |
1801 | } | |
1802 | ||
1803 | static unw_rec_list * | |
5a49b8ac | 1804 | output_mem_stack_v (void) |
800eeca4 JW |
1805 | { |
1806 | unw_rec_list *ptr = alloc_record (mem_stack_v); | |
1807 | return ptr; | |
1808 | } | |
1809 | ||
1810 | static unw_rec_list * | |
5a49b8ac | 1811 | output_psp_gr (unsigned int gr) |
800eeca4 JW |
1812 | { |
1813 | unw_rec_list *ptr = alloc_record (psp_gr); | |
ba825241 | 1814 | ptr->r.record.p.r.gr = gr; |
800eeca4 JW |
1815 | return ptr; |
1816 | } | |
1817 | ||
1818 | static unw_rec_list * | |
5a49b8ac | 1819 | output_psp_sprel (unsigned int offset) |
800eeca4 JW |
1820 | { |
1821 | unw_rec_list *ptr = alloc_record (psp_sprel); | |
ba825241 | 1822 | ptr->r.record.p.off.sp = offset / 4; |
800eeca4 JW |
1823 | return ptr; |
1824 | } | |
1825 | ||
1826 | static unw_rec_list * | |
5a49b8ac | 1827 | output_rp_when (void) |
800eeca4 JW |
1828 | { |
1829 | unw_rec_list *ptr = alloc_record (rp_when); | |
1830 | return ptr; | |
1831 | } | |
1832 | ||
1833 | static unw_rec_list * | |
5a49b8ac | 1834 | output_rp_gr (unsigned int gr) |
800eeca4 JW |
1835 | { |
1836 | unw_rec_list *ptr = alloc_record (rp_gr); | |
ba825241 | 1837 | ptr->r.record.p.r.gr = gr; |
800eeca4 JW |
1838 | return ptr; |
1839 | } | |
1840 | ||
1841 | static unw_rec_list * | |
5a49b8ac | 1842 | output_rp_br (unsigned int br) |
800eeca4 JW |
1843 | { |
1844 | unw_rec_list *ptr = alloc_record (rp_br); | |
ba825241 | 1845 | ptr->r.record.p.r.br = br; |
800eeca4 JW |
1846 | return ptr; |
1847 | } | |
1848 | ||
1849 | static unw_rec_list * | |
5a49b8ac | 1850 | output_rp_psprel (unsigned int offset) |
800eeca4 JW |
1851 | { |
1852 | unw_rec_list *ptr = alloc_record (rp_psprel); | |
ba825241 | 1853 | ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset); |
800eeca4 JW |
1854 | return ptr; |
1855 | } | |
1856 | ||
1857 | static unw_rec_list * | |
5a49b8ac | 1858 | output_rp_sprel (unsigned int offset) |
800eeca4 JW |
1859 | { |
1860 | unw_rec_list *ptr = alloc_record (rp_sprel); | |
ba825241 | 1861 | ptr->r.record.p.off.sp = offset / 4; |
800eeca4 JW |
1862 | return ptr; |
1863 | } | |
1864 | ||
1865 | static unw_rec_list * | |
5a49b8ac | 1866 | output_pfs_when (void) |
800eeca4 JW |
1867 | { |
1868 | unw_rec_list *ptr = alloc_record (pfs_when); | |
1869 | return ptr; | |
1870 | } | |
1871 | ||
1872 | static unw_rec_list * | |
5a49b8ac | 1873 | output_pfs_gr (unsigned int gr) |
800eeca4 JW |
1874 | { |
1875 | unw_rec_list *ptr = alloc_record (pfs_gr); | |
ba825241 | 1876 | ptr->r.record.p.r.gr = gr; |
800eeca4 JW |
1877 | return ptr; |
1878 | } | |
1879 | ||
1880 | static unw_rec_list * | |
5a49b8ac | 1881 | output_pfs_psprel (unsigned int offset) |
800eeca4 JW |
1882 | { |
1883 | unw_rec_list *ptr = alloc_record (pfs_psprel); | |
ba825241 | 1884 | ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset); |
800eeca4 JW |
1885 | return ptr; |
1886 | } | |
1887 | ||
1888 | static unw_rec_list * | |
5a49b8ac | 1889 | output_pfs_sprel (unsigned int offset) |
800eeca4 JW |
1890 | { |
1891 | unw_rec_list *ptr = alloc_record (pfs_sprel); | |
ba825241 | 1892 | ptr->r.record.p.off.sp = offset / 4; |
800eeca4 JW |
1893 | return ptr; |
1894 | } | |
1895 | ||
1896 | static unw_rec_list * | |
5a49b8ac | 1897 | output_preds_when (void) |
800eeca4 JW |
1898 | { |
1899 | unw_rec_list *ptr = alloc_record (preds_when); | |
1900 | return ptr; | |
1901 | } | |
1902 | ||
1903 | static unw_rec_list * | |
5a49b8ac | 1904 | output_preds_gr (unsigned int gr) |
800eeca4 JW |
1905 | { |
1906 | unw_rec_list *ptr = alloc_record (preds_gr); | |
ba825241 | 1907 | ptr->r.record.p.r.gr = gr; |
800eeca4 JW |
1908 | return ptr; |
1909 | } | |
1910 | ||
1911 | static unw_rec_list * | |
5a49b8ac | 1912 | output_preds_psprel (unsigned int offset) |
800eeca4 JW |
1913 | { |
1914 | unw_rec_list *ptr = alloc_record (preds_psprel); | |
ba825241 | 1915 | ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset); |
800eeca4 JW |
1916 | return ptr; |
1917 | } | |
1918 | ||
1919 | static unw_rec_list * | |
5a49b8ac | 1920 | output_preds_sprel (unsigned int offset) |
800eeca4 JW |
1921 | { |
1922 | unw_rec_list *ptr = alloc_record (preds_sprel); | |
ba825241 | 1923 | ptr->r.record.p.off.sp = offset / 4; |
800eeca4 JW |
1924 | return ptr; |
1925 | } | |
1926 | ||
1927 | static unw_rec_list * | |
5a49b8ac | 1928 | output_fr_mem (unsigned int mask) |
800eeca4 JW |
1929 | { |
1930 | unw_rec_list *ptr = alloc_record (fr_mem); | |
ba825241 JB |
1931 | unw_rec_list *cur = ptr; |
1932 | ||
1933 | ptr->r.record.p.frmask = mask; | |
1934 | unwind.pending_saves = &ptr->r.record.p; | |
1935 | for (;;) | |
1936 | { | |
1937 | unw_rec_list *prev = cur; | |
1938 | ||
1939 | /* Clear least significant set bit. */ | |
1940 | mask &= ~(mask & (~mask + 1)); | |
1941 | if (!mask) | |
1942 | return ptr; | |
1943 | cur = alloc_record (fr_mem); | |
1944 | cur->r.record.p.frmask = mask; | |
1945 | /* Retain only least significant bit. */ | |
1946 | prev->r.record.p.frmask ^= mask; | |
1947 | prev->r.record.p.next = cur; | |
1948 | } | |
800eeca4 JW |
1949 | } |
1950 | ||
1951 | static unw_rec_list * | |
5a49b8ac | 1952 | output_frgr_mem (unsigned int gr_mask, unsigned int fr_mask) |
800eeca4 JW |
1953 | { |
1954 | unw_rec_list *ptr = alloc_record (frgr_mem); | |
ba825241 JB |
1955 | unw_rec_list *cur = ptr; |
1956 | ||
1957 | unwind.pending_saves = &cur->r.record.p; | |
1958 | cur->r.record.p.frmask = fr_mask; | |
1959 | while (fr_mask) | |
1960 | { | |
1961 | unw_rec_list *prev = cur; | |
1962 | ||
1963 | /* Clear least significant set bit. */ | |
1964 | fr_mask &= ~(fr_mask & (~fr_mask + 1)); | |
1965 | if (!gr_mask && !fr_mask) | |
1966 | return ptr; | |
1967 | cur = alloc_record (frgr_mem); | |
1968 | cur->r.record.p.frmask = fr_mask; | |
1969 | /* Retain only least significant bit. */ | |
1970 | prev->r.record.p.frmask ^= fr_mask; | |
1971 | prev->r.record.p.next = cur; | |
1972 | } | |
1973 | cur->r.record.p.grmask = gr_mask; | |
1974 | for (;;) | |
1975 | { | |
1976 | unw_rec_list *prev = cur; | |
1977 | ||
1978 | /* Clear least significant set bit. */ | |
1979 | gr_mask &= ~(gr_mask & (~gr_mask + 1)); | |
1980 | if (!gr_mask) | |
1981 | return ptr; | |
1982 | cur = alloc_record (frgr_mem); | |
1983 | cur->r.record.p.grmask = gr_mask; | |
1984 | /* Retain only least significant bit. */ | |
1985 | prev->r.record.p.grmask ^= gr_mask; | |
1986 | prev->r.record.p.next = cur; | |
1987 | } | |
800eeca4 JW |
1988 | } |
1989 | ||
1990 | static unw_rec_list * | |
5a49b8ac | 1991 | output_gr_gr (unsigned int mask, unsigned int reg) |
800eeca4 JW |
1992 | { |
1993 | unw_rec_list *ptr = alloc_record (gr_gr); | |
ba825241 JB |
1994 | unw_rec_list *cur = ptr; |
1995 | ||
800eeca4 | 1996 | ptr->r.record.p.grmask = mask; |
ba825241 JB |
1997 | ptr->r.record.p.r.gr = reg; |
1998 | unwind.pending_saves = &ptr->r.record.p; | |
1999 | for (;;) | |
2000 | { | |
2001 | unw_rec_list *prev = cur; | |
2002 | ||
2003 | /* Clear least significant set bit. */ | |
2004 | mask &= ~(mask & (~mask + 1)); | |
2005 | if (!mask) | |
2006 | return ptr; | |
2007 | cur = alloc_record (gr_gr); | |
2008 | cur->r.record.p.grmask = mask; | |
2009 | /* Indicate this record shouldn't be output. */ | |
2010 | cur->r.record.p.r.gr = REG_NUM; | |
2011 | /* Retain only least significant bit. */ | |
2012 | prev->r.record.p.grmask ^= mask; | |
2013 | prev->r.record.p.next = cur; | |
2014 | } | |
800eeca4 JW |
2015 | } |
2016 | ||
2017 | static unw_rec_list * | |
5a49b8ac | 2018 | output_gr_mem (unsigned int mask) |
800eeca4 JW |
2019 | { |
2020 | unw_rec_list *ptr = alloc_record (gr_mem); | |
ba825241 JB |
2021 | unw_rec_list *cur = ptr; |
2022 | ||
2023 | ptr->r.record.p.grmask = mask; | |
2024 | unwind.pending_saves = &ptr->r.record.p; | |
2025 | for (;;) | |
2026 | { | |
2027 | unw_rec_list *prev = cur; | |
2028 | ||
2029 | /* Clear least significant set bit. */ | |
2030 | mask &= ~(mask & (~mask + 1)); | |
2031 | if (!mask) | |
2032 | return ptr; | |
2033 | cur = alloc_record (gr_mem); | |
2034 | cur->r.record.p.grmask = mask; | |
2035 | /* Retain only least significant bit. */ | |
2036 | prev->r.record.p.grmask ^= mask; | |
2037 | prev->r.record.p.next = cur; | |
2038 | } | |
800eeca4 JW |
2039 | } |
2040 | ||
2041 | static unw_rec_list * | |
2042 | output_br_mem (unsigned int mask) | |
2043 | { | |
2044 | unw_rec_list *ptr = alloc_record (br_mem); | |
ba825241 JB |
2045 | unw_rec_list *cur = ptr; |
2046 | ||
800eeca4 | 2047 | ptr->r.record.p.brmask = mask; |
ba825241 JB |
2048 | unwind.pending_saves = &ptr->r.record.p; |
2049 | for (;;) | |
2050 | { | |
2051 | unw_rec_list *prev = cur; | |
2052 | ||
2053 | /* Clear least significant set bit. */ | |
2054 | mask &= ~(mask & (~mask + 1)); | |
2055 | if (!mask) | |
2056 | return ptr; | |
2057 | cur = alloc_record (br_mem); | |
2058 | cur->r.record.p.brmask = mask; | |
2059 | /* Retain only least significant bit. */ | |
2060 | prev->r.record.p.brmask ^= mask; | |
2061 | prev->r.record.p.next = cur; | |
2062 | } | |
800eeca4 JW |
2063 | } |
2064 | ||
2065 | static unw_rec_list * | |
5a49b8ac | 2066 | output_br_gr (unsigned int mask, unsigned int reg) |
800eeca4 JW |
2067 | { |
2068 | unw_rec_list *ptr = alloc_record (br_gr); | |
ba825241 JB |
2069 | unw_rec_list *cur = ptr; |
2070 | ||
2071 | ptr->r.record.p.brmask = mask; | |
2072 | ptr->r.record.p.r.gr = reg; | |
2073 | unwind.pending_saves = &ptr->r.record.p; | |
2074 | for (;;) | |
2075 | { | |
2076 | unw_rec_list *prev = cur; | |
2077 | ||
2078 | /* Clear least significant set bit. */ | |
2079 | mask &= ~(mask & (~mask + 1)); | |
2080 | if (!mask) | |
2081 | return ptr; | |
2082 | cur = alloc_record (br_gr); | |
2083 | cur->r.record.p.brmask = mask; | |
2084 | /* Indicate this record shouldn't be output. */ | |
2085 | cur->r.record.p.r.gr = REG_NUM; | |
2086 | /* Retain only least significant bit. */ | |
2087 | prev->r.record.p.brmask ^= mask; | |
2088 | prev->r.record.p.next = cur; | |
2089 | } | |
800eeca4 JW |
2090 | } |
2091 | ||
2092 | static unw_rec_list * | |
5a49b8ac | 2093 | output_spill_base (unsigned int offset) |
800eeca4 JW |
2094 | { |
2095 | unw_rec_list *ptr = alloc_record (spill_base); | |
ba825241 | 2096 | ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset); |
800eeca4 JW |
2097 | return ptr; |
2098 | } | |
2099 | ||
2100 | static unw_rec_list * | |
5a49b8ac | 2101 | output_unat_when (void) |
800eeca4 JW |
2102 | { |
2103 | unw_rec_list *ptr = alloc_record (unat_when); | |
2104 | return ptr; | |
2105 | } | |
2106 | ||
2107 | static unw_rec_list * | |
5a49b8ac | 2108 | output_unat_gr (unsigned int gr) |
800eeca4 JW |
2109 | { |
2110 | unw_rec_list *ptr = alloc_record (unat_gr); | |
ba825241 | 2111 | ptr->r.record.p.r.gr = gr; |
800eeca4 JW |
2112 | return ptr; |
2113 | } | |
2114 | ||
2115 | static unw_rec_list * | |
5a49b8ac | 2116 | output_unat_psprel (unsigned int offset) |
800eeca4 JW |
2117 | { |
2118 | unw_rec_list *ptr = alloc_record (unat_psprel); | |
ba825241 | 2119 | ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset); |
800eeca4 JW |
2120 | return ptr; |
2121 | } | |
2122 | ||
2123 | static unw_rec_list * | |
5a49b8ac | 2124 | output_unat_sprel (unsigned int offset) |
800eeca4 JW |
2125 | { |
2126 | unw_rec_list *ptr = alloc_record (unat_sprel); | |
ba825241 | 2127 | ptr->r.record.p.off.sp = offset / 4; |
800eeca4 JW |
2128 | return ptr; |
2129 | } | |
2130 | ||
2131 | static unw_rec_list * | |
5a49b8ac | 2132 | output_lc_when (void) |
800eeca4 JW |
2133 | { |
2134 | unw_rec_list *ptr = alloc_record (lc_when); | |
2135 | return ptr; | |
2136 | } | |
2137 | ||
2138 | static unw_rec_list * | |
5a49b8ac | 2139 | output_lc_gr (unsigned int gr) |
800eeca4 JW |
2140 | { |
2141 | unw_rec_list *ptr = alloc_record (lc_gr); | |
ba825241 | 2142 | ptr->r.record.p.r.gr = gr; |
800eeca4 JW |
2143 | return ptr; |
2144 | } | |
2145 | ||
2146 | static unw_rec_list * | |
5a49b8ac | 2147 | output_lc_psprel (unsigned int offset) |
800eeca4 JW |
2148 | { |
2149 | unw_rec_list *ptr = alloc_record (lc_psprel); | |
ba825241 | 2150 | ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset); |
800eeca4 JW |
2151 | return ptr; |
2152 | } | |
2153 | ||
2154 | static unw_rec_list * | |
5a49b8ac | 2155 | output_lc_sprel (unsigned int offset) |
800eeca4 JW |
2156 | { |
2157 | unw_rec_list *ptr = alloc_record (lc_sprel); | |
ba825241 | 2158 | ptr->r.record.p.off.sp = offset / 4; |
800eeca4 JW |
2159 | return ptr; |
2160 | } | |
2161 | ||
2162 | static unw_rec_list * | |
5a49b8ac | 2163 | output_fpsr_when (void) |
800eeca4 JW |
2164 | { |
2165 | unw_rec_list *ptr = alloc_record (fpsr_when); | |
2166 | return ptr; | |
2167 | } | |
2168 | ||
2169 | static unw_rec_list * | |
5a49b8ac | 2170 | output_fpsr_gr (unsigned int gr) |
800eeca4 JW |
2171 | { |
2172 | unw_rec_list *ptr = alloc_record (fpsr_gr); | |
ba825241 | 2173 | ptr->r.record.p.r.gr = gr; |
800eeca4 JW |
2174 | return ptr; |
2175 | } | |
2176 | ||
2177 | static unw_rec_list * | |
5a49b8ac | 2178 | output_fpsr_psprel (unsigned int offset) |
800eeca4 JW |
2179 | { |
2180 | unw_rec_list *ptr = alloc_record (fpsr_psprel); | |
ba825241 | 2181 | ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset); |
800eeca4 JW |
2182 | return ptr; |
2183 | } | |
2184 | ||
2185 | static unw_rec_list * | |
5a49b8ac | 2186 | output_fpsr_sprel (unsigned int offset) |
800eeca4 JW |
2187 | { |
2188 | unw_rec_list *ptr = alloc_record (fpsr_sprel); | |
ba825241 | 2189 | ptr->r.record.p.off.sp = offset / 4; |
800eeca4 JW |
2190 | return ptr; |
2191 | } | |
2192 | ||
2193 | static unw_rec_list * | |
5a49b8ac | 2194 | output_priunat_when_gr (void) |
800eeca4 JW |
2195 | { |
2196 | unw_rec_list *ptr = alloc_record (priunat_when_gr); | |
2197 | return ptr; | |
2198 | } | |
2199 | ||
2200 | static unw_rec_list * | |
5a49b8ac | 2201 | output_priunat_when_mem (void) |
800eeca4 JW |
2202 | { |
2203 | unw_rec_list *ptr = alloc_record (priunat_when_mem); | |
2204 | return ptr; | |
2205 | } | |
2206 | ||
2207 | static unw_rec_list * | |
5a49b8ac | 2208 | output_priunat_gr (unsigned int gr) |
800eeca4 JW |
2209 | { |
2210 | unw_rec_list *ptr = alloc_record (priunat_gr); | |
ba825241 | 2211 | ptr->r.record.p.r.gr = gr; |
800eeca4 JW |
2212 | return ptr; |
2213 | } | |
2214 | ||
2215 | static unw_rec_list * | |
5a49b8ac | 2216 | output_priunat_psprel (unsigned int offset) |
800eeca4 JW |
2217 | { |
2218 | unw_rec_list *ptr = alloc_record (priunat_psprel); | |
ba825241 | 2219 | ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset); |
800eeca4 JW |
2220 | return ptr; |
2221 | } | |
2222 | ||
2223 | static unw_rec_list * | |
5a49b8ac | 2224 | output_priunat_sprel (unsigned int offset) |
800eeca4 JW |
2225 | { |
2226 | unw_rec_list *ptr = alloc_record (priunat_sprel); | |
ba825241 | 2227 | ptr->r.record.p.off.sp = offset / 4; |
800eeca4 JW |
2228 | return ptr; |
2229 | } | |
2230 | ||
2231 | static unw_rec_list * | |
5a49b8ac | 2232 | output_bsp_when (void) |
800eeca4 JW |
2233 | { |
2234 | unw_rec_list *ptr = alloc_record (bsp_when); | |
2235 | return ptr; | |
2236 | } | |
2237 | ||
2238 | static unw_rec_list * | |
5a49b8ac | 2239 | output_bsp_gr (unsigned int gr) |
800eeca4 JW |
2240 | { |
2241 | unw_rec_list *ptr = alloc_record (bsp_gr); | |
ba825241 | 2242 | ptr->r.record.p.r.gr = gr; |
800eeca4 JW |
2243 | return ptr; |
2244 | } | |
2245 | ||
2246 | static unw_rec_list * | |
5a49b8ac | 2247 | output_bsp_psprel (unsigned int offset) |
800eeca4 JW |
2248 | { |
2249 | unw_rec_list *ptr = alloc_record (bsp_psprel); | |
ba825241 | 2250 | ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset); |
800eeca4 JW |
2251 | return ptr; |
2252 | } | |
2253 | ||
2254 | static unw_rec_list * | |
5a49b8ac | 2255 | output_bsp_sprel (unsigned int offset) |
800eeca4 JW |
2256 | { |
2257 | unw_rec_list *ptr = alloc_record (bsp_sprel); | |
ba825241 | 2258 | ptr->r.record.p.off.sp = offset / 4; |
800eeca4 JW |
2259 | return ptr; |
2260 | } | |
2261 | ||
2262 | static unw_rec_list * | |
5a49b8ac | 2263 | output_bspstore_when (void) |
800eeca4 JW |
2264 | { |
2265 | unw_rec_list *ptr = alloc_record (bspstore_when); | |
2266 | return ptr; | |
2267 | } | |
2268 | ||
2269 | static unw_rec_list * | |
5a49b8ac | 2270 | output_bspstore_gr (unsigned int gr) |
800eeca4 JW |
2271 | { |
2272 | unw_rec_list *ptr = alloc_record (bspstore_gr); | |
ba825241 | 2273 | ptr->r.record.p.r.gr = gr; |
800eeca4 JW |
2274 | return ptr; |
2275 | } | |
2276 | ||
2277 | static unw_rec_list * | |
5a49b8ac | 2278 | output_bspstore_psprel (unsigned int offset) |
800eeca4 JW |
2279 | { |
2280 | unw_rec_list *ptr = alloc_record (bspstore_psprel); | |
ba825241 | 2281 | ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset); |
800eeca4 JW |
2282 | return ptr; |
2283 | } | |
2284 | ||
2285 | static unw_rec_list * | |
5a49b8ac | 2286 | output_bspstore_sprel (unsigned int offset) |
800eeca4 JW |
2287 | { |
2288 | unw_rec_list *ptr = alloc_record (bspstore_sprel); | |
ba825241 | 2289 | ptr->r.record.p.off.sp = offset / 4; |
800eeca4 JW |
2290 | return ptr; |
2291 | } | |
2292 | ||
2293 | static unw_rec_list * | |
5a49b8ac | 2294 | output_rnat_when (void) |
800eeca4 JW |
2295 | { |
2296 | unw_rec_list *ptr = alloc_record (rnat_when); | |
2297 | return ptr; | |
2298 | } | |
2299 | ||
2300 | static unw_rec_list * | |
5a49b8ac | 2301 | output_rnat_gr (unsigned int gr) |
800eeca4 JW |
2302 | { |
2303 | unw_rec_list *ptr = alloc_record (rnat_gr); | |
ba825241 | 2304 | ptr->r.record.p.r.gr = gr; |
800eeca4 JW |
2305 | return ptr; |
2306 | } | |
2307 | ||
2308 | static unw_rec_list * | |
5a49b8ac | 2309 | output_rnat_psprel (unsigned int offset) |
800eeca4 JW |
2310 | { |
2311 | unw_rec_list *ptr = alloc_record (rnat_psprel); | |
ba825241 | 2312 | ptr->r.record.p.off.psp = ENCODED_PSP_OFFSET (offset); |
800eeca4 JW |
2313 | return ptr; |
2314 | } | |
2315 | ||
2316 | static unw_rec_list * | |
5a49b8ac | 2317 | output_rnat_sprel (unsigned int offset) |
800eeca4 JW |
2318 | { |
2319 | unw_rec_list *ptr = alloc_record (rnat_sprel); | |
ba825241 | 2320 | ptr->r.record.p.off.sp = offset / 4; |
800eeca4 JW |
2321 | return ptr; |
2322 | } | |
2323 | ||
2324 | static unw_rec_list * | |
5a49b8ac | 2325 | output_unwabi (unsigned long abi, unsigned long context) |
800eeca4 | 2326 | { |
e0c9811a JW |
2327 | unw_rec_list *ptr = alloc_record (unwabi); |
2328 | ptr->r.record.p.abi = abi; | |
2329 | ptr->r.record.p.context = context; | |
800eeca4 JW |
2330 | return ptr; |
2331 | } | |
2332 | ||
2333 | static unw_rec_list * | |
e0c9811a | 2334 | output_epilogue (unsigned long ecount) |
800eeca4 | 2335 | { |
e0c9811a JW |
2336 | unw_rec_list *ptr = alloc_record (epilogue); |
2337 | ptr->r.record.b.ecount = ecount; | |
800eeca4 JW |
2338 | return ptr; |
2339 | } | |
2340 | ||
2341 | static unw_rec_list * | |
e0c9811a | 2342 | output_label_state (unsigned long label) |
800eeca4 | 2343 | { |
e0c9811a JW |
2344 | unw_rec_list *ptr = alloc_record (label_state); |
2345 | ptr->r.record.b.label = label; | |
800eeca4 JW |
2346 | return ptr; |
2347 | } | |
2348 | ||
2349 | static unw_rec_list * | |
e0c9811a JW |
2350 | output_copy_state (unsigned long label) |
2351 | { | |
2352 | unw_rec_list *ptr = alloc_record (copy_state); | |
2353 | ptr->r.record.b.label = label; | |
2354 | return ptr; | |
2355 | } | |
2356 | ||
2357 | static unw_rec_list * | |
5a49b8ac AM |
2358 | output_spill_psprel (unsigned int ab, |
2359 | unsigned int reg, | |
2360 | unsigned int offset, | |
2361 | unsigned int predicate) | |
800eeca4 | 2362 | { |
e4e8248d | 2363 | unw_rec_list *ptr = alloc_record (predicate ? spill_psprel_p : spill_psprel); |
e0c9811a | 2364 | ptr->r.record.x.ab = ab; |
800eeca4 | 2365 | ptr->r.record.x.reg = reg; |
ba825241 | 2366 | ptr->r.record.x.where.pspoff = ENCODED_PSP_OFFSET (offset); |
800eeca4 JW |
2367 | ptr->r.record.x.qp = predicate; |
2368 | return ptr; | |
2369 | } | |
2370 | ||
2371 | static unw_rec_list * | |
5a49b8ac AM |
2372 | output_spill_sprel (unsigned int ab, |
2373 | unsigned int reg, | |
2374 | unsigned int offset, | |
2375 | unsigned int predicate) | |
800eeca4 | 2376 | { |
e4e8248d | 2377 | unw_rec_list *ptr = alloc_record (predicate ? spill_sprel_p : spill_sprel); |
e0c9811a | 2378 | ptr->r.record.x.ab = ab; |
800eeca4 | 2379 | ptr->r.record.x.reg = reg; |
ba825241 | 2380 | ptr->r.record.x.where.spoff = offset / 4; |
800eeca4 JW |
2381 | ptr->r.record.x.qp = predicate; |
2382 | return ptr; | |
2383 | } | |
2384 | ||
2385 | static unw_rec_list * | |
5a49b8ac AM |
2386 | output_spill_reg (unsigned int ab, |
2387 | unsigned int reg, | |
2388 | unsigned int targ_reg, | |
2389 | unsigned int xy, | |
2390 | unsigned int predicate) | |
800eeca4 | 2391 | { |
e4e8248d | 2392 | unw_rec_list *ptr = alloc_record (predicate ? spill_reg_p : spill_reg); |
e0c9811a | 2393 | ptr->r.record.x.ab = ab; |
800eeca4 | 2394 | ptr->r.record.x.reg = reg; |
ba825241 | 2395 | ptr->r.record.x.where.reg = targ_reg; |
800eeca4 JW |
2396 | ptr->r.record.x.xy = xy; |
2397 | ptr->r.record.x.qp = predicate; | |
2398 | return ptr; | |
2399 | } | |
2400 | ||
197865e8 | 2401 | /* Given a unw_rec_list process the correct format with the |
800eeca4 | 2402 | specified function. */ |
542d6675 | 2403 | |
800eeca4 | 2404 | static void |
5a49b8ac | 2405 | process_one_record (unw_rec_list *ptr, vbyte_func f) |
800eeca4 | 2406 | { |
ba825241 | 2407 | unsigned int fr_mask, gr_mask; |
e0c9811a | 2408 | |
197865e8 | 2409 | switch (ptr->r.type) |
800eeca4 | 2410 | { |
5738bc24 JW |
2411 | /* This is a dummy record that takes up no space in the output. */ |
2412 | case endp: | |
2413 | break; | |
2414 | ||
542d6675 KH |
2415 | case gr_mem: |
2416 | case fr_mem: | |
2417 | case br_mem: | |
2418 | case frgr_mem: | |
2419 | /* These are taken care of by prologue/prologue_gr. */ | |
2420 | break; | |
e0c9811a | 2421 | |
542d6675 KH |
2422 | case prologue_gr: |
2423 | case prologue: | |
2424 | if (ptr->r.type == prologue_gr) | |
2425 | output_R2_format (f, ptr->r.record.r.grmask, | |
2426 | ptr->r.record.r.grsave, ptr->r.record.r.rlen); | |
2427 | else | |
800eeca4 | 2428 | output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen); |
542d6675 KH |
2429 | |
2430 | /* Output descriptor(s) for union of register spills (if any). */ | |
2431 | gr_mask = ptr->r.record.r.mask.gr_mem; | |
2432 | fr_mask = ptr->r.record.r.mask.fr_mem; | |
2433 | if (fr_mask) | |
2434 | { | |
2435 | if ((fr_mask & ~0xfUL) == 0) | |
2436 | output_P6_format (f, fr_mem, fr_mask); | |
2437 | else | |
2438 | { | |
2439 | output_P5_format (f, gr_mask, fr_mask); | |
2440 | gr_mask = 0; | |
2441 | } | |
2442 | } | |
2443 | if (gr_mask) | |
2444 | output_P6_format (f, gr_mem, gr_mask); | |
2445 | if (ptr->r.record.r.mask.br_mem) | |
2446 | output_P1_format (f, ptr->r.record.r.mask.br_mem); | |
2447 | ||
2448 | /* output imask descriptor if necessary: */ | |
2449 | if (ptr->r.record.r.mask.i) | |
2450 | output_P4_format (f, ptr->r.record.r.mask.i, | |
2451 | ptr->r.record.r.imask_size); | |
2452 | break; | |
2453 | ||
2454 | case body: | |
2455 | output_R1_format (f, ptr->r.type, ptr->r.record.r.rlen); | |
2456 | break; | |
2457 | case mem_stack_f: | |
2458 | case mem_stack_v: | |
2459 | output_P7_format (f, ptr->r.type, ptr->r.record.p.t, | |
2460 | ptr->r.record.p.size); | |
2461 | break; | |
2462 | case psp_gr: | |
2463 | case rp_gr: | |
2464 | case pfs_gr: | |
2465 | case preds_gr: | |
2466 | case unat_gr: | |
2467 | case lc_gr: | |
2468 | case fpsr_gr: | |
2469 | case priunat_gr: | |
2470 | case bsp_gr: | |
2471 | case bspstore_gr: | |
2472 | case rnat_gr: | |
ba825241 | 2473 | output_P3_format (f, ptr->r.type, ptr->r.record.p.r.gr); |
542d6675 KH |
2474 | break; |
2475 | case rp_br: | |
ba825241 | 2476 | output_P3_format (f, rp_br, ptr->r.record.p.r.br); |
542d6675 KH |
2477 | break; |
2478 | case psp_sprel: | |
ba825241 | 2479 | output_P7_format (f, psp_sprel, ptr->r.record.p.off.sp, 0); |
542d6675 KH |
2480 | break; |
2481 | case rp_when: | |
2482 | case pfs_when: | |
2483 | case preds_when: | |
2484 | case unat_when: | |
2485 | case lc_when: | |
2486 | case fpsr_when: | |
2487 | output_P7_format (f, ptr->r.type, ptr->r.record.p.t, 0); | |
2488 | break; | |
2489 | case rp_psprel: | |
2490 | case pfs_psprel: | |
2491 | case preds_psprel: | |
2492 | case unat_psprel: | |
2493 | case lc_psprel: | |
2494 | case fpsr_psprel: | |
2495 | case spill_base: | |
ba825241 | 2496 | output_P7_format (f, ptr->r.type, ptr->r.record.p.off.psp, 0); |
542d6675 KH |
2497 | break; |
2498 | case rp_sprel: | |
2499 | case pfs_sprel: | |
2500 | case preds_sprel: | |
2501 | case unat_sprel: | |
2502 | case lc_sprel: | |
2503 | case fpsr_sprel: | |
2504 | case priunat_sprel: | |
2505 | case bsp_sprel: | |
2506 | case bspstore_sprel: | |
2507 | case rnat_sprel: | |
ba825241 | 2508 | output_P8_format (f, ptr->r.type, ptr->r.record.p.off.sp); |
542d6675 KH |
2509 | break; |
2510 | case gr_gr: | |
ba825241 JB |
2511 | if (ptr->r.record.p.r.gr < REG_NUM) |
2512 | { | |
2513 | const unw_rec_list *cur = ptr; | |
2514 | ||
2515 | gr_mask = cur->r.record.p.grmask; | |
2516 | while ((cur = cur->r.record.p.next) != NULL) | |
2517 | gr_mask |= cur->r.record.p.grmask; | |
2518 | output_P9_format (f, gr_mask, ptr->r.record.p.r.gr); | |
2519 | } | |
542d6675 KH |
2520 | break; |
2521 | case br_gr: | |
ba825241 JB |
2522 | if (ptr->r.record.p.r.gr < REG_NUM) |
2523 | { | |
2524 | const unw_rec_list *cur = ptr; | |
2525 | ||
2526 | gr_mask = cur->r.record.p.brmask; | |
2527 | while ((cur = cur->r.record.p.next) != NULL) | |
2528 | gr_mask |= cur->r.record.p.brmask; | |
2529 | output_P2_format (f, gr_mask, ptr->r.record.p.r.gr); | |
2530 | } | |
542d6675 KH |
2531 | break; |
2532 | case spill_mask: | |
ad4b42b4 | 2533 | as_bad (_("spill_mask record unimplemented.")); |
542d6675 KH |
2534 | break; |
2535 | case priunat_when_gr: | |
2536 | case priunat_when_mem: | |
2537 | case bsp_when: | |
2538 | case bspstore_when: | |
2539 | case rnat_when: | |
2540 | output_P8_format (f, ptr->r.type, ptr->r.record.p.t); | |
2541 | break; | |
2542 | case priunat_psprel: | |
2543 | case bsp_psprel: | |
2544 | case bspstore_psprel: | |
2545 | case rnat_psprel: | |
ba825241 | 2546 | output_P8_format (f, ptr->r.type, ptr->r.record.p.off.psp); |
542d6675 KH |
2547 | break; |
2548 | case unwabi: | |
2549 | output_P10_format (f, ptr->r.record.p.abi, ptr->r.record.p.context); | |
2550 | break; | |
2551 | case epilogue: | |
2552 | output_B3_format (f, ptr->r.record.b.ecount, ptr->r.record.b.t); | |
2553 | break; | |
2554 | case label_state: | |
2555 | case copy_state: | |
2556 | output_B4_format (f, ptr->r.type, ptr->r.record.b.label); | |
2557 | break; | |
2558 | case spill_psprel: | |
2559 | output_X1_format (f, ptr->r.type, ptr->r.record.x.ab, | |
2560 | ptr->r.record.x.reg, ptr->r.record.x.t, | |
ba825241 | 2561 | ptr->r.record.x.where.pspoff); |
542d6675 KH |
2562 | break; |
2563 | case spill_sprel: | |
2564 | output_X1_format (f, ptr->r.type, ptr->r.record.x.ab, | |
2565 | ptr->r.record.x.reg, ptr->r.record.x.t, | |
ba825241 | 2566 | ptr->r.record.x.where.spoff); |
542d6675 KH |
2567 | break; |
2568 | case spill_reg: | |
2569 | output_X2_format (f, ptr->r.record.x.ab, ptr->r.record.x.reg, | |
2570 | ptr->r.record.x.xy >> 1, ptr->r.record.x.xy, | |
ba825241 | 2571 | ptr->r.record.x.where.reg, ptr->r.record.x.t); |
542d6675 KH |
2572 | break; |
2573 | case spill_psprel_p: | |
2574 | output_X3_format (f, ptr->r.type, ptr->r.record.x.qp, | |
2575 | ptr->r.record.x.ab, ptr->r.record.x.reg, | |
ba825241 | 2576 | ptr->r.record.x.t, ptr->r.record.x.where.pspoff); |
542d6675 KH |
2577 | break; |
2578 | case spill_sprel_p: | |
2579 | output_X3_format (f, ptr->r.type, ptr->r.record.x.qp, | |
2580 | ptr->r.record.x.ab, ptr->r.record.x.reg, | |
ba825241 | 2581 | ptr->r.record.x.t, ptr->r.record.x.where.spoff); |
542d6675 KH |
2582 | break; |
2583 | case spill_reg_p: | |
2584 | output_X4_format (f, ptr->r.record.x.qp, ptr->r.record.x.ab, | |
2585 | ptr->r.record.x.reg, ptr->r.record.x.xy >> 1, | |
ba825241 | 2586 | ptr->r.record.x.xy, ptr->r.record.x.where.reg, |
542d6675 KH |
2587 | ptr->r.record.x.t); |
2588 | break; | |
2589 | default: | |
ad4b42b4 | 2590 | as_bad (_("record_type_not_valid")); |
542d6675 | 2591 | break; |
800eeca4 JW |
2592 | } |
2593 | } | |
2594 | ||
197865e8 | 2595 | /* Given a unw_rec_list list, process all the records with |
800eeca4 JW |
2596 | the specified function. */ |
2597 | static void | |
5a49b8ac | 2598 | process_unw_records (unw_rec_list *list, vbyte_func f) |
800eeca4 JW |
2599 | { |
2600 | unw_rec_list *ptr; | |
2601 | for (ptr = list; ptr; ptr = ptr->next) | |
2602 | process_one_record (ptr, f); | |
2603 | } | |
2604 | ||
2605 | /* Determine the size of a record list in bytes. */ | |
2606 | static int | |
5a49b8ac | 2607 | calc_record_size (unw_rec_list *list) |
800eeca4 JW |
2608 | { |
2609 | vbyte_count = 0; | |
2610 | process_unw_records (list, count_output); | |
2611 | return vbyte_count; | |
2612 | } | |
2613 | ||
e4e8248d JB |
2614 | /* Return the number of bits set in the input value. |
2615 | Perhaps this has a better place... */ | |
2616 | #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) | |
2617 | # define popcount __builtin_popcount | |
2618 | #else | |
2619 | static int | |
2620 | popcount (unsigned x) | |
2621 | { | |
2622 | static const unsigned char popcnt[16] = | |
2623 | { | |
2624 | 0, 1, 1, 2, | |
2625 | 1, 2, 2, 3, | |
2626 | 1, 2, 2, 3, | |
2627 | 2, 3, 3, 4 | |
2628 | }; | |
2629 | ||
2630 | if (x < NELEMS (popcnt)) | |
2631 | return popcnt[x]; | |
2632 | return popcnt[x % NELEMS (popcnt)] + popcount (x / NELEMS (popcnt)); | |
2633 | } | |
2634 | #endif | |
2635 | ||
e0c9811a JW |
2636 | /* Update IMASK bitmask to reflect the fact that one or more registers |
2637 | of type TYPE are saved starting at instruction with index T. If N | |
2638 | bits are set in REGMASK, it is assumed that instructions T through | |
2639 | T+N-1 save these registers. | |
2640 | ||
2641 | TYPE values: | |
2642 | 0: no save | |
2643 | 1: instruction saves next fp reg | |
2644 | 2: instruction saves next general reg | |
2645 | 3: instruction saves next branch reg */ | |
2646 | static void | |
5a49b8ac AM |
2647 | set_imask (unw_rec_list *region, |
2648 | unsigned long regmask, | |
2649 | unsigned long t, | |
2650 | unsigned int type) | |
e0c9811a JW |
2651 | { |
2652 | unsigned char *imask; | |
2653 | unsigned long imask_size; | |
2654 | unsigned int i; | |
2655 | int pos; | |
2656 | ||
2657 | imask = region->r.record.r.mask.i; | |
2658 | imask_size = region->r.record.r.imask_size; | |
2659 | if (!imask) | |
2660 | { | |
542d6675 | 2661 | imask_size = (region->r.record.r.rlen * 2 + 7) / 8 + 1; |
e0c9811a JW |
2662 | imask = xmalloc (imask_size); |
2663 | memset (imask, 0, imask_size); | |
2664 | ||
2665 | region->r.record.r.imask_size = imask_size; | |
2666 | region->r.record.r.mask.i = imask; | |
2667 | } | |
2668 | ||
542d6675 KH |
2669 | i = (t / 4) + 1; |
2670 | pos = 2 * (3 - t % 4); | |
e0c9811a JW |
2671 | while (regmask) |
2672 | { | |
2673 | if (i >= imask_size) | |
2674 | { | |
ad4b42b4 | 2675 | as_bad (_("Ignoring attempt to spill beyond end of region")); |
e0c9811a JW |
2676 | return; |
2677 | } | |
2678 | ||
2679 | imask[i] |= (type & 0x3) << pos; | |
197865e8 | 2680 | |
e0c9811a JW |
2681 | regmask &= (regmask - 1); |
2682 | pos -= 2; | |
2683 | if (pos < 0) | |
2684 | { | |
2685 | pos = 0; | |
2686 | ++i; | |
2687 | } | |
2688 | } | |
2689 | } | |
2690 | ||
f5a30c2e JW |
2691 | /* Return the number of instruction slots from FIRST_ADDR to SLOT_ADDR. |
2692 | SLOT_FRAG is the frag containing SLOT_ADDR, and FIRST_FRAG is the frag | |
b5e0fabd JW |
2693 | containing FIRST_ADDR. If BEFORE_RELAX, then we use worst-case estimates |
2694 | for frag sizes. */ | |
f5a30c2e | 2695 | |
5a49b8ac AM |
2696 | static unsigned long |
2697 | slot_index (unsigned long slot_addr, | |
2698 | fragS *slot_frag, | |
2699 | unsigned long first_addr, | |
2700 | fragS *first_frag, | |
2701 | int before_relax) | |
e0c9811a | 2702 | { |
91d6fa6a | 2703 | unsigned long s_index = 0; |
f5a30c2e JW |
2704 | |
2705 | /* First time we are called, the initial address and frag are invalid. */ | |
2706 | if (first_addr == 0) | |
2707 | return 0; | |
2708 | ||
2709 | /* If the two addresses are in different frags, then we need to add in | |
2710 | the remaining size of this frag, and then the entire size of intermediate | |
2711 | frags. */ | |
4dddc1d1 | 2712 | while (slot_frag != first_frag) |
f5a30c2e JW |
2713 | { |
2714 | unsigned long start_addr = (unsigned long) &first_frag->fr_literal; | |
2715 | ||
b5e0fabd | 2716 | if (! before_relax) |
73f20958 | 2717 | { |
b5e0fabd JW |
2718 | /* We can get the final addresses only during and after |
2719 | relaxation. */ | |
73f20958 | 2720 | if (first_frag->fr_next && first_frag->fr_next->fr_address) |
91d6fa6a | 2721 | s_index += 3 * ((first_frag->fr_next->fr_address |
73f20958 L |
2722 | - first_frag->fr_address |
2723 | - first_frag->fr_fix) >> 4); | |
2724 | } | |
2725 | else | |
2726 | /* We don't know what the final addresses will be. We try our | |
2727 | best to estimate. */ | |
2728 | switch (first_frag->fr_type) | |
2729 | { | |
2730 | default: | |
2731 | break; | |
2732 | ||
2733 | case rs_space: | |
ad4b42b4 | 2734 | as_fatal (_("Only constant space allocation is supported")); |
73f20958 L |
2735 | break; |
2736 | ||
2737 | case rs_align: | |
2738 | case rs_align_code: | |
2739 | case rs_align_test: | |
2740 | /* Take alignment into account. Assume the worst case | |
2741 | before relaxation. */ | |
91d6fa6a | 2742 | s_index += 3 * ((1 << first_frag->fr_offset) >> 4); |
73f20958 L |
2743 | break; |
2744 | ||
2745 | case rs_org: | |
2746 | if (first_frag->fr_symbol) | |
2747 | { | |
ad4b42b4 | 2748 | as_fatal (_("Only constant offsets are supported")); |
73f20958 L |
2749 | break; |
2750 | } | |
2751 | case rs_fill: | |
91d6fa6a | 2752 | s_index += 3 * (first_frag->fr_offset >> 4); |
73f20958 L |
2753 | break; |
2754 | } | |
2755 | ||
f5a30c2e | 2756 | /* Add in the full size of the frag converted to instruction slots. */ |
91d6fa6a | 2757 | s_index += 3 * (first_frag->fr_fix >> 4); |
f5a30c2e | 2758 | /* Subtract away the initial part before first_addr. */ |
91d6fa6a | 2759 | s_index -= (3 * ((first_addr >> 4) - (start_addr >> 4)) |
f5a30c2e | 2760 | + ((first_addr & 0x3) - (start_addr & 0x3))); |
e0c9811a | 2761 | |
f5a30c2e JW |
2762 | /* Move to the beginning of the next frag. */ |
2763 | first_frag = first_frag->fr_next; | |
2764 | first_addr = (unsigned long) &first_frag->fr_literal; | |
4dddc1d1 JW |
2765 | |
2766 | /* This can happen if there is section switching in the middle of a | |
cb3b8d91 JW |
2767 | function, causing the frag chain for the function to be broken. |
2768 | It is too difficult to recover safely from this problem, so we just | |
2769 | exit with an error. */ | |
4dddc1d1 | 2770 | if (first_frag == NULL) |
ad4b42b4 | 2771 | as_fatal (_("Section switching in code is not supported.")); |
f5a30c2e JW |
2772 | } |
2773 | ||
2774 | /* Add in the used part of the last frag. */ | |
91d6fa6a | 2775 | s_index += (3 * ((slot_addr >> 4) - (first_addr >> 4)) |
f5a30c2e | 2776 | + ((slot_addr & 0x3) - (first_addr & 0x3))); |
91d6fa6a | 2777 | return s_index; |
f5a30c2e | 2778 | } |
4a1805b1 | 2779 | |
91a2ae2a RH |
2780 | /* Optimize unwind record directives. */ |
2781 | ||
2782 | static unw_rec_list * | |
5a49b8ac | 2783 | optimize_unw_records (unw_rec_list *list) |
91a2ae2a RH |
2784 | { |
2785 | if (!list) | |
2786 | return NULL; | |
2787 | ||
2788 | /* If the only unwind record is ".prologue" or ".prologue" followed | |
2789 | by ".body", then we can optimize the unwind directives away. */ | |
2790 | if (list->r.type == prologue | |
5738bc24 JW |
2791 | && (list->next->r.type == endp |
2792 | || (list->next->r.type == body && list->next->next->r.type == endp))) | |
91a2ae2a RH |
2793 | return NULL; |
2794 | ||
2795 | return list; | |
2796 | } | |
2797 | ||
800eeca4 JW |
2798 | /* Given a complete record list, process any records which have |
2799 | unresolved fields, (ie length counts for a prologue). After | |
0234cb7c | 2800 | this has been run, all necessary information should be available |
800eeca4 | 2801 | within each record to generate an image. */ |
542d6675 | 2802 | |
800eeca4 | 2803 | static void |
5a49b8ac | 2804 | fixup_unw_records (unw_rec_list *list, int before_relax) |
800eeca4 | 2805 | { |
e0c9811a JW |
2806 | unw_rec_list *ptr, *region = 0; |
2807 | unsigned long first_addr = 0, rlen = 0, t; | |
f5a30c2e | 2808 | fragS *first_frag = 0; |
e0c9811a | 2809 | |
800eeca4 JW |
2810 | for (ptr = list; ptr; ptr = ptr->next) |
2811 | { | |
2812 | if (ptr->slot_number == SLOT_NUM_NOT_SET) | |
ad4b42b4 | 2813 | as_bad (_(" Insn slot not set in unwind record.")); |
f5a30c2e | 2814 | t = slot_index (ptr->slot_number, ptr->slot_frag, |
b5e0fabd | 2815 | first_addr, first_frag, before_relax); |
800eeca4 JW |
2816 | switch (ptr->r.type) |
2817 | { | |
542d6675 KH |
2818 | case prologue: |
2819 | case prologue_gr: | |
2820 | case body: | |
2821 | { | |
2822 | unw_rec_list *last; | |
5738bc24 JW |
2823 | int size; |
2824 | unsigned long last_addr = 0; | |
2825 | fragS *last_frag = NULL; | |
542d6675 KH |
2826 | |
2827 | first_addr = ptr->slot_number; | |
f5a30c2e | 2828 | first_frag = ptr->slot_frag; |
542d6675 | 2829 | /* Find either the next body/prologue start, or the end of |
5738bc24 | 2830 | the function, and determine the size of the region. */ |
542d6675 KH |
2831 | for (last = ptr->next; last != NULL; last = last->next) |
2832 | if (last->r.type == prologue || last->r.type == prologue_gr | |
5738bc24 | 2833 | || last->r.type == body || last->r.type == endp) |
542d6675 KH |
2834 | { |
2835 | last_addr = last->slot_number; | |
f5a30c2e | 2836 | last_frag = last->slot_frag; |
542d6675 KH |
2837 | break; |
2838 | } | |
b5e0fabd JW |
2839 | size = slot_index (last_addr, last_frag, first_addr, first_frag, |
2840 | before_relax); | |
542d6675 | 2841 | rlen = ptr->r.record.r.rlen = size; |
1e16b528 AS |
2842 | if (ptr->r.type == body) |
2843 | /* End of region. */ | |
2844 | region = 0; | |
2845 | else | |
2846 | region = ptr; | |
e0c9811a | 2847 | break; |
542d6675 KH |
2848 | } |
2849 | case epilogue: | |
ed7af9f9 L |
2850 | if (t < rlen) |
2851 | ptr->r.record.b.t = rlen - 1 - t; | |
2852 | else | |
2853 | /* This happens when a memory-stack-less procedure uses a | |
2854 | ".restore sp" directive at the end of a region to pop | |
2855 | the frame state. */ | |
2856 | ptr->r.record.b.t = 0; | |
542d6675 | 2857 | break; |
e0c9811a | 2858 | |
542d6675 KH |
2859 | case mem_stack_f: |
2860 | case mem_stack_v: | |
2861 | case rp_when: | |
2862 | case pfs_when: | |
2863 | case preds_when: | |
2864 | case unat_when: | |
2865 | case lc_when: | |
2866 | case fpsr_when: | |
2867 | case priunat_when_gr: | |
2868 | case priunat_when_mem: | |
2869 | case bsp_when: | |
2870 | case bspstore_when: | |
2871 | case rnat_when: | |
2872 | ptr->r.record.p.t = t; | |
2873 | break; | |
e0c9811a | 2874 | |
542d6675 KH |
2875 | case spill_reg: |
2876 | case spill_sprel: | |
2877 | case spill_psprel: | |
2878 | case spill_reg_p: | |
2879 | case spill_sprel_p: | |
2880 | case spill_psprel_p: | |
2881 | ptr->r.record.x.t = t; | |
2882 | break; | |
e0c9811a | 2883 | |
542d6675 KH |
2884 | case frgr_mem: |
2885 | if (!region) | |
2886 | { | |
ad4b42b4 | 2887 | as_bad (_("frgr_mem record before region record!")); |
542d6675 KH |
2888 | return; |
2889 | } | |
2890 | region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask; | |
2891 | region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask; | |
2892 | set_imask (region, ptr->r.record.p.frmask, t, 1); | |
2893 | set_imask (region, ptr->r.record.p.grmask, t, 2); | |
2894 | break; | |
2895 | case fr_mem: | |
2896 | if (!region) | |
2897 | { | |
ad4b42b4 | 2898 | as_bad (_("fr_mem record before region record!")); |
542d6675 KH |
2899 | return; |
2900 | } | |
ba825241 JB |
2901 | region->r.record.r.mask.fr_mem |= ptr->r.record.p.frmask; |
2902 | set_imask (region, ptr->r.record.p.frmask, t, 1); | |
542d6675 KH |
2903 | break; |
2904 | case gr_mem: | |
2905 | if (!region) | |
2906 | { | |
ad4b42b4 | 2907 | as_bad (_("gr_mem record before region record!")); |
542d6675 KH |
2908 | return; |
2909 | } | |
ba825241 JB |
2910 | region->r.record.r.mask.gr_mem |= ptr->r.record.p.grmask; |
2911 | set_imask (region, ptr->r.record.p.grmask, t, 2); | |
542d6675 KH |
2912 | break; |
2913 | case br_mem: | |
2914 | if (!region) | |
2915 | { | |
ad4b42b4 | 2916 | as_bad (_("br_mem record before region record!")); |
542d6675 KH |
2917 | return; |
2918 | } | |
2919 | region->r.record.r.mask.br_mem |= ptr->r.record.p.brmask; | |
2920 | set_imask (region, ptr->r.record.p.brmask, t, 3); | |
2921 | break; | |
e0c9811a | 2922 | |
542d6675 KH |
2923 | case gr_gr: |
2924 | if (!region) | |
2925 | { | |
ad4b42b4 | 2926 | as_bad (_("gr_gr record before region record!")); |
542d6675 KH |
2927 | return; |
2928 | } | |
2929 | set_imask (region, ptr->r.record.p.grmask, t, 2); | |
2930 | break; | |
2931 | case br_gr: | |
2932 | if (!region) | |
2933 | { | |
ad4b42b4 | 2934 | as_bad (_("br_gr record before region record!")); |
542d6675 KH |
2935 | return; |
2936 | } | |
2937 | set_imask (region, ptr->r.record.p.brmask, t, 3); | |
2938 | break; | |
e0c9811a | 2939 | |
542d6675 KH |
2940 | default: |
2941 | break; | |
800eeca4 JW |
2942 | } |
2943 | } | |
2944 | } | |
2945 | ||
b5e0fabd JW |
2946 | /* Estimate the size of a frag before relaxing. We only have one type of frag |
2947 | to handle here, which is the unwind info frag. */ | |
2948 | ||
2949 | int | |
2950 | ia64_estimate_size_before_relax (fragS *frag, | |
2951 | asection *segtype ATTRIBUTE_UNUSED) | |
2952 | { | |
2953 | unw_rec_list *list; | |
2954 | int len, size, pad; | |
2955 | ||
2956 | /* ??? This code is identical to the first part of ia64_convert_frag. */ | |
2957 | list = (unw_rec_list *) frag->fr_opcode; | |
2958 | fixup_unw_records (list, 0); | |
2959 | ||
2960 | len = calc_record_size (list); | |
2961 | /* pad to pointer-size boundary. */ | |
2962 | pad = len % md.pointer_size; | |
2963 | if (pad != 0) | |
2964 | len += md.pointer_size - pad; | |
f7e323d5 JB |
2965 | /* Add 8 for the header. */ |
2966 | size = len + 8; | |
2967 | /* Add a pointer for the personality offset. */ | |
2968 | if (frag->fr_offset) | |
2969 | size += md.pointer_size; | |
b5e0fabd JW |
2970 | |
2971 | /* fr_var carries the max_chars that we created the fragment with. | |
2972 | We must, of course, have allocated enough memory earlier. */ | |
9c2799c2 | 2973 | gas_assert (frag->fr_var >= size); |
b5e0fabd JW |
2974 | |
2975 | return frag->fr_fix + size; | |
2976 | } | |
2977 | ||
73f20958 | 2978 | /* This function converts a rs_machine_dependent variant frag into a |
9aff4b7a | 2979 | normal fill frag with the unwind image from the record list. */ |
73f20958 L |
2980 | void |
2981 | ia64_convert_frag (fragS *frag) | |
557debba | 2982 | { |
73f20958 L |
2983 | unw_rec_list *list; |
2984 | int len, size, pad; | |
1cd8ff38 | 2985 | valueT flag_value; |
557debba | 2986 | |
b5e0fabd | 2987 | /* ??? This code is identical to ia64_estimate_size_before_relax. */ |
73f20958 | 2988 | list = (unw_rec_list *) frag->fr_opcode; |
b5e0fabd | 2989 | fixup_unw_records (list, 0); |
1cd8ff38 | 2990 | |
73f20958 L |
2991 | len = calc_record_size (list); |
2992 | /* pad to pointer-size boundary. */ | |
2993 | pad = len % md.pointer_size; | |
2994 | if (pad != 0) | |
2995 | len += md.pointer_size - pad; | |
f7e323d5 JB |
2996 | /* Add 8 for the header. */ |
2997 | size = len + 8; | |
2998 | /* Add a pointer for the personality offset. */ | |
2999 | if (frag->fr_offset) | |
3000 | size += md.pointer_size; | |
73f20958 L |
3001 | |
3002 | /* fr_var carries the max_chars that we created the fragment with. | |
3003 | We must, of course, have allocated enough memory earlier. */ | |
9c2799c2 | 3004 | gas_assert (frag->fr_var >= size); |
73f20958 L |
3005 | |
3006 | /* Initialize the header area. fr_offset is initialized with | |
3007 | unwind.personality_routine. */ | |
3008 | if (frag->fr_offset) | |
1cd8ff38 NC |
3009 | { |
3010 | if (md.flags & EF_IA_64_ABI64) | |
3011 | flag_value = (bfd_vma) 3 << 32; | |
3012 | else | |
3013 | /* 32-bit unwind info block. */ | |
3014 | flag_value = (bfd_vma) 0x1003 << 32; | |
3015 | } | |
3016 | else | |
3017 | flag_value = 0; | |
557debba | 3018 | |
73f20958 L |
3019 | md_number_to_chars (frag->fr_literal, |
3020 | (((bfd_vma) 1 << 48) /* Version. */ | |
3021 | | flag_value /* U & E handler flags. */ | |
3022 | | (len / md.pointer_size)), /* Length. */ | |
3023 | 8); | |
557debba | 3024 | |
73f20958 L |
3025 | /* Skip the header. */ |
3026 | vbyte_mem_ptr = frag->fr_literal + 8; | |
3027 | process_unw_records (list, output_vbyte_mem); | |
d6e78c11 JW |
3028 | |
3029 | /* Fill the padding bytes with zeros. */ | |
3030 | if (pad != 0) | |
3031 | md_number_to_chars (frag->fr_literal + len + 8 - md.pointer_size + pad, 0, | |
3032 | md.pointer_size - pad); | |
417c21b7 AO |
3033 | /* Fill the unwind personality with zeros. */ |
3034 | if (frag->fr_offset) | |
3035 | md_number_to_chars (frag->fr_literal + size - md.pointer_size, 0, | |
3036 | md.pointer_size); | |
d6e78c11 | 3037 | |
73f20958 L |
3038 | frag->fr_fix += size; |
3039 | frag->fr_type = rs_fill; | |
3040 | frag->fr_var = 0; | |
3041 | frag->fr_offset = 0; | |
800eeca4 JW |
3042 | } |
3043 | ||
e0c9811a | 3044 | static int |
5a49b8ac | 3045 | parse_predicate_and_operand (expressionS *e, unsigned *qp, const char *po) |
e4e8248d | 3046 | { |
cd42ff9c | 3047 | int sep = parse_operand_and_eval (e, ','); |
e4e8248d JB |
3048 | |
3049 | *qp = e->X_add_number - REG_P; | |
3050 | if (e->X_op != O_register || *qp > 63) | |
3051 | { | |
ad4b42b4 | 3052 | as_bad (_("First operand to .%s must be a predicate"), po); |
e4e8248d JB |
3053 | *qp = 0; |
3054 | } | |
3055 | else if (*qp == 0) | |
ad4b42b4 | 3056 | as_warn (_("Pointless use of p0 as first operand to .%s"), po); |
e4e8248d | 3057 | if (sep == ',') |
cd42ff9c | 3058 | sep = parse_operand_and_eval (e, ','); |
e4e8248d JB |
3059 | else |
3060 | e->X_op = O_absent; | |
3061 | return sep; | |
3062 | } | |
3063 | ||
3064 | static void | |
5a49b8ac AM |
3065 | convert_expr_to_ab_reg (const expressionS *e, |
3066 | unsigned int *ab, | |
3067 | unsigned int *regp, | |
3068 | const char *po, | |
3069 | int n) | |
e0c9811a | 3070 | { |
e4e8248d JB |
3071 | unsigned int reg = e->X_add_number; |
3072 | ||
3073 | *ab = *regp = 0; /* Anything valid is good here. */ | |
e0c9811a JW |
3074 | |
3075 | if (e->X_op != O_register) | |
e4e8248d | 3076 | reg = REG_GR; /* Anything invalid is good here. */ |
e0c9811a | 3077 | |
2434f565 | 3078 | if (reg >= (REG_GR + 4) && reg <= (REG_GR + 7)) |
e0c9811a JW |
3079 | { |
3080 | *ab = 0; | |
3081 | *regp = reg - REG_GR; | |
3082 | } | |
2434f565 JW |
3083 | else if ((reg >= (REG_FR + 2) && reg <= (REG_FR + 5)) |
3084 | || (reg >= (REG_FR + 16) && reg <= (REG_FR + 31))) | |
e0c9811a JW |
3085 | { |
3086 | *ab = 1; | |
3087 | *regp = reg - REG_FR; | |
3088 | } | |
2434f565 | 3089 | else if (reg >= (REG_BR + 1) && reg <= (REG_BR + 5)) |
e0c9811a JW |
3090 | { |
3091 | *ab = 2; | |
3092 | *regp = reg - REG_BR; | |
3093 | } | |
3094 | else | |
3095 | { | |
3096 | *ab = 3; | |
3097 | switch (reg) | |
3098 | { | |
3099 | case REG_PR: *regp = 0; break; | |
3100 | case REG_PSP: *regp = 1; break; | |
3101 | case REG_PRIUNAT: *regp = 2; break; | |
3102 | case REG_BR + 0: *regp = 3; break; | |
3103 | case REG_AR + AR_BSP: *regp = 4; break; | |
3104 | case REG_AR + AR_BSPSTORE: *regp = 5; break; | |
3105 | case REG_AR + AR_RNAT: *regp = 6; break; | |
3106 | case REG_AR + AR_UNAT: *regp = 7; break; | |
3107 | case REG_AR + AR_FPSR: *regp = 8; break; | |
3108 | case REG_AR + AR_PFS: *regp = 9; break; | |
3109 | case REG_AR + AR_LC: *regp = 10; break; | |
3110 | ||
3111 | default: | |
ad4b42b4 | 3112 | as_bad (_("Operand %d to .%s must be a preserved register"), n, po); |
e4e8248d | 3113 | break; |
e0c9811a JW |
3114 | } |
3115 | } | |
197865e8 | 3116 | } |
e0c9811a | 3117 | |
e4e8248d | 3118 | static void |
5a49b8ac AM |
3119 | convert_expr_to_xy_reg (const expressionS *e, |
3120 | unsigned int *xy, | |
3121 | unsigned int *regp, | |
3122 | const char *po, | |
3123 | int n) | |
e0c9811a | 3124 | { |
e4e8248d | 3125 | unsigned int reg = e->X_add_number; |
e0c9811a | 3126 | |
e4e8248d | 3127 | *xy = *regp = 0; /* Anything valid is good here. */ |
e0c9811a | 3128 | |
e4e8248d JB |
3129 | if (e->X_op != O_register) |
3130 | reg = REG_GR; /* Anything invalid is good here. */ | |
e0c9811a | 3131 | |
e4e8248d | 3132 | if (reg >= (REG_GR + 1) && reg <= (REG_GR + 127)) |
e0c9811a JW |
3133 | { |
3134 | *xy = 0; | |
3135 | *regp = reg - REG_GR; | |
3136 | } | |
e4e8248d | 3137 | else if (reg >= (REG_FR + 2) && reg <= (REG_FR + 127)) |
e0c9811a JW |
3138 | { |
3139 | *xy = 1; | |
3140 | *regp = reg - REG_FR; | |
3141 | } | |
2434f565 | 3142 | else if (reg >= REG_BR && reg <= (REG_BR + 7)) |
e0c9811a JW |
3143 | { |
3144 | *xy = 2; | |
3145 | *regp = reg - REG_BR; | |
3146 | } | |
3147 | else | |
ad4b42b4 | 3148 | as_bad (_("Operand %d to .%s must be a writable register"), n, po); |
197865e8 | 3149 | } |
e0c9811a | 3150 | |
d9201763 L |
3151 | static void |
3152 | dot_align (int arg) | |
3153 | { | |
3154 | /* The current frag is an alignment frag. */ | |
3155 | align_frag = frag_now; | |
3156 | s_align_bytes (arg); | |
3157 | } | |
3158 | ||
800eeca4 | 3159 | static void |
5a49b8ac | 3160 | dot_radix (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3161 | { |
fa30c84f JB |
3162 | char *radix; |
3163 | int ch; | |
800eeca4 JW |
3164 | |
3165 | SKIP_WHITESPACE (); | |
800eeca4 | 3166 | |
fa30c84f JB |
3167 | if (is_it_end_of_statement ()) |
3168 | return; | |
d02603dc | 3169 | ch = get_symbol_name (&radix); |
fa30c84f JB |
3170 | ia64_canonicalize_symbol_name (radix); |
3171 | if (strcasecmp (radix, "C")) | |
ad4b42b4 | 3172 | as_bad (_("Radix `%s' unsupported or invalid"), radix); |
d02603dc | 3173 | (void) restore_line_pointer (ch); |
fa30c84f | 3174 | demand_empty_rest_of_line (); |
800eeca4 JW |
3175 | } |
3176 | ||
196e8040 JW |
3177 | /* Helper function for .loc directives. If the assembler is not generating |
3178 | line number info, then we need to remember which instructions have a .loc | |
3179 | directive, and only call dwarf2_gen_line_info for those instructions. */ | |
3180 | ||
3181 | static void | |
3182 | dot_loc (int x) | |
3183 | { | |
3184 | CURR_SLOT.loc_directive_seen = 1; | |
3185 | dwarf2_directive_loc (x); | |
3186 | } | |
3187 | ||
800eeca4 JW |
3188 | /* .sbss, .bss etc. are macros that expand into ".section SECNAME". */ |
3189 | static void | |
5a49b8ac | 3190 | dot_special_section (int which) |
800eeca4 JW |
3191 | { |
3192 | set_section ((char *) special_section_name[which]); | |
3193 | } | |
3194 | ||
07450571 L |
3195 | /* Return -1 for warning and 0 for error. */ |
3196 | ||
3197 | static int | |
970d6792 L |
3198 | unwind_diagnostic (const char * region, const char *directive) |
3199 | { | |
3200 | if (md.unwind_check == unwind_check_warning) | |
07450571 | 3201 | { |
ad4b42b4 | 3202 | as_warn (_(".%s outside of %s"), directive, region); |
07450571 L |
3203 | return -1; |
3204 | } | |
970d6792 L |
3205 | else |
3206 | { | |
ad4b42b4 | 3207 | as_bad (_(".%s outside of %s"), directive, region); |
970d6792 | 3208 | ignore_rest_of_line (); |
07450571 | 3209 | return 0; |
970d6792 L |
3210 | } |
3211 | } | |
3212 | ||
07450571 L |
3213 | /* Return 1 if a directive is in a procedure, -1 if a directive isn't in |
3214 | a procedure but the unwind directive check is set to warning, 0 if | |
3215 | a directive isn't in a procedure and the unwind directive check is set | |
3216 | to error. */ | |
3217 | ||
75e09913 JB |
3218 | static int |
3219 | in_procedure (const char *directive) | |
3220 | { | |
5656b6b8 | 3221 | if (unwind.proc_pending.sym |
75e09913 JB |
3222 | && (!unwind.saved_text_seg || strcmp (directive, "endp") == 0)) |
3223 | return 1; | |
07450571 | 3224 | return unwind_diagnostic ("procedure", directive); |
75e09913 JB |
3225 | } |
3226 | ||
07450571 L |
3227 | /* Return 1 if a directive is in a prologue, -1 if a directive isn't in |
3228 | a prologue but the unwind directive check is set to warning, 0 if | |
3229 | a directive isn't in a prologue and the unwind directive check is set | |
3230 | to error. */ | |
3231 | ||
75e09913 JB |
3232 | static int |
3233 | in_prologue (const char *directive) | |
3234 | { | |
07450571 | 3235 | int in = in_procedure (directive); |
ba825241 JB |
3236 | |
3237 | if (in > 0 && !unwind.prologue) | |
3238 | in = unwind_diagnostic ("prologue", directive); | |
3239 | check_pending_save (); | |
3240 | return in; | |
75e09913 JB |
3241 | } |
3242 | ||
07450571 L |
3243 | /* Return 1 if a directive is in a body, -1 if a directive isn't in |
3244 | a body but the unwind directive check is set to warning, 0 if | |
3245 | a directive isn't in a body and the unwind directive check is set | |
3246 | to error. */ | |
3247 | ||
75e09913 JB |
3248 | static int |
3249 | in_body (const char *directive) | |
3250 | { | |
07450571 | 3251 | int in = in_procedure (directive); |
ba825241 JB |
3252 | |
3253 | if (in > 0 && !unwind.body) | |
3254 | in = unwind_diagnostic ("body region", directive); | |
3255 | return in; | |
75e09913 JB |
3256 | } |
3257 | ||
800eeca4 | 3258 | static void |
5a49b8ac | 3259 | add_unwind_entry (unw_rec_list *ptr, int sep) |
800eeca4 | 3260 | { |
e4e8248d JB |
3261 | if (ptr) |
3262 | { | |
3263 | if (unwind.tail) | |
3264 | unwind.tail->next = ptr; | |
3265 | else | |
3266 | unwind.list = ptr; | |
3267 | unwind.tail = ptr; | |
3268 | ||
3269 | /* The current entry can in fact be a chain of unwind entries. */ | |
3270 | if (unwind.current_entry == NULL) | |
3271 | unwind.current_entry = ptr; | |
3272 | } | |
800eeca4 JW |
3273 | |
3274 | /* The current entry can in fact be a chain of unwind entries. */ | |
e0c9811a JW |
3275 | if (unwind.current_entry == NULL) |
3276 | unwind.current_entry = ptr; | |
e4e8248d JB |
3277 | |
3278 | if (sep == ',') | |
3279 | { | |
d02603dc | 3280 | char *name; |
e4e8248d JB |
3281 | /* Parse a tag permitted for the current directive. */ |
3282 | int ch; | |
3283 | ||
3284 | SKIP_WHITESPACE (); | |
d02603dc | 3285 | ch = get_symbol_name (&name); |
e4e8248d JB |
3286 | /* FIXME: For now, just issue a warning that this isn't implemented. */ |
3287 | { | |
3288 | static int warned; | |
3289 | ||
3290 | if (!warned) | |
3291 | { | |
3292 | warned = 1; | |
ad4b42b4 | 3293 | as_warn (_("Tags on unwind pseudo-ops aren't supported, yet")); |
e4e8248d JB |
3294 | } |
3295 | } | |
d02603dc | 3296 | (void) restore_line_pointer (ch); |
e4e8248d JB |
3297 | } |
3298 | if (sep != NOT_A_CHAR) | |
3299 | demand_empty_rest_of_line (); | |
800eeca4 JW |
3300 | } |
3301 | ||
197865e8 | 3302 | static void |
5a49b8ac | 3303 | dot_fframe (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
3304 | { |
3305 | expressionS e; | |
e4e8248d | 3306 | int sep; |
e0c9811a | 3307 | |
75e09913 JB |
3308 | if (!in_prologue ("fframe")) |
3309 | return; | |
3310 | ||
cd42ff9c | 3311 | sep = parse_operand_and_eval (&e, ','); |
197865e8 | 3312 | |
800eeca4 | 3313 | if (e.X_op != O_constant) |
e4e8248d | 3314 | { |
ad4b42b4 | 3315 | as_bad (_("First operand to .fframe must be a constant")); |
e4e8248d JB |
3316 | e.X_add_number = 0; |
3317 | } | |
3318 | add_unwind_entry (output_mem_stack_f (e.X_add_number), sep); | |
e0c9811a JW |
3319 | } |
3320 | ||
197865e8 | 3321 | static void |
5a49b8ac | 3322 | dot_vframe (int dummy ATTRIBUTE_UNUSED) |
e0c9811a JW |
3323 | { |
3324 | expressionS e; | |
3325 | unsigned reg; | |
e4e8248d | 3326 | int sep; |
e0c9811a | 3327 | |
75e09913 JB |
3328 | if (!in_prologue ("vframe")) |
3329 | return; | |
3330 | ||
cd42ff9c | 3331 | sep = parse_operand_and_eval (&e, ','); |
e0c9811a | 3332 | reg = e.X_add_number - REG_GR; |
e4e8248d | 3333 | if (e.X_op != O_register || reg > 127) |
800eeca4 | 3334 | { |
ad4b42b4 | 3335 | as_bad (_("First operand to .vframe must be a general register")); |
e4e8248d | 3336 | reg = 0; |
800eeca4 | 3337 | } |
e4e8248d JB |
3338 | add_unwind_entry (output_mem_stack_v (), sep); |
3339 | if (! (unwind.prologue_mask & 2)) | |
3340 | add_unwind_entry (output_psp_gr (reg), NOT_A_CHAR); | |
3341 | else if (reg != unwind.prologue_gr | |
8d3842cd | 3342 | + (unsigned) popcount (unwind.prologue_mask & -(2 << 1))) |
ad4b42b4 | 3343 | as_warn (_("Operand of .vframe contradicts .prologue")); |
800eeca4 JW |
3344 | } |
3345 | ||
197865e8 | 3346 | static void |
5a49b8ac | 3347 | dot_vframesp (int psp) |
800eeca4 | 3348 | { |
e0c9811a | 3349 | expressionS e; |
e4e8248d | 3350 | int sep; |
e0c9811a | 3351 | |
e4e8248d | 3352 | if (psp) |
ad4b42b4 | 3353 | as_warn (_(".vframepsp is meaningless, assuming .vframesp was meant")); |
e0c9811a | 3354 | |
e4e8248d | 3355 | if (!in_prologue ("vframesp")) |
75e09913 JB |
3356 | return; |
3357 | ||
cd42ff9c | 3358 | sep = parse_operand_and_eval (&e, ','); |
e4e8248d | 3359 | if (e.X_op != O_constant) |
e0c9811a | 3360 | { |
ad4b42b4 | 3361 | as_bad (_("Operand to .vframesp must be a constant (sp-relative offset)")); |
e4e8248d | 3362 | e.X_add_number = 0; |
e0c9811a | 3363 | } |
e4e8248d JB |
3364 | add_unwind_entry (output_mem_stack_v (), sep); |
3365 | add_unwind_entry (output_psp_sprel (e.X_add_number), NOT_A_CHAR); | |
800eeca4 JW |
3366 | } |
3367 | ||
197865e8 | 3368 | static void |
5a49b8ac | 3369 | dot_save (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
3370 | { |
3371 | expressionS e1, e2; | |
e4e8248d | 3372 | unsigned reg1, reg2; |
800eeca4 | 3373 | int sep; |
800eeca4 | 3374 | |
75e09913 JB |
3375 | if (!in_prologue ("save")) |
3376 | return; | |
3377 | ||
cd42ff9c | 3378 | sep = parse_operand_and_eval (&e1, ','); |
e4e8248d | 3379 | if (sep == ',') |
cd42ff9c | 3380 | sep = parse_operand_and_eval (&e2, ','); |
e4e8248d JB |
3381 | else |
3382 | e2.X_op = O_absent; | |
800eeca4 | 3383 | |
e0c9811a | 3384 | reg1 = e1.X_add_number; |
800eeca4 | 3385 | /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */ |
e4e8248d | 3386 | if (e1.X_op != O_register) |
800eeca4 | 3387 | { |
ad4b42b4 | 3388 | as_bad (_("First operand to .save not a register")); |
e4e8248d JB |
3389 | reg1 = REG_PR; /* Anything valid is good here. */ |
3390 | } | |
3391 | reg2 = e2.X_add_number - REG_GR; | |
3392 | if (e2.X_op != O_register || reg2 > 127) | |
3393 | { | |
ad4b42b4 | 3394 | as_bad (_("Second operand to .save not a valid register")); |
e4e8248d JB |
3395 | reg2 = 0; |
3396 | } | |
3397 | switch (reg1) | |
3398 | { | |
3399 | case REG_AR + AR_BSP: | |
3400 | add_unwind_entry (output_bsp_when (), sep); | |
3401 | add_unwind_entry (output_bsp_gr (reg2), NOT_A_CHAR); | |
3402 | break; | |
3403 | case REG_AR + AR_BSPSTORE: | |
3404 | add_unwind_entry (output_bspstore_when (), sep); | |
3405 | add_unwind_entry (output_bspstore_gr (reg2), NOT_A_CHAR); | |
3406 | break; | |
3407 | case REG_AR + AR_RNAT: | |
3408 | add_unwind_entry (output_rnat_when (), sep); | |
3409 | add_unwind_entry (output_rnat_gr (reg2), NOT_A_CHAR); | |
3410 | break; | |
3411 | case REG_AR + AR_UNAT: | |
3412 | add_unwind_entry (output_unat_when (), sep); | |
3413 | add_unwind_entry (output_unat_gr (reg2), NOT_A_CHAR); | |
3414 | break; | |
3415 | case REG_AR + AR_FPSR: | |
3416 | add_unwind_entry (output_fpsr_when (), sep); | |
3417 | add_unwind_entry (output_fpsr_gr (reg2), NOT_A_CHAR); | |
3418 | break; | |
3419 | case REG_AR + AR_PFS: | |
3420 | add_unwind_entry (output_pfs_when (), sep); | |
3421 | if (! (unwind.prologue_mask & 4)) | |
3422 | add_unwind_entry (output_pfs_gr (reg2), NOT_A_CHAR); | |
3423 | else if (reg2 != unwind.prologue_gr | |
8d3842cd | 3424 | + (unsigned) popcount (unwind.prologue_mask & -(4 << 1))) |
ad4b42b4 | 3425 | as_warn (_("Second operand of .save contradicts .prologue")); |
e4e8248d JB |
3426 | break; |
3427 | case REG_AR + AR_LC: | |
3428 | add_unwind_entry (output_lc_when (), sep); | |
3429 | add_unwind_entry (output_lc_gr (reg2), NOT_A_CHAR); | |
3430 | break; | |
3431 | case REG_BR: | |
3432 | add_unwind_entry (output_rp_when (), sep); | |
3433 | if (! (unwind.prologue_mask & 8)) | |
3434 | add_unwind_entry (output_rp_gr (reg2), NOT_A_CHAR); | |
3435 | else if (reg2 != unwind.prologue_gr) | |
ad4b42b4 | 3436 | as_warn (_("Second operand of .save contradicts .prologue")); |
e4e8248d JB |
3437 | break; |
3438 | case REG_PR: | |
3439 | add_unwind_entry (output_preds_when (), sep); | |
3440 | if (! (unwind.prologue_mask & 1)) | |
3441 | add_unwind_entry (output_preds_gr (reg2), NOT_A_CHAR); | |
3442 | else if (reg2 != unwind.prologue_gr | |
8d3842cd | 3443 | + (unsigned) popcount (unwind.prologue_mask & -(1 << 1))) |
ad4b42b4 | 3444 | as_warn (_("Second operand of .save contradicts .prologue")); |
e4e8248d JB |
3445 | break; |
3446 | case REG_PRIUNAT: | |
3447 | add_unwind_entry (output_priunat_when_gr (), sep); | |
3448 | add_unwind_entry (output_priunat_gr (reg2), NOT_A_CHAR); | |
3449 | break; | |
3450 | default: | |
ad4b42b4 | 3451 | as_bad (_("First operand to .save not a valid register")); |
e4e8248d JB |
3452 | add_unwind_entry (NULL, sep); |
3453 | break; | |
800eeca4 | 3454 | } |
800eeca4 JW |
3455 | } |
3456 | ||
197865e8 | 3457 | static void |
5a49b8ac | 3458 | dot_restore (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3459 | { |
e4e8248d | 3460 | expressionS e1; |
33d01f33 | 3461 | unsigned long ecount; /* # of _additional_ regions to pop */ |
e0c9811a JW |
3462 | int sep; |
3463 | ||
75e09913 JB |
3464 | if (!in_body ("restore")) |
3465 | return; | |
3466 | ||
cd42ff9c | 3467 | sep = parse_operand_and_eval (&e1, ','); |
e0c9811a | 3468 | if (e1.X_op != O_register || e1.X_add_number != REG_GR + 12) |
ad4b42b4 | 3469 | as_bad (_("First operand to .restore must be stack pointer (sp)")); |
e0c9811a JW |
3470 | |
3471 | if (sep == ',') | |
3472 | { | |
e4e8248d JB |
3473 | expressionS e2; |
3474 | ||
cd42ff9c | 3475 | sep = parse_operand_and_eval (&e2, ','); |
33d01f33 | 3476 | if (e2.X_op != O_constant || e2.X_add_number < 0) |
e0c9811a | 3477 | { |
ad4b42b4 | 3478 | as_bad (_("Second operand to .restore must be a constant >= 0")); |
e4e8248d | 3479 | e2.X_add_number = 0; |
e0c9811a | 3480 | } |
33d01f33 | 3481 | ecount = e2.X_add_number; |
e0c9811a | 3482 | } |
33d01f33 JW |
3483 | else |
3484 | ecount = unwind.prologue_count - 1; | |
6290819d NC |
3485 | |
3486 | if (ecount >= unwind.prologue_count) | |
3487 | { | |
ad4b42b4 | 3488 | as_bad (_("Epilogue count of %lu exceeds number of nested prologues (%u)"), |
6290819d | 3489 | ecount + 1, unwind.prologue_count); |
e4e8248d | 3490 | ecount = 0; |
6290819d NC |
3491 | } |
3492 | ||
e4e8248d | 3493 | add_unwind_entry (output_epilogue (ecount), sep); |
33d01f33 JW |
3494 | |
3495 | if (ecount < unwind.prologue_count) | |
3496 | unwind.prologue_count -= ecount + 1; | |
3497 | else | |
3498 | unwind.prologue_count = 0; | |
e0c9811a JW |
3499 | } |
3500 | ||
197865e8 | 3501 | static void |
5a49b8ac | 3502 | dot_restorereg (int pred) |
e0c9811a JW |
3503 | { |
3504 | unsigned int qp, ab, reg; | |
e4e8248d | 3505 | expressionS e; |
e0c9811a | 3506 | int sep; |
e4e8248d | 3507 | const char * const po = pred ? "restorereg.p" : "restorereg"; |
e0c9811a | 3508 | |
e4e8248d | 3509 | if (!in_procedure (po)) |
75e09913 JB |
3510 | return; |
3511 | ||
e4e8248d JB |
3512 | if (pred) |
3513 | sep = parse_predicate_and_operand (&e, &qp, po); | |
3514 | else | |
e0c9811a | 3515 | { |
cd42ff9c | 3516 | sep = parse_operand_and_eval (&e, ','); |
e4e8248d | 3517 | qp = 0; |
e0c9811a | 3518 | } |
e4e8248d | 3519 | convert_expr_to_ab_reg (&e, &ab, ®, po, 1 + pred); |
e0c9811a | 3520 | |
e4e8248d | 3521 | add_unwind_entry (output_spill_reg (ab, reg, 0, 0, qp), sep); |
800eeca4 JW |
3522 | } |
3523 | ||
f86f5863 | 3524 | static const char *special_linkonce_name[] = |
2d6ed997 L |
3525 | { |
3526 | ".gnu.linkonce.ia64unw.", ".gnu.linkonce.ia64unwi." | |
3527 | }; | |
3528 | ||
3529 | static void | |
da9f89d4 | 3530 | start_unwind_section (const segT text_seg, int sec_index) |
2d6ed997 L |
3531 | { |
3532 | /* | |
3533 | Use a slightly ugly scheme to derive the unwind section names from | |
3534 | the text section name: | |
3535 | ||
3536 | text sect. unwind table sect. | |
3537 | name: name: comments: | |
3538 | ---------- ----------------- -------------------------------- | |
3539 | .text .IA_64.unwind | |
3540 | .text.foo .IA_64.unwind.text.foo | |
3541 | .foo .IA_64.unwind.foo | |
3542 | .gnu.linkonce.t.foo | |
3543 | .gnu.linkonce.ia64unw.foo | |
3544 | _info .IA_64.unwind_info gas issues error message (ditto) | |
3545 | _infoFOO .IA_64.unwind_infoFOO gas issues error message (ditto) | |
3546 | ||
3547 | This mapping is done so that: | |
3548 | ||
3549 | (a) An object file with unwind info only in .text will use | |
3550 | unwind section names .IA_64.unwind and .IA_64.unwind_info. | |
3551 | This follows the letter of the ABI and also ensures backwards | |
3552 | compatibility with older toolchains. | |
3553 | ||
3554 | (b) An object file with unwind info in multiple text sections | |
3555 | will use separate unwind sections for each text section. | |
3556 | This allows us to properly set the "sh_info" and "sh_link" | |
3557 | fields in SHT_IA_64_UNWIND as required by the ABI and also | |
3558 | lets GNU ld support programs with multiple segments | |
3559 | containing unwind info (as might be the case for certain | |
3560 | embedded applications). | |
3561 | ||
3562 | (c) An error is issued if there would be a name clash. | |
3563 | */ | |
3564 | ||
3565 | const char *text_name, *sec_text_name; | |
3566 | char *sec_name; | |
3567 | const char *prefix = special_section_name [sec_index]; | |
3568 | const char *suffix; | |
2d6ed997 L |
3569 | |
3570 | sec_text_name = segment_name (text_seg); | |
3571 | text_name = sec_text_name; | |
3572 | if (strncmp (text_name, "_info", 5) == 0) | |
3573 | { | |
ad4b42b4 | 3574 | as_bad (_("Illegal section name `%s' (causes unwind section name clash)"), |
2d6ed997 L |
3575 | text_name); |
3576 | ignore_rest_of_line (); | |
3577 | return; | |
3578 | } | |
3579 | if (strcmp (text_name, ".text") == 0) | |
3580 | text_name = ""; | |
3581 | ||
3582 | /* Build the unwind section name by appending the (possibly stripped) | |
3583 | text section name to the unwind prefix. */ | |
3584 | suffix = text_name; | |
3585 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
3586 | sizeof (".gnu.linkonce.t.") - 1) == 0) | |
3587 | { | |
3588 | prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND]; | |
3589 | suffix += sizeof (".gnu.linkonce.t.") - 1; | |
3590 | } | |
3591 | ||
e1fa0163 | 3592 | sec_name = concat (prefix, suffix, NULL); |
2d6ed997 L |
3593 | |
3594 | /* Handle COMDAT group. */ | |
6e3f953d L |
3595 | if ((text_seg->flags & SEC_LINK_ONCE) != 0 |
3596 | && (elf_section_flags (text_seg) & SHF_GROUP) != 0) | |
2d6ed997 L |
3597 | { |
3598 | char *section; | |
2d6ed997 L |
3599 | const char *group_name = elf_group_name (text_seg); |
3600 | ||
3601 | if (group_name == NULL) | |
3602 | { | |
ad4b42b4 | 3603 | as_bad (_("Group section `%s' has no group signature"), |
2d6ed997 L |
3604 | sec_text_name); |
3605 | ignore_rest_of_line (); | |
e1fa0163 | 3606 | free (sec_name); |
2d6ed997 L |
3607 | return; |
3608 | } | |
e1fa0163 NC |
3609 | |
3610 | /* We have to construct a fake section directive. */ | |
3611 | section = concat (sec_name, ",\"aG\",@progbits,", group_name, ",comdat", NULL); | |
2d6ed997 | 3612 | set_section (section); |
e1fa0163 | 3613 | free (section); |
2d6ed997 L |
3614 | } |
3615 | else | |
3616 | { | |
3617 | set_section (sec_name); | |
3618 | bfd_set_section_flags (stdoutput, now_seg, | |
3619 | SEC_LOAD | SEC_ALLOC | SEC_READONLY); | |
3620 | } | |
38ce5b11 L |
3621 | |
3622 | elf_linked_to_section (now_seg) = text_seg; | |
e1fa0163 | 3623 | free (sec_name); |
2d6ed997 L |
3624 | } |
3625 | ||
73f20958 | 3626 | static void |
2d6ed997 | 3627 | generate_unwind_image (const segT text_seg) |
800eeca4 | 3628 | { |
73f20958 L |
3629 | int size, pad; |
3630 | unw_rec_list *list; | |
800eeca4 | 3631 | |
c97b7ef6 JW |
3632 | /* Mark the end of the unwind info, so that we can compute the size of the |
3633 | last unwind region. */ | |
e4e8248d | 3634 | add_unwind_entry (output_endp (), NOT_A_CHAR); |
c97b7ef6 | 3635 | |
10850f29 JW |
3636 | /* Force out pending instructions, to make sure all unwind records have |
3637 | a valid slot_number field. */ | |
3638 | ia64_flush_insns (); | |
3639 | ||
800eeca4 | 3640 | /* Generate the unwind record. */ |
73f20958 | 3641 | list = optimize_unw_records (unwind.list); |
b5e0fabd | 3642 | fixup_unw_records (list, 1); |
73f20958 L |
3643 | size = calc_record_size (list); |
3644 | ||
3645 | if (size > 0 || unwind.force_unwind_entry) | |
3646 | { | |
3647 | unwind.force_unwind_entry = 0; | |
3648 | /* pad to pointer-size boundary. */ | |
3649 | pad = size % md.pointer_size; | |
3650 | if (pad != 0) | |
3651 | size += md.pointer_size - pad; | |
f7e323d5 JB |
3652 | /* Add 8 for the header. */ |
3653 | size += 8; | |
3654 | /* Add a pointer for the personality offset. */ | |
3655 | if (unwind.personality_routine) | |
3656 | size += md.pointer_size; | |
73f20958 | 3657 | } |
6290819d | 3658 | |
800eeca4 JW |
3659 | /* If there are unwind records, switch sections, and output the info. */ |
3660 | if (size != 0) | |
3661 | { | |
800eeca4 | 3662 | expressionS exp; |
1cd8ff38 | 3663 | bfd_reloc_code_real_type reloc; |
91a2ae2a | 3664 | |
da9f89d4 | 3665 | start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO); |
800eeca4 | 3666 | |
557debba JW |
3667 | /* Make sure the section has 4 byte alignment for ILP32 and |
3668 | 8 byte alignment for LP64. */ | |
3669 | frag_align (md.pointer_size_shift, 0, 0); | |
3670 | record_alignment (now_seg, md.pointer_size_shift); | |
5e7474a7 | 3671 | |
800eeca4 | 3672 | /* Set expression which points to start of unwind descriptor area. */ |
e0c9811a | 3673 | unwind.info = expr_build_dot (); |
3739860c | 3674 | |
73f20958 | 3675 | frag_var (rs_machine_dependent, size, size, 0, 0, |
652ca075 L |
3676 | (offsetT) (long) unwind.personality_routine, |
3677 | (char *) list); | |
91a2ae2a | 3678 | |
800eeca4 | 3679 | /* Add the personality address to the image. */ |
e0c9811a | 3680 | if (unwind.personality_routine != 0) |
542d6675 | 3681 | { |
40449e9f | 3682 | exp.X_op = O_symbol; |
e0c9811a | 3683 | exp.X_add_symbol = unwind.personality_routine; |
800eeca4 | 3684 | exp.X_add_number = 0; |
1cd8ff38 NC |
3685 | |
3686 | if (md.flags & EF_IA_64_BE) | |
3687 | { | |
3688 | if (md.flags & EF_IA_64_ABI64) | |
3689 | reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB; | |
3690 | else | |
3691 | reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB; | |
3692 | } | |
40449e9f | 3693 | else |
1cd8ff38 NC |
3694 | { |
3695 | if (md.flags & EF_IA_64_ABI64) | |
3696 | reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB; | |
3697 | else | |
3698 | reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB; | |
3699 | } | |
3700 | ||
3701 | fix_new_exp (frag_now, frag_now_fix () - md.pointer_size, | |
40449e9f | 3702 | md.pointer_size, &exp, 0, reloc); |
e0c9811a | 3703 | unwind.personality_routine = 0; |
542d6675 | 3704 | } |
800eeca4 JW |
3705 | } |
3706 | ||
6290819d | 3707 | free_saved_prologue_counts (); |
e0c9811a | 3708 | unwind.list = unwind.tail = unwind.current_entry = NULL; |
800eeca4 JW |
3709 | } |
3710 | ||
197865e8 | 3711 | static void |
5a49b8ac | 3712 | dot_handlerdata (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3713 | { |
75e09913 JB |
3714 | if (!in_procedure ("handlerdata")) |
3715 | return; | |
91a2ae2a RH |
3716 | unwind.force_unwind_entry = 1; |
3717 | ||
3718 | /* Remember which segment we're in so we can switch back after .endp */ | |
3719 | unwind.saved_text_seg = now_seg; | |
3720 | unwind.saved_text_subseg = now_subseg; | |
3721 | ||
3722 | /* Generate unwind info into unwind-info section and then leave that | |
3723 | section as the currently active one so dataXX directives go into | |
3724 | the language specific data area of the unwind info block. */ | |
2d6ed997 | 3725 | generate_unwind_image (now_seg); |
e0c9811a | 3726 | demand_empty_rest_of_line (); |
800eeca4 JW |
3727 | } |
3728 | ||
197865e8 | 3729 | static void |
5a49b8ac | 3730 | dot_unwentry (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3731 | { |
75e09913 JB |
3732 | if (!in_procedure ("unwentry")) |
3733 | return; | |
91a2ae2a | 3734 | unwind.force_unwind_entry = 1; |
e0c9811a | 3735 | demand_empty_rest_of_line (); |
800eeca4 JW |
3736 | } |
3737 | ||
197865e8 | 3738 | static void |
5a49b8ac | 3739 | dot_altrp (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3740 | { |
e0c9811a JW |
3741 | expressionS e; |
3742 | unsigned reg; | |
3743 | ||
75e09913 JB |
3744 | if (!in_prologue ("altrp")) |
3745 | return; | |
3746 | ||
cd42ff9c | 3747 | parse_operand_and_eval (&e, 0); |
e0c9811a | 3748 | reg = e.X_add_number - REG_BR; |
e4e8248d JB |
3749 | if (e.X_op != O_register || reg > 7) |
3750 | { | |
ad4b42b4 | 3751 | as_bad (_("First operand to .altrp not a valid branch register")); |
e4e8248d JB |
3752 | reg = 0; |
3753 | } | |
3754 | add_unwind_entry (output_rp_br (reg), 0); | |
800eeca4 JW |
3755 | } |
3756 | ||
197865e8 | 3757 | static void |
5a49b8ac | 3758 | dot_savemem (int psprel) |
800eeca4 JW |
3759 | { |
3760 | expressionS e1, e2; | |
3761 | int sep; | |
3762 | int reg1, val; | |
e4e8248d | 3763 | const char * const po = psprel ? "savepsp" : "savesp"; |
800eeca4 | 3764 | |
e4e8248d | 3765 | if (!in_prologue (po)) |
75e09913 JB |
3766 | return; |
3767 | ||
cd42ff9c | 3768 | sep = parse_operand_and_eval (&e1, ','); |
e4e8248d | 3769 | if (sep == ',') |
cd42ff9c | 3770 | sep = parse_operand_and_eval (&e2, ','); |
e4e8248d JB |
3771 | else |
3772 | e2.X_op = O_absent; | |
800eeca4 | 3773 | |
e0c9811a | 3774 | reg1 = e1.X_add_number; |
800eeca4 | 3775 | val = e2.X_add_number; |
197865e8 | 3776 | |
800eeca4 | 3777 | /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */ |
e4e8248d | 3778 | if (e1.X_op != O_register) |
800eeca4 | 3779 | { |
ad4b42b4 | 3780 | as_bad (_("First operand to .%s not a register"), po); |
e4e8248d JB |
3781 | reg1 = REG_PR; /* Anything valid is good here. */ |
3782 | } | |
3783 | if (e2.X_op != O_constant) | |
3784 | { | |
ad4b42b4 | 3785 | as_bad (_("Second operand to .%s not a constant"), po); |
e4e8248d JB |
3786 | val = 0; |
3787 | } | |
3788 | ||
3789 | switch (reg1) | |
3790 | { | |
3791 | case REG_AR + AR_BSP: | |
3792 | add_unwind_entry (output_bsp_when (), sep); | |
3793 | add_unwind_entry ((psprel | |
3794 | ? output_bsp_psprel | |
3795 | : output_bsp_sprel) (val), NOT_A_CHAR); | |
3796 | break; | |
3797 | case REG_AR + AR_BSPSTORE: | |
3798 | add_unwind_entry (output_bspstore_when (), sep); | |
3799 | add_unwind_entry ((psprel | |
3800 | ? output_bspstore_psprel | |
3801 | : output_bspstore_sprel) (val), NOT_A_CHAR); | |
3802 | break; | |
3803 | case REG_AR + AR_RNAT: | |
3804 | add_unwind_entry (output_rnat_when (), sep); | |
3805 | add_unwind_entry ((psprel | |
3806 | ? output_rnat_psprel | |
3807 | : output_rnat_sprel) (val), NOT_A_CHAR); | |
3808 | break; | |
3809 | case REG_AR + AR_UNAT: | |
3810 | add_unwind_entry (output_unat_when (), sep); | |
3811 | add_unwind_entry ((psprel | |
3812 | ? output_unat_psprel | |
3813 | : output_unat_sprel) (val), NOT_A_CHAR); | |
3814 | break; | |
3815 | case REG_AR + AR_FPSR: | |
3816 | add_unwind_entry (output_fpsr_when (), sep); | |
3817 | add_unwind_entry ((psprel | |
3818 | ? output_fpsr_psprel | |
3819 | : output_fpsr_sprel) (val), NOT_A_CHAR); | |
3820 | break; | |
3821 | case REG_AR + AR_PFS: | |
3822 | add_unwind_entry (output_pfs_when (), sep); | |
3823 | add_unwind_entry ((psprel | |
3824 | ? output_pfs_psprel | |
3825 | : output_pfs_sprel) (val), NOT_A_CHAR); | |
3826 | break; | |
3827 | case REG_AR + AR_LC: | |
3828 | add_unwind_entry (output_lc_when (), sep); | |
3829 | add_unwind_entry ((psprel | |
3830 | ? output_lc_psprel | |
3831 | : output_lc_sprel) (val), NOT_A_CHAR); | |
3832 | break; | |
3833 | case REG_BR: | |
3834 | add_unwind_entry (output_rp_when (), sep); | |
3835 | add_unwind_entry ((psprel | |
3836 | ? output_rp_psprel | |
3837 | : output_rp_sprel) (val), NOT_A_CHAR); | |
3838 | break; | |
3839 | case REG_PR: | |
3840 | add_unwind_entry (output_preds_when (), sep); | |
3841 | add_unwind_entry ((psprel | |
3842 | ? output_preds_psprel | |
3843 | : output_preds_sprel) (val), NOT_A_CHAR); | |
3844 | break; | |
3845 | case REG_PRIUNAT: | |
3846 | add_unwind_entry (output_priunat_when_mem (), sep); | |
3847 | add_unwind_entry ((psprel | |
3848 | ? output_priunat_psprel | |
3849 | : output_priunat_sprel) (val), NOT_A_CHAR); | |
3850 | break; | |
3851 | default: | |
ad4b42b4 | 3852 | as_bad (_("First operand to .%s not a valid register"), po); |
e4e8248d JB |
3853 | add_unwind_entry (NULL, sep); |
3854 | break; | |
800eeca4 | 3855 | } |
800eeca4 JW |
3856 | } |
3857 | ||
197865e8 | 3858 | static void |
5a49b8ac | 3859 | dot_saveg (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3860 | { |
e4e8248d JB |
3861 | expressionS e; |
3862 | unsigned grmask; | |
800eeca4 | 3863 | int sep; |
75e09913 JB |
3864 | |
3865 | if (!in_prologue ("save.g")) | |
3866 | return; | |
3867 | ||
cd42ff9c | 3868 | sep = parse_operand_and_eval (&e, ','); |
197865e8 | 3869 | |
e4e8248d JB |
3870 | grmask = e.X_add_number; |
3871 | if (e.X_op != O_constant | |
3872 | || e.X_add_number <= 0 | |
3873 | || e.X_add_number > 0xf) | |
800eeca4 | 3874 | { |
ad4b42b4 | 3875 | as_bad (_("First operand to .save.g must be a positive 4-bit constant")); |
e4e8248d JB |
3876 | grmask = 0; |
3877 | } | |
3878 | ||
3879 | if (sep == ',') | |
3880 | { | |
3881 | unsigned reg; | |
3882 | int n = popcount (grmask); | |
3883 | ||
cd42ff9c | 3884 | parse_operand_and_eval (&e, 0); |
e4e8248d JB |
3885 | reg = e.X_add_number - REG_GR; |
3886 | if (e.X_op != O_register || reg > 127) | |
542d6675 | 3887 | { |
ad4b42b4 | 3888 | as_bad (_("Second operand to .save.g must be a general register")); |
e4e8248d JB |
3889 | reg = 0; |
3890 | } | |
3891 | else if (reg > 128U - n) | |
3892 | { | |
ad4b42b4 | 3893 | as_bad (_("Second operand to .save.g must be the first of %d general registers"), n); |
e4e8248d | 3894 | reg = 0; |
800eeca4 | 3895 | } |
e4e8248d | 3896 | add_unwind_entry (output_gr_gr (grmask, reg), 0); |
800eeca4 | 3897 | } |
e4e8248d JB |
3898 | else |
3899 | add_unwind_entry (output_gr_mem (grmask), 0); | |
800eeca4 JW |
3900 | } |
3901 | ||
197865e8 | 3902 | static void |
5a49b8ac | 3903 | dot_savef (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3904 | { |
e4e8248d | 3905 | expressionS e; |
75e09913 JB |
3906 | |
3907 | if (!in_prologue ("save.f")) | |
3908 | return; | |
3909 | ||
cd42ff9c | 3910 | parse_operand_and_eval (&e, 0); |
197865e8 | 3911 | |
e4e8248d JB |
3912 | if (e.X_op != O_constant |
3913 | || e.X_add_number <= 0 | |
3914 | || e.X_add_number > 0xfffff) | |
3915 | { | |
ad4b42b4 | 3916 | as_bad (_("Operand to .save.f must be a positive 20-bit constant")); |
e4e8248d JB |
3917 | e.X_add_number = 0; |
3918 | } | |
3919 | add_unwind_entry (output_fr_mem (e.X_add_number), 0); | |
800eeca4 JW |
3920 | } |
3921 | ||
197865e8 | 3922 | static void |
5a49b8ac | 3923 | dot_saveb (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3924 | { |
e4e8248d JB |
3925 | expressionS e; |
3926 | unsigned brmask; | |
3927 | int sep; | |
e0c9811a | 3928 | |
75e09913 JB |
3929 | if (!in_prologue ("save.b")) |
3930 | return; | |
3931 | ||
cd42ff9c | 3932 | sep = parse_operand_and_eval (&e, ','); |
e4e8248d JB |
3933 | |
3934 | brmask = e.X_add_number; | |
3935 | if (e.X_op != O_constant | |
3936 | || e.X_add_number <= 0 | |
3937 | || e.X_add_number > 0x1f) | |
800eeca4 | 3938 | { |
ad4b42b4 | 3939 | as_bad (_("First operand to .save.b must be a positive 5-bit constant")); |
e4e8248d | 3940 | brmask = 0; |
800eeca4 | 3941 | } |
e0c9811a JW |
3942 | |
3943 | if (sep == ',') | |
3944 | { | |
e4e8248d JB |
3945 | unsigned reg; |
3946 | int n = popcount (brmask); | |
3947 | ||
cd42ff9c | 3948 | parse_operand_and_eval (&e, 0); |
e4e8248d JB |
3949 | reg = e.X_add_number - REG_GR; |
3950 | if (e.X_op != O_register || reg > 127) | |
e0c9811a | 3951 | { |
ad4b42b4 | 3952 | as_bad (_("Second operand to .save.b must be a general register")); |
e4e8248d | 3953 | reg = 0; |
e0c9811a | 3954 | } |
e4e8248d JB |
3955 | else if (reg > 128U - n) |
3956 | { | |
ad4b42b4 | 3957 | as_bad (_("Second operand to .save.b must be the first of %d general registers"), n); |
e4e8248d JB |
3958 | reg = 0; |
3959 | } | |
3960 | add_unwind_entry (output_br_gr (brmask, reg), 0); | |
e0c9811a JW |
3961 | } |
3962 | else | |
e4e8248d | 3963 | add_unwind_entry (output_br_mem (brmask), 0); |
800eeca4 JW |
3964 | } |
3965 | ||
197865e8 | 3966 | static void |
5a49b8ac | 3967 | dot_savegf (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
3968 | { |
3969 | expressionS e1, e2; | |
75e09913 JB |
3970 | |
3971 | if (!in_prologue ("save.gf")) | |
3972 | return; | |
3973 | ||
cd42ff9c AM |
3974 | if (parse_operand_and_eval (&e1, ',') == ',') |
3975 | parse_operand_and_eval (&e2, 0); | |
800eeca4 | 3976 | else |
e4e8248d JB |
3977 | e2.X_op = O_absent; |
3978 | ||
3979 | if (e1.X_op != O_constant | |
3980 | || e1.X_add_number < 0 | |
3981 | || e1.X_add_number > 0xf) | |
3982 | { | |
ad4b42b4 | 3983 | as_bad (_("First operand to .save.gf must be a non-negative 4-bit constant")); |
e4e8248d JB |
3984 | e1.X_op = O_absent; |
3985 | e1.X_add_number = 0; | |
3986 | } | |
3987 | if (e2.X_op != O_constant | |
3988 | || e2.X_add_number < 0 | |
3989 | || e2.X_add_number > 0xfffff) | |
800eeca4 | 3990 | { |
ad4b42b4 | 3991 | as_bad (_("Second operand to .save.gf must be a non-negative 20-bit constant")); |
e4e8248d JB |
3992 | e2.X_op = O_absent; |
3993 | e2.X_add_number = 0; | |
800eeca4 | 3994 | } |
e4e8248d JB |
3995 | if (e1.X_op == O_constant |
3996 | && e2.X_op == O_constant | |
3997 | && e1.X_add_number == 0 | |
3998 | && e2.X_add_number == 0) | |
ad4b42b4 | 3999 | as_bad (_("Operands to .save.gf may not be both zero")); |
e4e8248d JB |
4000 | |
4001 | add_unwind_entry (output_frgr_mem (e1.X_add_number, e2.X_add_number), 0); | |
800eeca4 JW |
4002 | } |
4003 | ||
197865e8 | 4004 | static void |
5a49b8ac | 4005 | dot_spill (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4006 | { |
4007 | expressionS e; | |
e0c9811a | 4008 | |
75e09913 JB |
4009 | if (!in_prologue ("spill")) |
4010 | return; | |
4011 | ||
cd42ff9c | 4012 | parse_operand_and_eval (&e, 0); |
197865e8 | 4013 | |
800eeca4 | 4014 | if (e.X_op != O_constant) |
800eeca4 | 4015 | { |
ad4b42b4 | 4016 | as_bad (_("Operand to .spill must be a constant")); |
e4e8248d | 4017 | e.X_add_number = 0; |
e0c9811a | 4018 | } |
e4e8248d | 4019 | add_unwind_entry (output_spill_base (e.X_add_number), 0); |
e0c9811a JW |
4020 | } |
4021 | ||
4022 | static void | |
5a49b8ac | 4023 | dot_spillreg (int pred) |
e0c9811a | 4024 | { |
2132e3a3 | 4025 | int sep; |
e4e8248d JB |
4026 | unsigned int qp, ab, xy, reg, treg; |
4027 | expressionS e; | |
4028 | const char * const po = pred ? "spillreg.p" : "spillreg"; | |
e0c9811a | 4029 | |
e4e8248d | 4030 | if (!in_procedure (po)) |
75e09913 JB |
4031 | return; |
4032 | ||
e4e8248d JB |
4033 | if (pred) |
4034 | sep = parse_predicate_and_operand (&e, &qp, po); | |
e0c9811a | 4035 | else |
e0c9811a | 4036 | { |
cd42ff9c | 4037 | sep = parse_operand_and_eval (&e, ','); |
e4e8248d | 4038 | qp = 0; |
e0c9811a | 4039 | } |
e4e8248d | 4040 | convert_expr_to_ab_reg (&e, &ab, ®, po, 1 + pred); |
e0c9811a | 4041 | |
e4e8248d | 4042 | if (sep == ',') |
cd42ff9c | 4043 | sep = parse_operand_and_eval (&e, ','); |
e4e8248d JB |
4044 | else |
4045 | e.X_op = O_absent; | |
4046 | convert_expr_to_xy_reg (&e, &xy, &treg, po, 2 + pred); | |
e0c9811a | 4047 | |
e4e8248d | 4048 | add_unwind_entry (output_spill_reg (ab, reg, treg, xy, qp), sep); |
e0c9811a JW |
4049 | } |
4050 | ||
4051 | static void | |
5a49b8ac | 4052 | dot_spillmem (int psprel) |
e0c9811a | 4053 | { |
e4e8248d JB |
4054 | expressionS e; |
4055 | int pred = (psprel < 0), sep; | |
4056 | unsigned int qp, ab, reg; | |
4057 | const char * po; | |
e0c9811a | 4058 | |
e4e8248d | 4059 | if (pred) |
e0c9811a | 4060 | { |
e4e8248d JB |
4061 | psprel = ~psprel; |
4062 | po = psprel ? "spillpsp.p" : "spillsp.p"; | |
e0c9811a | 4063 | } |
e4e8248d JB |
4064 | else |
4065 | po = psprel ? "spillpsp" : "spillsp"; | |
e0c9811a | 4066 | |
e4e8248d JB |
4067 | if (!in_procedure (po)) |
4068 | return; | |
e0c9811a | 4069 | |
e4e8248d JB |
4070 | if (pred) |
4071 | sep = parse_predicate_and_operand (&e, &qp, po); | |
4072 | else | |
e0c9811a | 4073 | { |
cd42ff9c | 4074 | sep = parse_operand_and_eval (&e, ','); |
e4e8248d | 4075 | qp = 0; |
e0c9811a | 4076 | } |
e4e8248d | 4077 | convert_expr_to_ab_reg (&e, &ab, ®, po, 1 + pred); |
e0c9811a | 4078 | |
e4e8248d | 4079 | if (sep == ',') |
cd42ff9c | 4080 | sep = parse_operand_and_eval (&e, ','); |
e4e8248d JB |
4081 | else |
4082 | e.X_op = O_absent; | |
4083 | if (e.X_op != O_constant) | |
e0c9811a | 4084 | { |
ad4b42b4 | 4085 | as_bad (_("Operand %d to .%s must be a constant"), 2 + pred, po); |
e4e8248d | 4086 | e.X_add_number = 0; |
e0c9811a JW |
4087 | } |
4088 | ||
4089 | if (psprel) | |
e4e8248d | 4090 | add_unwind_entry (output_spill_psprel (ab, reg, e.X_add_number, qp), sep); |
e0c9811a | 4091 | else |
e4e8248d | 4092 | add_unwind_entry (output_spill_sprel (ab, reg, e.X_add_number, qp), sep); |
e0c9811a JW |
4093 | } |
4094 | ||
6290819d | 4095 | static unsigned int |
5a49b8ac | 4096 | get_saved_prologue_count (unsigned long lbl) |
6290819d NC |
4097 | { |
4098 | label_prologue_count *lpc = unwind.saved_prologue_counts; | |
4099 | ||
4100 | while (lpc != NULL && lpc->label_number != lbl) | |
4101 | lpc = lpc->next; | |
4102 | ||
4103 | if (lpc != NULL) | |
4104 | return lpc->prologue_count; | |
4105 | ||
ad4b42b4 | 4106 | as_bad (_("Missing .label_state %ld"), lbl); |
6290819d NC |
4107 | return 1; |
4108 | } | |
4109 | ||
4110 | static void | |
5a49b8ac | 4111 | save_prologue_count (unsigned long lbl, unsigned int count) |
6290819d NC |
4112 | { |
4113 | label_prologue_count *lpc = unwind.saved_prologue_counts; | |
4114 | ||
4115 | while (lpc != NULL && lpc->label_number != lbl) | |
4116 | lpc = lpc->next; | |
4117 | ||
4118 | if (lpc != NULL) | |
4119 | lpc->prologue_count = count; | |
4120 | else | |
4121 | { | |
40449e9f | 4122 | label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc)); |
6290819d NC |
4123 | |
4124 | new_lpc->next = unwind.saved_prologue_counts; | |
4125 | new_lpc->label_number = lbl; | |
4126 | new_lpc->prologue_count = count; | |
4127 | unwind.saved_prologue_counts = new_lpc; | |
4128 | } | |
4129 | } | |
4130 | ||
4131 | static void | |
4132 | free_saved_prologue_counts () | |
4133 | { | |
40449e9f KH |
4134 | label_prologue_count *lpc = unwind.saved_prologue_counts; |
4135 | label_prologue_count *next; | |
6290819d NC |
4136 | |
4137 | while (lpc != NULL) | |
4138 | { | |
4139 | next = lpc->next; | |
4140 | free (lpc); | |
4141 | lpc = next; | |
4142 | } | |
4143 | ||
4144 | unwind.saved_prologue_counts = NULL; | |
4145 | } | |
4146 | ||
e0c9811a | 4147 | static void |
5a49b8ac | 4148 | dot_label_state (int dummy ATTRIBUTE_UNUSED) |
e0c9811a JW |
4149 | { |
4150 | expressionS e; | |
4151 | ||
75e09913 JB |
4152 | if (!in_body ("label_state")) |
4153 | return; | |
4154 | ||
cd42ff9c | 4155 | parse_operand_and_eval (&e, 0); |
e4e8248d JB |
4156 | if (e.X_op == O_constant) |
4157 | save_prologue_count (e.X_add_number, unwind.prologue_count); | |
4158 | else | |
e0c9811a | 4159 | { |
ad4b42b4 | 4160 | as_bad (_("Operand to .label_state must be a constant")); |
e4e8248d | 4161 | e.X_add_number = 0; |
e0c9811a | 4162 | } |
e4e8248d | 4163 | add_unwind_entry (output_label_state (e.X_add_number), 0); |
e0c9811a JW |
4164 | } |
4165 | ||
4166 | static void | |
5a49b8ac | 4167 | dot_copy_state (int dummy ATTRIBUTE_UNUSED) |
e0c9811a JW |
4168 | { |
4169 | expressionS e; | |
4170 | ||
75e09913 JB |
4171 | if (!in_body ("copy_state")) |
4172 | return; | |
4173 | ||
cd42ff9c | 4174 | parse_operand_and_eval (&e, 0); |
e4e8248d JB |
4175 | if (e.X_op == O_constant) |
4176 | unwind.prologue_count = get_saved_prologue_count (e.X_add_number); | |
4177 | else | |
e0c9811a | 4178 | { |
ad4b42b4 | 4179 | as_bad (_("Operand to .copy_state must be a constant")); |
e4e8248d | 4180 | e.X_add_number = 0; |
e0c9811a | 4181 | } |
e4e8248d | 4182 | add_unwind_entry (output_copy_state (e.X_add_number), 0); |
800eeca4 JW |
4183 | } |
4184 | ||
197865e8 | 4185 | static void |
5a49b8ac | 4186 | dot_unwabi (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 4187 | { |
e0c9811a JW |
4188 | expressionS e1, e2; |
4189 | unsigned char sep; | |
4190 | ||
e4e8248d | 4191 | if (!in_prologue ("unwabi")) |
75e09913 JB |
4192 | return; |
4193 | ||
cd42ff9c | 4194 | sep = parse_operand_and_eval (&e1, ','); |
e4e8248d | 4195 | if (sep == ',') |
cd42ff9c | 4196 | parse_operand_and_eval (&e2, 0); |
e4e8248d JB |
4197 | else |
4198 | e2.X_op = O_absent; | |
e0c9811a JW |
4199 | |
4200 | if (e1.X_op != O_constant) | |
4201 | { | |
ad4b42b4 | 4202 | as_bad (_("First operand to .unwabi must be a constant")); |
e4e8248d | 4203 | e1.X_add_number = 0; |
e0c9811a JW |
4204 | } |
4205 | ||
4206 | if (e2.X_op != O_constant) | |
4207 | { | |
ad4b42b4 | 4208 | as_bad (_("Second operand to .unwabi must be a constant")); |
e4e8248d | 4209 | e2.X_add_number = 0; |
e0c9811a JW |
4210 | } |
4211 | ||
e4e8248d | 4212 | add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number), 0); |
800eeca4 JW |
4213 | } |
4214 | ||
197865e8 | 4215 | static void |
5a49b8ac | 4216 | dot_personality (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4217 | { |
4218 | char *name, *p, c; | |
d02603dc | 4219 | |
75e09913 JB |
4220 | if (!in_procedure ("personality")) |
4221 | return; | |
800eeca4 | 4222 | SKIP_WHITESPACE (); |
d02603dc | 4223 | c = get_symbol_name (&name); |
800eeca4 | 4224 | p = input_line_pointer; |
e0c9811a | 4225 | unwind.personality_routine = symbol_find_or_make (name); |
91a2ae2a | 4226 | unwind.force_unwind_entry = 1; |
800eeca4 | 4227 | *p = c; |
d02603dc | 4228 | SKIP_WHITESPACE_AFTER_NAME (); |
800eeca4 JW |
4229 | demand_empty_rest_of_line (); |
4230 | } | |
4231 | ||
4232 | static void | |
5a49b8ac | 4233 | dot_proc (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4234 | { |
4235 | char *name, *p, c; | |
4236 | symbolS *sym; | |
5656b6b8 JB |
4237 | proc_pending *pending, *last_pending; |
4238 | ||
4239 | if (unwind.proc_pending.sym) | |
4240 | { | |
4241 | (md.unwind_check == unwind_check_warning | |
4242 | ? as_warn | |
ad4b42b4 | 4243 | : as_bad) (_("Missing .endp after previous .proc")); |
5656b6b8 JB |
4244 | while (unwind.proc_pending.next) |
4245 | { | |
4246 | pending = unwind.proc_pending.next; | |
4247 | unwind.proc_pending.next = pending->next; | |
4248 | free (pending); | |
4249 | } | |
4250 | } | |
4251 | last_pending = NULL; | |
800eeca4 | 4252 | |
e0c9811a | 4253 | /* Parse names of main and alternate entry points and mark them as |
542d6675 | 4254 | function symbols: */ |
800eeca4 JW |
4255 | while (1) |
4256 | { | |
4257 | SKIP_WHITESPACE (); | |
d02603dc | 4258 | c = get_symbol_name (&name); |
800eeca4 | 4259 | p = input_line_pointer; |
75e09913 | 4260 | if (!*name) |
ad4b42b4 | 4261 | as_bad (_("Empty argument of .proc")); |
75e09913 | 4262 | else |
542d6675 | 4263 | { |
75e09913 JB |
4264 | sym = symbol_find_or_make (name); |
4265 | if (S_IS_DEFINED (sym)) | |
ad4b42b4 | 4266 | as_bad (_("`%s' was already defined"), name); |
5656b6b8 JB |
4267 | else if (!last_pending) |
4268 | { | |
4269 | unwind.proc_pending.sym = sym; | |
4270 | last_pending = &unwind.proc_pending; | |
4271 | } | |
4272 | else | |
75e09913 | 4273 | { |
5656b6b8 JB |
4274 | pending = xmalloc (sizeof (*pending)); |
4275 | pending->sym = sym; | |
4276 | last_pending = last_pending->next = pending; | |
75e09913 JB |
4277 | } |
4278 | symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION; | |
800eeca4 | 4279 | } |
800eeca4 | 4280 | *p = c; |
d02603dc | 4281 | SKIP_WHITESPACE_AFTER_NAME (); |
800eeca4 JW |
4282 | if (*input_line_pointer != ',') |
4283 | break; | |
4284 | ++input_line_pointer; | |
4285 | } | |
5656b6b8 JB |
4286 | if (!last_pending) |
4287 | { | |
4288 | unwind.proc_pending.sym = expr_build_dot (); | |
4289 | last_pending = &unwind.proc_pending; | |
4290 | } | |
4291 | last_pending->next = NULL; | |
800eeca4 JW |
4292 | demand_empty_rest_of_line (); |
4293 | ia64_do_align (16); | |
4294 | ||
75e09913 | 4295 | unwind.prologue = 0; |
33d01f33 | 4296 | unwind.prologue_count = 0; |
75e09913 JB |
4297 | unwind.body = 0; |
4298 | unwind.insn = 0; | |
e0c9811a JW |
4299 | unwind.list = unwind.tail = unwind.current_entry = NULL; |
4300 | unwind.personality_routine = 0; | |
800eeca4 JW |
4301 | } |
4302 | ||
4303 | static void | |
5a49b8ac | 4304 | dot_body (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 4305 | { |
75e09913 JB |
4306 | if (!in_procedure ("body")) |
4307 | return; | |
4308 | if (!unwind.prologue && !unwind.body && unwind.insn) | |
ad4b42b4 | 4309 | as_warn (_("Initial .body should precede any instructions")); |
ba825241 | 4310 | check_pending_save (); |
75e09913 | 4311 | |
e0c9811a | 4312 | unwind.prologue = 0; |
30d25259 | 4313 | unwind.prologue_mask = 0; |
75e09913 | 4314 | unwind.body = 1; |
30d25259 | 4315 | |
e4e8248d | 4316 | add_unwind_entry (output_body (), 0); |
800eeca4 JW |
4317 | } |
4318 | ||
4319 | static void | |
5a49b8ac | 4320 | dot_prologue (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 4321 | { |
e4e8248d | 4322 | unsigned mask = 0, grsave = 0; |
e0c9811a | 4323 | |
75e09913 JB |
4324 | if (!in_procedure ("prologue")) |
4325 | return; | |
4326 | if (unwind.prologue) | |
4327 | { | |
ad4b42b4 | 4328 | as_bad (_(".prologue within prologue")); |
75e09913 JB |
4329 | ignore_rest_of_line (); |
4330 | return; | |
4331 | } | |
4332 | if (!unwind.body && unwind.insn) | |
ad4b42b4 | 4333 | as_warn (_("Initial .prologue should precede any instructions")); |
75e09913 | 4334 | |
e0c9811a | 4335 | if (!is_it_end_of_statement ()) |
800eeca4 | 4336 | { |
e4e8248d | 4337 | expressionS e; |
cd42ff9c | 4338 | int n, sep = parse_operand_and_eval (&e, ','); |
30d25259 | 4339 | |
e4e8248d JB |
4340 | if (e.X_op != O_constant |
4341 | || e.X_add_number < 0 | |
4342 | || e.X_add_number > 0xf) | |
ad4b42b4 | 4343 | as_bad (_("First operand to .prologue must be a positive 4-bit constant")); |
e4e8248d | 4344 | else if (e.X_add_number == 0) |
ad4b42b4 | 4345 | as_warn (_("Pointless use of zero first operand to .prologue")); |
e4e8248d JB |
4346 | else |
4347 | mask = e.X_add_number; | |
9264d325 NC |
4348 | |
4349 | n = popcount (mask); | |
30d25259 | 4350 | |
e4e8248d | 4351 | if (sep == ',') |
cd42ff9c | 4352 | parse_operand_and_eval (&e, 0); |
800eeca4 | 4353 | else |
e4e8248d | 4354 | e.X_op = O_absent; |
9264d325 | 4355 | |
e4e8248d JB |
4356 | if (e.X_op == O_constant |
4357 | && e.X_add_number >= 0 | |
4358 | && e.X_add_number < 128) | |
4359 | { | |
4360 | if (md.unwind_check == unwind_check_error) | |
ad4b42b4 | 4361 | as_warn (_("Using a constant as second operand to .prologue is deprecated")); |
e4e8248d JB |
4362 | grsave = e.X_add_number; |
4363 | } | |
4364 | else if (e.X_op != O_register | |
4365 | || (grsave = e.X_add_number - REG_GR) > 127) | |
4366 | { | |
ad4b42b4 | 4367 | as_bad (_("Second operand to .prologue must be a general register")); |
e4e8248d JB |
4368 | grsave = 0; |
4369 | } | |
4370 | else if (grsave > 128U - n) | |
4371 | { | |
ad4b42b4 | 4372 | as_bad (_("Second operand to .prologue must be the first of %d general registers"), n); |
e4e8248d JB |
4373 | grsave = 0; |
4374 | } | |
800eeca4 | 4375 | } |
e4e8248d JB |
4376 | |
4377 | if (mask) | |
4378 | add_unwind_entry (output_prologue_gr (mask, grsave), 0); | |
800eeca4 | 4379 | else |
e4e8248d | 4380 | add_unwind_entry (output_prologue (), 0); |
30d25259 RH |
4381 | |
4382 | unwind.prologue = 1; | |
4383 | unwind.prologue_mask = mask; | |
e4e8248d | 4384 | unwind.prologue_gr = grsave; |
75e09913 | 4385 | unwind.body = 0; |
33d01f33 | 4386 | ++unwind.prologue_count; |
800eeca4 JW |
4387 | } |
4388 | ||
4389 | static void | |
5a49b8ac | 4390 | dot_endp (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4391 | { |
4392 | expressionS e; | |
44f5c83a | 4393 | int bytes_per_address; |
800eeca4 JW |
4394 | long where; |
4395 | segT saved_seg; | |
4396 | subsegT saved_subseg; | |
5656b6b8 | 4397 | proc_pending *pending; |
970d6792 | 4398 | int unwind_check = md.unwind_check; |
800eeca4 | 4399 | |
970d6792 | 4400 | md.unwind_check = unwind_check_error; |
75e09913 JB |
4401 | if (!in_procedure ("endp")) |
4402 | return; | |
970d6792 | 4403 | md.unwind_check = unwind_check; |
75e09913 | 4404 | |
91a2ae2a RH |
4405 | if (unwind.saved_text_seg) |
4406 | { | |
4407 | saved_seg = unwind.saved_text_seg; | |
4408 | saved_subseg = unwind.saved_text_subseg; | |
4409 | unwind.saved_text_seg = NULL; | |
4410 | } | |
4411 | else | |
4412 | { | |
4413 | saved_seg = now_seg; | |
4414 | saved_subseg = now_subseg; | |
4415 | } | |
4416 | ||
800eeca4 | 4417 | insn_group_break (1, 0, 0); |
800eeca4 | 4418 | |
91a2ae2a RH |
4419 | /* If there wasn't a .handlerdata, we haven't generated an image yet. */ |
4420 | if (!unwind.info) | |
2d6ed997 | 4421 | generate_unwind_image (saved_seg); |
800eeca4 | 4422 | |
91a2ae2a RH |
4423 | if (unwind.info || unwind.force_unwind_entry) |
4424 | { | |
75e09913 JB |
4425 | symbolS *proc_end; |
4426 | ||
91a2ae2a | 4427 | subseg_set (md.last_text_seg, 0); |
75e09913 | 4428 | proc_end = expr_build_dot (); |
5e7474a7 | 4429 | |
da9f89d4 | 4430 | start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND); |
5e7474a7 | 4431 | |
557debba JW |
4432 | /* Make sure that section has 4 byte alignment for ILP32 and |
4433 | 8 byte alignment for LP64. */ | |
4434 | record_alignment (now_seg, md.pointer_size_shift); | |
800eeca4 | 4435 | |
557debba JW |
4436 | /* Need space for 3 pointers for procedure start, procedure end, |
4437 | and unwind info. */ | |
6baf2b51 | 4438 | memset (frag_more (3 * md.pointer_size), 0, 3 * md.pointer_size); |
557debba | 4439 | where = frag_now_fix () - (3 * md.pointer_size); |
91a2ae2a | 4440 | bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8; |
800eeca4 | 4441 | |
40449e9f | 4442 | /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */ |
91a2ae2a RH |
4443 | e.X_op = O_pseudo_fixup; |
4444 | e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym; | |
4445 | e.X_add_number = 0; | |
5656b6b8 JB |
4446 | if (!S_IS_LOCAL (unwind.proc_pending.sym) |
4447 | && S_IS_DEFINED (unwind.proc_pending.sym)) | |
4448 | e.X_add_symbol = symbol_temp_new (S_GET_SEGMENT (unwind.proc_pending.sym), | |
4449 | S_GET_VALUE (unwind.proc_pending.sym), | |
4450 | symbol_get_frag (unwind.proc_pending.sym)); | |
4600db48 | 4451 | else |
5656b6b8 | 4452 | e.X_add_symbol = unwind.proc_pending.sym; |
62ebcb5c AM |
4453 | ia64_cons_fix_new (frag_now, where, bytes_per_address, &e, |
4454 | BFD_RELOC_NONE); | |
800eeca4 | 4455 | |
800eeca4 JW |
4456 | e.X_op = O_pseudo_fixup; |
4457 | e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym; | |
4458 | e.X_add_number = 0; | |
75e09913 | 4459 | e.X_add_symbol = proc_end; |
91a2ae2a | 4460 | ia64_cons_fix_new (frag_now, where + bytes_per_address, |
62ebcb5c | 4461 | bytes_per_address, &e, BFD_RELOC_NONE); |
91a2ae2a RH |
4462 | |
4463 | if (unwind.info) | |
4464 | { | |
4465 | e.X_op = O_pseudo_fixup; | |
4466 | e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym; | |
4467 | e.X_add_number = 0; | |
4468 | e.X_add_symbol = unwind.info; | |
4469 | ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2), | |
62ebcb5c | 4470 | bytes_per_address, &e, BFD_RELOC_NONE); |
91a2ae2a | 4471 | } |
91a2ae2a | 4472 | } |
800eeca4 | 4473 | subseg_set (saved_seg, saved_subseg); |
c538998c | 4474 | |
5656b6b8 JB |
4475 | /* Set symbol sizes. */ |
4476 | pending = &unwind.proc_pending; | |
4477 | if (S_GET_NAME (pending->sym)) | |
c538998c | 4478 | { |
5656b6b8 | 4479 | do |
75e09913 | 4480 | { |
5656b6b8 JB |
4481 | symbolS *sym = pending->sym; |
4482 | ||
4483 | if (!S_IS_DEFINED (sym)) | |
ad4b42b4 | 4484 | as_bad (_("`%s' was not defined within procedure"), S_GET_NAME (sym)); |
5656b6b8 JB |
4485 | else if (S_GET_SIZE (sym) == 0 |
4486 | && symbol_get_obj (sym)->size == NULL) | |
75e09913 | 4487 | { |
75e09913 JB |
4488 | fragS *frag = symbol_get_frag (sym); |
4489 | ||
5656b6b8 | 4490 | if (frag) |
c538998c | 4491 | { |
75e09913 JB |
4492 | if (frag == frag_now && SEG_NORMAL (now_seg)) |
4493 | S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym)); | |
4494 | else | |
4495 | { | |
4496 | symbol_get_obj (sym)->size = | |
4497 | (expressionS *) xmalloc (sizeof (expressionS)); | |
4498 | symbol_get_obj (sym)->size->X_op = O_subtract; | |
4499 | symbol_get_obj (sym)->size->X_add_symbol | |
4500 | = symbol_new (FAKE_LABEL_NAME, now_seg, | |
4501 | frag_now_fix (), frag_now); | |
4502 | symbol_get_obj (sym)->size->X_op_symbol = sym; | |
4503 | symbol_get_obj (sym)->size->X_add_number = 0; | |
4504 | } | |
c538998c JJ |
4505 | } |
4506 | } | |
5656b6b8 JB |
4507 | } while ((pending = pending->next) != NULL); |
4508 | } | |
4509 | ||
4510 | /* Parse names of main and alternate entry points. */ | |
4511 | while (1) | |
4512 | { | |
4513 | char *name, *p, c; | |
4514 | ||
4515 | SKIP_WHITESPACE (); | |
d02603dc | 4516 | c = get_symbol_name (&name); |
5656b6b8 JB |
4517 | p = input_line_pointer; |
4518 | if (!*name) | |
4519 | (md.unwind_check == unwind_check_warning | |
4520 | ? as_warn | |
ad4b42b4 | 4521 | : as_bad) (_("Empty argument of .endp")); |
5656b6b8 JB |
4522 | else |
4523 | { | |
4524 | symbolS *sym = symbol_find (name); | |
4525 | ||
4526 | for (pending = &unwind.proc_pending; pending; pending = pending->next) | |
4527 | { | |
4528 | if (sym == pending->sym) | |
4529 | { | |
4530 | pending->sym = NULL; | |
4531 | break; | |
4532 | } | |
4533 | } | |
4534 | if (!sym || !pending) | |
ad4b42b4 | 4535 | as_warn (_("`%s' was not specified with previous .proc"), name); |
c538998c JJ |
4536 | } |
4537 | *p = c; | |
d02603dc | 4538 | SKIP_WHITESPACE_AFTER_NAME (); |
c538998c JJ |
4539 | if (*input_line_pointer != ',') |
4540 | break; | |
4541 | ++input_line_pointer; | |
4542 | } | |
4543 | demand_empty_rest_of_line (); | |
5656b6b8 JB |
4544 | |
4545 | /* Deliberately only checking for the main entry point here; the | |
4546 | language spec even says all arguments to .endp are ignored. */ | |
4547 | if (unwind.proc_pending.sym | |
4548 | && S_GET_NAME (unwind.proc_pending.sym) | |
4549 | && strcmp (S_GET_NAME (unwind.proc_pending.sym), FAKE_LABEL_NAME)) | |
ad4b42b4 | 4550 | as_warn (_("`%s' should be an operand to this .endp"), |
5656b6b8 JB |
4551 | S_GET_NAME (unwind.proc_pending.sym)); |
4552 | while (unwind.proc_pending.next) | |
4553 | { | |
4554 | pending = unwind.proc_pending.next; | |
4555 | unwind.proc_pending.next = pending->next; | |
4556 | free (pending); | |
4557 | } | |
4558 | unwind.proc_pending.sym = unwind.info = NULL; | |
800eeca4 JW |
4559 | } |
4560 | ||
4561 | static void | |
d3ce72d0 | 4562 | dot_template (int template_val) |
800eeca4 | 4563 | { |
d3ce72d0 | 4564 | CURR_SLOT.user_template = template_val; |
800eeca4 JW |
4565 | } |
4566 | ||
4567 | static void | |
5a49b8ac | 4568 | dot_regstk (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4569 | { |
4570 | int ins, locs, outs, rots; | |
4571 | ||
4572 | if (is_it_end_of_statement ()) | |
4573 | ins = locs = outs = rots = 0; | |
4574 | else | |
4575 | { | |
4576 | ins = get_absolute_expression (); | |
4577 | if (*input_line_pointer++ != ',') | |
4578 | goto err; | |
4579 | locs = get_absolute_expression (); | |
4580 | if (*input_line_pointer++ != ',') | |
4581 | goto err; | |
4582 | outs = get_absolute_expression (); | |
4583 | if (*input_line_pointer++ != ',') | |
4584 | goto err; | |
4585 | rots = get_absolute_expression (); | |
4586 | } | |
4587 | set_regstack (ins, locs, outs, rots); | |
4588 | return; | |
4589 | ||
4590 | err: | |
ad4b42b4 | 4591 | as_bad (_("Comma expected")); |
800eeca4 JW |
4592 | ignore_rest_of_line (); |
4593 | } | |
4594 | ||
4595 | static void | |
5a49b8ac | 4596 | dot_rot (int type) |
800eeca4 | 4597 | { |
6a2375c6 JB |
4598 | offsetT num_regs; |
4599 | valueT num_alloced = 0; | |
800eeca4 JW |
4600 | struct dynreg **drpp, *dr; |
4601 | int ch, base_reg = 0; | |
4602 | char *name, *start; | |
4603 | size_t len; | |
4604 | ||
4605 | switch (type) | |
4606 | { | |
4607 | case DYNREG_GR: base_reg = REG_GR + 32; break; | |
4608 | case DYNREG_FR: base_reg = REG_FR + 32; break; | |
4609 | case DYNREG_PR: base_reg = REG_P + 16; break; | |
4610 | default: break; | |
4611 | } | |
4612 | ||
542d6675 | 4613 | /* First, remove existing names from hash table. */ |
800eeca4 JW |
4614 | for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next) |
4615 | { | |
db0bc284 | 4616 | hash_delete (md.dynreg_hash, dr->name, FALSE); |
20b36a95 | 4617 | /* FIXME: Free dr->name. */ |
800eeca4 JW |
4618 | dr->num_regs = 0; |
4619 | } | |
4620 | ||
4621 | drpp = &md.dynreg[type]; | |
4622 | while (1) | |
4623 | { | |
d02603dc | 4624 | ch = get_symbol_name (&start); |
20b36a95 | 4625 | len = strlen (ia64_canonicalize_symbol_name (start)); |
800eeca4 | 4626 | *input_line_pointer = ch; |
800eeca4 | 4627 | |
d02603dc | 4628 | SKIP_WHITESPACE_AFTER_NAME (); |
800eeca4 JW |
4629 | if (*input_line_pointer != '[') |
4630 | { | |
ad4b42b4 | 4631 | as_bad (_("Expected '['")); |
800eeca4 JW |
4632 | goto err; |
4633 | } | |
4634 | ++input_line_pointer; /* skip '[' */ | |
4635 | ||
4636 | num_regs = get_absolute_expression (); | |
4637 | ||
4638 | if (*input_line_pointer++ != ']') | |
4639 | { | |
ad4b42b4 | 4640 | as_bad (_("Expected ']'")); |
800eeca4 JW |
4641 | goto err; |
4642 | } | |
6a2375c6 JB |
4643 | if (num_regs <= 0) |
4644 | { | |
ad4b42b4 | 4645 | as_bad (_("Number of elements must be positive")); |
6a2375c6 JB |
4646 | goto err; |
4647 | } | |
800eeca4 JW |
4648 | SKIP_WHITESPACE (); |
4649 | ||
4650 | num_alloced += num_regs; | |
4651 | switch (type) | |
4652 | { | |
4653 | case DYNREG_GR: | |
4654 | if (num_alloced > md.rot.num_regs) | |
4655 | { | |
ad4b42b4 | 4656 | as_bad (_("Used more than the declared %d rotating registers"), |
800eeca4 JW |
4657 | md.rot.num_regs); |
4658 | goto err; | |
4659 | } | |
4660 | break; | |
4661 | case DYNREG_FR: | |
4662 | if (num_alloced > 96) | |
4663 | { | |
ad4b42b4 | 4664 | as_bad (_("Used more than the available 96 rotating registers")); |
800eeca4 JW |
4665 | goto err; |
4666 | } | |
4667 | break; | |
4668 | case DYNREG_PR: | |
4669 | if (num_alloced > 48) | |
4670 | { | |
ad4b42b4 | 4671 | as_bad (_("Used more than the available 48 rotating registers")); |
800eeca4 JW |
4672 | goto err; |
4673 | } | |
4674 | break; | |
4675 | ||
4676 | default: | |
4677 | break; | |
4678 | } | |
4679 | ||
800eeca4 JW |
4680 | if (!*drpp) |
4681 | { | |
4682 | *drpp = obstack_alloc (¬es, sizeof (*dr)); | |
4683 | memset (*drpp, 0, sizeof (*dr)); | |
4684 | } | |
4685 | ||
20b36a95 JB |
4686 | name = obstack_alloc (¬es, len + 1); |
4687 | memcpy (name, start, len); | |
4688 | name[len] = '\0'; | |
4689 | ||
800eeca4 JW |
4690 | dr = *drpp; |
4691 | dr->name = name; | |
4692 | dr->num_regs = num_regs; | |
4693 | dr->base = base_reg; | |
4694 | drpp = &dr->next; | |
4695 | base_reg += num_regs; | |
4696 | ||
4697 | if (hash_insert (md.dynreg_hash, name, dr)) | |
4698 | { | |
ad4b42b4 | 4699 | as_bad (_("Attempt to redefine register set `%s'"), name); |
20b36a95 | 4700 | obstack_free (¬es, name); |
800eeca4 JW |
4701 | goto err; |
4702 | } | |
4703 | ||
4704 | if (*input_line_pointer != ',') | |
4705 | break; | |
4706 | ++input_line_pointer; /* skip comma */ | |
4707 | SKIP_WHITESPACE (); | |
4708 | } | |
4709 | demand_empty_rest_of_line (); | |
4710 | return; | |
4711 | ||
4712 | err: | |
4713 | ignore_rest_of_line (); | |
4714 | } | |
4715 | ||
4716 | static void | |
5a49b8ac | 4717 | dot_byteorder (int byteorder) |
800eeca4 | 4718 | { |
10a98291 L |
4719 | segment_info_type *seginfo = seg_info (now_seg); |
4720 | ||
4721 | if (byteorder == -1) | |
4722 | { | |
4723 | if (seginfo->tc_segment_info_data.endian == 0) | |
549f748d | 4724 | seginfo->tc_segment_info_data.endian = default_big_endian ? 1 : 2; |
10a98291 L |
4725 | byteorder = seginfo->tc_segment_info_data.endian == 1; |
4726 | } | |
4727 | else | |
4728 | seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2; | |
4729 | ||
4730 | if (target_big_endian != byteorder) | |
4731 | { | |
4732 | target_big_endian = byteorder; | |
4733 | if (target_big_endian) | |
4734 | { | |
4735 | ia64_number_to_chars = number_to_chars_bigendian; | |
4736 | ia64_float_to_chars = ia64_float_to_chars_bigendian; | |
4737 | } | |
4738 | else | |
4739 | { | |
4740 | ia64_number_to_chars = number_to_chars_littleendian; | |
4741 | ia64_float_to_chars = ia64_float_to_chars_littleendian; | |
4742 | } | |
4743 | } | |
800eeca4 JW |
4744 | } |
4745 | ||
4746 | static void | |
5a49b8ac | 4747 | dot_psr (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4748 | { |
4749 | char *option; | |
4750 | int ch; | |
4751 | ||
4752 | while (1) | |
4753 | { | |
d02603dc | 4754 | ch = get_symbol_name (&option); |
800eeca4 JW |
4755 | if (strcmp (option, "lsb") == 0) |
4756 | md.flags &= ~EF_IA_64_BE; | |
4757 | else if (strcmp (option, "msb") == 0) | |
4758 | md.flags |= EF_IA_64_BE; | |
4759 | else if (strcmp (option, "abi32") == 0) | |
4760 | md.flags &= ~EF_IA_64_ABI64; | |
4761 | else if (strcmp (option, "abi64") == 0) | |
4762 | md.flags |= EF_IA_64_ABI64; | |
4763 | else | |
ad4b42b4 | 4764 | as_bad (_("Unknown psr option `%s'"), option); |
800eeca4 JW |
4765 | *input_line_pointer = ch; |
4766 | ||
d02603dc | 4767 | SKIP_WHITESPACE_AFTER_NAME (); |
800eeca4 JW |
4768 | if (*input_line_pointer != ',') |
4769 | break; | |
4770 | ||
4771 | ++input_line_pointer; | |
4772 | SKIP_WHITESPACE (); | |
4773 | } | |
4774 | demand_empty_rest_of_line (); | |
4775 | } | |
4776 | ||
800eeca4 | 4777 | static void |
5a49b8ac | 4778 | dot_ln (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4779 | { |
4780 | new_logical_line (0, get_absolute_expression ()); | |
4781 | demand_empty_rest_of_line (); | |
4782 | } | |
4783 | ||
ef6a2b41 | 4784 | static void |
91d6fa6a | 4785 | cross_section (int ref, void (*builder) (int), int ua) |
800eeca4 | 4786 | { |
ef6a2b41 JB |
4787 | char *start, *end; |
4788 | int saved_auto_align; | |
4789 | unsigned int section_count; | |
d02603dc NC |
4790 | char *name; |
4791 | char c; | |
800eeca4 JW |
4792 | |
4793 | SKIP_WHITESPACE (); | |
ef6a2b41 | 4794 | start = input_line_pointer; |
d02603dc NC |
4795 | c = get_symbol_name (&name); |
4796 | if (input_line_pointer == start) | |
800eeca4 | 4797 | { |
d02603dc NC |
4798 | as_bad (_("Missing section name")); |
4799 | ignore_rest_of_line (); | |
4800 | return; | |
800eeca4 | 4801 | } |
d02603dc NC |
4802 | * input_line_pointer = c; |
4803 | SKIP_WHITESPACE_AFTER_NAME (); | |
ef6a2b41 | 4804 | end = input_line_pointer; |
800eeca4 JW |
4805 | if (*input_line_pointer != ',') |
4806 | { | |
ad4b42b4 | 4807 | as_bad (_("Comma expected after section name")); |
800eeca4 | 4808 | ignore_rest_of_line (); |
ef6a2b41 | 4809 | return; |
800eeca4 | 4810 | } |
ef6a2b41 JB |
4811 | *end = '\0'; |
4812 | end = input_line_pointer + 1; /* skip comma */ | |
4813 | input_line_pointer = start; | |
4814 | md.keep_pending_output = 1; | |
91d6fa6a | 4815 | section_count = bfd_count_sections (stdoutput); |
ef6a2b41 | 4816 | obj_elf_section (0); |
91d6fa6a | 4817 | if (section_count != bfd_count_sections (stdoutput)) |
ad4b42b4 | 4818 | as_warn (_("Creating sections with .xdataN/.xrealN/.xstringZ is deprecated.")); |
ef6a2b41 JB |
4819 | input_line_pointer = end; |
4820 | saved_auto_align = md.auto_align; | |
4821 | if (ua) | |
4822 | md.auto_align = 0; | |
91d6fa6a | 4823 | (*builder) (ref); |
ef6a2b41 JB |
4824 | if (ua) |
4825 | md.auto_align = saved_auto_align; | |
4826 | obj_elf_previous (0); | |
4827 | md.keep_pending_output = 0; | |
800eeca4 JW |
4828 | } |
4829 | ||
4830 | static void | |
5a49b8ac | 4831 | dot_xdata (int size) |
800eeca4 | 4832 | { |
ef6a2b41 | 4833 | cross_section (size, cons, 0); |
800eeca4 JW |
4834 | } |
4835 | ||
4836 | /* Why doesn't float_cons() call md_cons_align() the way cons() does? */ | |
542d6675 | 4837 | |
800eeca4 | 4838 | static void |
5a49b8ac | 4839 | stmt_float_cons (int kind) |
800eeca4 | 4840 | { |
165a7f90 | 4841 | size_t alignment; |
800eeca4 JW |
4842 | |
4843 | switch (kind) | |
4844 | { | |
165a7f90 L |
4845 | case 'd': |
4846 | alignment = 8; | |
4847 | break; | |
4848 | ||
4849 | case 'x': | |
4850 | case 'X': | |
4851 | alignment = 16; | |
4852 | break; | |
800eeca4 JW |
4853 | |
4854 | case 'f': | |
4855 | default: | |
165a7f90 | 4856 | alignment = 4; |
800eeca4 JW |
4857 | break; |
4858 | } | |
165a7f90 | 4859 | ia64_do_align (alignment); |
800eeca4 JW |
4860 | float_cons (kind); |
4861 | } | |
4862 | ||
4863 | static void | |
5a49b8ac | 4864 | stmt_cons_ua (int size) |
800eeca4 JW |
4865 | { |
4866 | int saved_auto_align = md.auto_align; | |
4867 | ||
4868 | md.auto_align = 0; | |
4869 | cons (size); | |
4870 | md.auto_align = saved_auto_align; | |
4871 | } | |
4872 | ||
4873 | static void | |
5a49b8ac | 4874 | dot_xfloat_cons (int kind) |
800eeca4 | 4875 | { |
ef6a2b41 | 4876 | cross_section (kind, stmt_float_cons, 0); |
800eeca4 JW |
4877 | } |
4878 | ||
4879 | static void | |
38a57ae7 | 4880 | dot_xstringer (int zero) |
800eeca4 | 4881 | { |
ef6a2b41 | 4882 | cross_section (zero, stringer, 0); |
800eeca4 JW |
4883 | } |
4884 | ||
4885 | static void | |
5a49b8ac | 4886 | dot_xdata_ua (int size) |
800eeca4 | 4887 | { |
ef6a2b41 | 4888 | cross_section (size, cons, 1); |
800eeca4 JW |
4889 | } |
4890 | ||
4891 | static void | |
5a49b8ac | 4892 | dot_xfloat_cons_ua (int kind) |
800eeca4 | 4893 | { |
ef6a2b41 | 4894 | cross_section (kind, float_cons, 1); |
800eeca4 JW |
4895 | } |
4896 | ||
4897 | /* .reg.val <regname>,value */ | |
542d6675 | 4898 | |
800eeca4 | 4899 | static void |
5a49b8ac | 4900 | dot_reg_val (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4901 | { |
4902 | expressionS reg; | |
4903 | ||
60d11e55 | 4904 | expression_and_evaluate (®); |
800eeca4 JW |
4905 | if (reg.X_op != O_register) |
4906 | { | |
4907 | as_bad (_("Register name expected")); | |
4908 | ignore_rest_of_line (); | |
4909 | } | |
4910 | else if (*input_line_pointer++ != ',') | |
4911 | { | |
4912 | as_bad (_("Comma expected")); | |
4913 | ignore_rest_of_line (); | |
4914 | } | |
197865e8 | 4915 | else |
800eeca4 JW |
4916 | { |
4917 | valueT value = get_absolute_expression (); | |
4918 | int regno = reg.X_add_number; | |
a66d2bb7 | 4919 | if (regno <= REG_GR || regno > REG_GR + 127) |
542d6675 | 4920 | as_warn (_("Register value annotation ignored")); |
800eeca4 | 4921 | else |
542d6675 KH |
4922 | { |
4923 | gr_values[regno - REG_GR].known = 1; | |
4924 | gr_values[regno - REG_GR].value = value; | |
4925 | gr_values[regno - REG_GR].path = md.path; | |
4926 | } | |
800eeca4 JW |
4927 | } |
4928 | demand_empty_rest_of_line (); | |
4929 | } | |
4930 | ||
5e819f9c JW |
4931 | /* |
4932 | .serialize.data | |
4933 | .serialize.instruction | |
4934 | */ | |
4935 | static void | |
5a49b8ac | 4936 | dot_serialize (int type) |
5e819f9c JW |
4937 | { |
4938 | insn_group_break (0, 0, 0); | |
4939 | if (type) | |
4940 | instruction_serialization (); | |
4941 | else | |
4942 | data_serialization (); | |
4943 | insn_group_break (0, 0, 0); | |
4944 | demand_empty_rest_of_line (); | |
4945 | } | |
4946 | ||
197865e8 | 4947 | /* select dv checking mode |
800eeca4 JW |
4948 | .auto |
4949 | .explicit | |
4950 | .default | |
4951 | ||
197865e8 | 4952 | A stop is inserted when changing modes |
800eeca4 | 4953 | */ |
542d6675 | 4954 | |
800eeca4 | 4955 | static void |
5a49b8ac | 4956 | dot_dv_mode (int type) |
800eeca4 JW |
4957 | { |
4958 | if (md.manual_bundling) | |
4959 | as_warn (_("Directive invalid within a bundle")); | |
4960 | ||
4961 | if (type == 'E' || type == 'A') | |
4962 | md.mode_explicitly_set = 0; | |
4963 | else | |
4964 | md.mode_explicitly_set = 1; | |
4965 | ||
4966 | md.detect_dv = 1; | |
4967 | switch (type) | |
4968 | { | |
4969 | case 'A': | |
4970 | case 'a': | |
4971 | if (md.explicit_mode) | |
542d6675 | 4972 | insn_group_break (1, 0, 0); |
800eeca4 JW |
4973 | md.explicit_mode = 0; |
4974 | break; | |
4975 | case 'E': | |
4976 | case 'e': | |
4977 | if (!md.explicit_mode) | |
542d6675 | 4978 | insn_group_break (1, 0, 0); |
800eeca4 JW |
4979 | md.explicit_mode = 1; |
4980 | break; | |
4981 | default: | |
4982 | case 'd': | |
4983 | if (md.explicit_mode != md.default_explicit_mode) | |
542d6675 | 4984 | insn_group_break (1, 0, 0); |
800eeca4 JW |
4985 | md.explicit_mode = md.default_explicit_mode; |
4986 | md.mode_explicitly_set = 0; | |
4987 | break; | |
4988 | } | |
4989 | } | |
4990 | ||
4991 | static void | |
5a49b8ac | 4992 | print_prmask (valueT mask) |
800eeca4 JW |
4993 | { |
4994 | int regno; | |
f86f5863 | 4995 | const char *comma = ""; |
542d6675 | 4996 | for (regno = 0; regno < 64; regno++) |
800eeca4 | 4997 | { |
542d6675 KH |
4998 | if (mask & ((valueT) 1 << regno)) |
4999 | { | |
5000 | fprintf (stderr, "%s p%d", comma, regno); | |
5001 | comma = ","; | |
5002 | } | |
800eeca4 JW |
5003 | } |
5004 | } | |
5005 | ||
5006 | /* | |
05ee4b0f JB |
5007 | .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear" or @clear) |
5008 | .pred.rel.imply p1, p2 (also .pred.rel "imply" or @imply) | |
5009 | .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex" or @mutex) | |
800eeca4 JW |
5010 | .pred.safe_across_calls p1 [, p2 [,...]] |
5011 | */ | |
542d6675 | 5012 | |
800eeca4 | 5013 | static void |
5a49b8ac | 5014 | dot_pred_rel (int type) |
800eeca4 JW |
5015 | { |
5016 | valueT mask = 0; | |
5017 | int count = 0; | |
5018 | int p1 = -1, p2 = -1; | |
5019 | ||
5020 | if (type == 0) | |
5021 | { | |
05ee4b0f | 5022 | if (*input_line_pointer == '"') |
542d6675 KH |
5023 | { |
5024 | int len; | |
5025 | char *form = demand_copy_C_string (&len); | |
05ee4b0f | 5026 | |
542d6675 KH |
5027 | if (strcmp (form, "mutex") == 0) |
5028 | type = 'm'; | |
5029 | else if (strcmp (form, "clear") == 0) | |
5030 | type = 'c'; | |
5031 | else if (strcmp (form, "imply") == 0) | |
5032 | type = 'i'; | |
05ee4b0f JB |
5033 | obstack_free (¬es, form); |
5034 | } | |
5035 | else if (*input_line_pointer == '@') | |
5036 | { | |
d02603dc NC |
5037 | char *form; |
5038 | char c; | |
5039 | ||
5040 | ++input_line_pointer; | |
5041 | c = get_symbol_name (&form); | |
05ee4b0f JB |
5042 | |
5043 | if (strcmp (form, "mutex") == 0) | |
5044 | type = 'm'; | |
5045 | else if (strcmp (form, "clear") == 0) | |
5046 | type = 'c'; | |
5047 | else if (strcmp (form, "imply") == 0) | |
5048 | type = 'i'; | |
d02603dc | 5049 | (void) restore_line_pointer (c); |
05ee4b0f JB |
5050 | } |
5051 | else | |
5052 | { | |
5053 | as_bad (_("Missing predicate relation type")); | |
5054 | ignore_rest_of_line (); | |
5055 | return; | |
5056 | } | |
5057 | if (type == 0) | |
5058 | { | |
5059 | as_bad (_("Unrecognized predicate relation type")); | |
5060 | ignore_rest_of_line (); | |
5061 | return; | |
542d6675 | 5062 | } |
800eeca4 | 5063 | if (*input_line_pointer == ',') |
542d6675 | 5064 | ++input_line_pointer; |
800eeca4 JW |
5065 | SKIP_WHITESPACE (); |
5066 | } | |
5067 | ||
800eeca4 JW |
5068 | while (1) |
5069 | { | |
20b36a95 | 5070 | valueT bits = 1; |
cc941dee | 5071 | int sep, regno; |
20b36a95 JB |
5072 | expressionS pr, *pr1, *pr2; |
5073 | ||
cd42ff9c | 5074 | sep = parse_operand_and_eval (&pr, ','); |
20b36a95 JB |
5075 | if (pr.X_op == O_register |
5076 | && pr.X_add_number >= REG_P | |
5077 | && pr.X_add_number <= REG_P + 63) | |
5078 | { | |
5079 | regno = pr.X_add_number - REG_P; | |
5080 | bits <<= regno; | |
5081 | count++; | |
5082 | if (p1 == -1) | |
5083 | p1 = regno; | |
5084 | else if (p2 == -1) | |
5085 | p2 = regno; | |
5086 | } | |
5087 | else if (type != 'i' | |
5088 | && pr.X_op == O_subtract | |
5089 | && (pr1 = symbol_get_value_expression (pr.X_add_symbol)) | |
5090 | && pr1->X_op == O_register | |
5091 | && pr1->X_add_number >= REG_P | |
5092 | && pr1->X_add_number <= REG_P + 63 | |
5093 | && (pr2 = symbol_get_value_expression (pr.X_op_symbol)) | |
5094 | && pr2->X_op == O_register | |
5095 | && pr2->X_add_number >= REG_P | |
5096 | && pr2->X_add_number <= REG_P + 63) | |
5097 | { | |
5098 | /* It's a range. */ | |
5099 | int stop; | |
5100 | ||
5101 | regno = pr1->X_add_number - REG_P; | |
5102 | stop = pr2->X_add_number - REG_P; | |
5103 | if (regno >= stop) | |
542d6675 KH |
5104 | { |
5105 | as_bad (_("Bad register range")); | |
5106 | ignore_rest_of_line (); | |
5107 | return; | |
5108 | } | |
20b36a95 JB |
5109 | bits = ((bits << stop) << 1) - (bits << regno); |
5110 | count += stop - regno + 1; | |
5111 | } | |
5112 | else | |
5113 | { | |
5114 | as_bad (_("Predicate register expected")); | |
5115 | ignore_rest_of_line (); | |
5116 | return; | |
542d6675 | 5117 | } |
20b36a95 JB |
5118 | if (mask & bits) |
5119 | as_warn (_("Duplicate predicate register ignored")); | |
5120 | mask |= bits; | |
cc941dee | 5121 | if (sep != ',') |
542d6675 | 5122 | break; |
800eeca4 JW |
5123 | } |
5124 | ||
5125 | switch (type) | |
5126 | { | |
5127 | case 'c': | |
5128 | if (count == 0) | |
542d6675 | 5129 | mask = ~(valueT) 0; |
800eeca4 | 5130 | clear_qp_mutex (mask); |
197865e8 | 5131 | clear_qp_implies (mask, (valueT) 0); |
800eeca4 JW |
5132 | break; |
5133 | case 'i': | |
5134 | if (count != 2 || p1 == -1 || p2 == -1) | |
542d6675 | 5135 | as_bad (_("Predicate source and target required")); |
800eeca4 | 5136 | else if (p1 == 0 || p2 == 0) |
542d6675 | 5137 | as_bad (_("Use of p0 is not valid in this context")); |
800eeca4 | 5138 | else |
542d6675 | 5139 | add_qp_imply (p1, p2); |
800eeca4 JW |
5140 | break; |
5141 | case 'm': | |
5142 | if (count < 2) | |
542d6675 KH |
5143 | { |
5144 | as_bad (_("At least two PR arguments expected")); | |
5145 | break; | |
5146 | } | |
800eeca4 | 5147 | else if (mask & 1) |
542d6675 KH |
5148 | { |
5149 | as_bad (_("Use of p0 is not valid in this context")); | |
5150 | break; | |
5151 | } | |
800eeca4 JW |
5152 | add_qp_mutex (mask); |
5153 | break; | |
5154 | case 's': | |
5155 | /* note that we don't override any existing relations */ | |
5156 | if (count == 0) | |
542d6675 KH |
5157 | { |
5158 | as_bad (_("At least one PR argument expected")); | |
5159 | break; | |
5160 | } | |
800eeca4 | 5161 | if (md.debug_dv) |
542d6675 KH |
5162 | { |
5163 | fprintf (stderr, "Safe across calls: "); | |
5164 | print_prmask (mask); | |
5165 | fprintf (stderr, "\n"); | |
5166 | } | |
800eeca4 JW |
5167 | qp_safe_across_calls = mask; |
5168 | break; | |
5169 | } | |
5170 | demand_empty_rest_of_line (); | |
5171 | } | |
5172 | ||
5173 | /* .entry label [, label [, ...]] | |
5174 | Hint to DV code that the given labels are to be considered entry points. | |
542d6675 KH |
5175 | Otherwise, only global labels are considered entry points. */ |
5176 | ||
800eeca4 | 5177 | static void |
5a49b8ac | 5178 | dot_entry (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
5179 | { |
5180 | const char *err; | |
5181 | char *name; | |
5182 | int c; | |
5183 | symbolS *symbolP; | |
5184 | ||
5185 | do | |
5186 | { | |
d02603dc | 5187 | c = get_symbol_name (&name); |
800eeca4 JW |
5188 | symbolP = symbol_find_or_make (name); |
5189 | ||
5a49b8ac | 5190 | err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (void *) symbolP); |
800eeca4 | 5191 | if (err) |
542d6675 KH |
5192 | as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"), |
5193 | name, err); | |
800eeca4 JW |
5194 | |
5195 | *input_line_pointer = c; | |
d02603dc | 5196 | SKIP_WHITESPACE_AFTER_NAME (); |
800eeca4 JW |
5197 | c = *input_line_pointer; |
5198 | if (c == ',') | |
5199 | { | |
5200 | input_line_pointer++; | |
5201 | SKIP_WHITESPACE (); | |
5202 | if (*input_line_pointer == '\n') | |
5203 | c = '\n'; | |
5204 | } | |
5205 | } | |
5206 | while (c == ','); | |
5207 | ||
5208 | demand_empty_rest_of_line (); | |
5209 | } | |
5210 | ||
197865e8 | 5211 | /* .mem.offset offset, base |
542d6675 KH |
5212 | "base" is used to distinguish between offsets from a different base. */ |
5213 | ||
800eeca4 | 5214 | static void |
5a49b8ac | 5215 | dot_mem_offset (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
5216 | { |
5217 | md.mem_offset.hint = 1; | |
5218 | md.mem_offset.offset = get_absolute_expression (); | |
5219 | if (*input_line_pointer != ',') | |
5220 | { | |
5221 | as_bad (_("Comma expected")); | |
5222 | ignore_rest_of_line (); | |
5223 | return; | |
5224 | } | |
5225 | ++input_line_pointer; | |
5226 | md.mem_offset.base = get_absolute_expression (); | |
5227 | demand_empty_rest_of_line (); | |
5228 | } | |
5229 | ||
542d6675 | 5230 | /* ia64-specific pseudo-ops: */ |
800eeca4 JW |
5231 | const pseudo_typeS md_pseudo_table[] = |
5232 | { | |
5233 | { "radix", dot_radix, 0 }, | |
5234 | { "lcomm", s_lcomm_bytes, 1 }, | |
196e8040 | 5235 | { "loc", dot_loc, 0 }, |
800eeca4 JW |
5236 | { "bss", dot_special_section, SPECIAL_SECTION_BSS }, |
5237 | { "sbss", dot_special_section, SPECIAL_SECTION_SBSS }, | |
5238 | { "sdata", dot_special_section, SPECIAL_SECTION_SDATA }, | |
5239 | { "rodata", dot_special_section, SPECIAL_SECTION_RODATA }, | |
5240 | { "comment", dot_special_section, SPECIAL_SECTION_COMMENT }, | |
5241 | { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND }, | |
5242 | { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO }, | |
557debba JW |
5243 | { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY }, |
5244 | { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY }, | |
800eeca4 JW |
5245 | { "proc", dot_proc, 0 }, |
5246 | { "body", dot_body, 0 }, | |
5247 | { "prologue", dot_prologue, 0 }, | |
2434f565 | 5248 | { "endp", dot_endp, 0 }, |
2434f565 JW |
5249 | |
5250 | { "fframe", dot_fframe, 0 }, | |
5251 | { "vframe", dot_vframe, 0 }, | |
5252 | { "vframesp", dot_vframesp, 0 }, | |
e4e8248d | 5253 | { "vframepsp", dot_vframesp, 1 }, |
2434f565 JW |
5254 | { "save", dot_save, 0 }, |
5255 | { "restore", dot_restore, 0 }, | |
5256 | { "restorereg", dot_restorereg, 0 }, | |
e4e8248d | 5257 | { "restorereg.p", dot_restorereg, 1 }, |
2434f565 JW |
5258 | { "handlerdata", dot_handlerdata, 0 }, |
5259 | { "unwentry", dot_unwentry, 0 }, | |
5260 | { "altrp", dot_altrp, 0 }, | |
e0c9811a JW |
5261 | { "savesp", dot_savemem, 0 }, |
5262 | { "savepsp", dot_savemem, 1 }, | |
2434f565 JW |
5263 | { "save.g", dot_saveg, 0 }, |
5264 | { "save.f", dot_savef, 0 }, | |
5265 | { "save.b", dot_saveb, 0 }, | |
5266 | { "save.gf", dot_savegf, 0 }, | |
5267 | { "spill", dot_spill, 0 }, | |
5268 | { "spillreg", dot_spillreg, 0 }, | |
e0c9811a JW |
5269 | { "spillsp", dot_spillmem, 0 }, |
5270 | { "spillpsp", dot_spillmem, 1 }, | |
e4e8248d JB |
5271 | { "spillreg.p", dot_spillreg, 1 }, |
5272 | { "spillsp.p", dot_spillmem, ~0 }, | |
5273 | { "spillpsp.p", dot_spillmem, ~1 }, | |
2434f565 JW |
5274 | { "label_state", dot_label_state, 0 }, |
5275 | { "copy_state", dot_copy_state, 0 }, | |
5276 | { "unwabi", dot_unwabi, 0 }, | |
5277 | { "personality", dot_personality, 0 }, | |
800eeca4 JW |
5278 | { "mii", dot_template, 0x0 }, |
5279 | { "mli", dot_template, 0x2 }, /* old format, for compatibility */ | |
5280 | { "mlx", dot_template, 0x2 }, | |
5281 | { "mmi", dot_template, 0x4 }, | |
5282 | { "mfi", dot_template, 0x6 }, | |
5283 | { "mmf", dot_template, 0x7 }, | |
5284 | { "mib", dot_template, 0x8 }, | |
5285 | { "mbb", dot_template, 0x9 }, | |
5286 | { "bbb", dot_template, 0xb }, | |
5287 | { "mmb", dot_template, 0xc }, | |
5288 | { "mfb", dot_template, 0xe }, | |
d9201763 | 5289 | { "align", dot_align, 0 }, |
800eeca4 JW |
5290 | { "regstk", dot_regstk, 0 }, |
5291 | { "rotr", dot_rot, DYNREG_GR }, | |
5292 | { "rotf", dot_rot, DYNREG_FR }, | |
5293 | { "rotp", dot_rot, DYNREG_PR }, | |
5294 | { "lsb", dot_byteorder, 0 }, | |
5295 | { "msb", dot_byteorder, 1 }, | |
5296 | { "psr", dot_psr, 0 }, | |
5297 | { "alias", dot_alias, 0 }, | |
35f5df7f | 5298 | { "secalias", dot_alias, 1 }, |
800eeca4 JW |
5299 | { "ln", dot_ln, 0 }, /* source line info (for debugging) */ |
5300 | ||
5301 | { "xdata1", dot_xdata, 1 }, | |
5302 | { "xdata2", dot_xdata, 2 }, | |
5303 | { "xdata4", dot_xdata, 4 }, | |
5304 | { "xdata8", dot_xdata, 8 }, | |
b3f19c14 | 5305 | { "xdata16", dot_xdata, 16 }, |
800eeca4 JW |
5306 | { "xreal4", dot_xfloat_cons, 'f' }, |
5307 | { "xreal8", dot_xfloat_cons, 'd' }, | |
5308 | { "xreal10", dot_xfloat_cons, 'x' }, | |
165a7f90 | 5309 | { "xreal16", dot_xfloat_cons, 'X' }, |
38a57ae7 NC |
5310 | { "xstring", dot_xstringer, 8 + 0 }, |
5311 | { "xstringz", dot_xstringer, 8 + 1 }, | |
800eeca4 | 5312 | |
542d6675 | 5313 | /* unaligned versions: */ |
800eeca4 JW |
5314 | { "xdata2.ua", dot_xdata_ua, 2 }, |
5315 | { "xdata4.ua", dot_xdata_ua, 4 }, | |
5316 | { "xdata8.ua", dot_xdata_ua, 8 }, | |
b3f19c14 | 5317 | { "xdata16.ua", dot_xdata_ua, 16 }, |
800eeca4 JW |
5318 | { "xreal4.ua", dot_xfloat_cons_ua, 'f' }, |
5319 | { "xreal8.ua", dot_xfloat_cons_ua, 'd' }, | |
5320 | { "xreal10.ua", dot_xfloat_cons_ua, 'x' }, | |
165a7f90 | 5321 | { "xreal16.ua", dot_xfloat_cons_ua, 'X' }, |
800eeca4 JW |
5322 | |
5323 | /* annotations/DV checking support */ | |
5324 | { "entry", dot_entry, 0 }, | |
2434f565 | 5325 | { "mem.offset", dot_mem_offset, 0 }, |
800eeca4 JW |
5326 | { "pred.rel", dot_pred_rel, 0 }, |
5327 | { "pred.rel.clear", dot_pred_rel, 'c' }, | |
5328 | { "pred.rel.imply", dot_pred_rel, 'i' }, | |
5329 | { "pred.rel.mutex", dot_pred_rel, 'm' }, | |
5330 | { "pred.safe_across_calls", dot_pred_rel, 's' }, | |
2434f565 | 5331 | { "reg.val", dot_reg_val, 0 }, |
5e819f9c JW |
5332 | { "serialize.data", dot_serialize, 0 }, |
5333 | { "serialize.instruction", dot_serialize, 1 }, | |
800eeca4 JW |
5334 | { "auto", dot_dv_mode, 'a' }, |
5335 | { "explicit", dot_dv_mode, 'e' }, | |
5336 | { "default", dot_dv_mode, 'd' }, | |
5337 | ||
87885043 JW |
5338 | /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work. |
5339 | IA-64 aligns data allocation pseudo-ops by default, so we have to | |
5340 | tell it that these ones are supposed to be unaligned. Long term, | |
5341 | should rewrite so that only IA-64 specific data allocation pseudo-ops | |
5342 | are aligned by default. */ | |
5343 | {"2byte", stmt_cons_ua, 2}, | |
5344 | {"4byte", stmt_cons_ua, 4}, | |
5345 | {"8byte", stmt_cons_ua, 8}, | |
5346 | ||
2b0bc501 TG |
5347 | #ifdef TE_VMS |
5348 | {"vms_common", obj_elf_vms_common, 0}, | |
5349 | #endif | |
5350 | ||
800eeca4 JW |
5351 | { NULL, 0, 0 } |
5352 | }; | |
5353 | ||
5354 | static const struct pseudo_opcode | |
5355 | { | |
5356 | const char *name; | |
5357 | void (*handler) (int); | |
5358 | int arg; | |
5359 | } | |
5360 | pseudo_opcode[] = | |
5361 | { | |
5362 | /* these are more like pseudo-ops, but don't start with a dot */ | |
5363 | { "data1", cons, 1 }, | |
5364 | { "data2", cons, 2 }, | |
5365 | { "data4", cons, 4 }, | |
5366 | { "data8", cons, 8 }, | |
3969b680 | 5367 | { "data16", cons, 16 }, |
800eeca4 JW |
5368 | { "real4", stmt_float_cons, 'f' }, |
5369 | { "real8", stmt_float_cons, 'd' }, | |
5370 | { "real10", stmt_float_cons, 'x' }, | |
165a7f90 | 5371 | { "real16", stmt_float_cons, 'X' }, |
38a57ae7 NC |
5372 | { "string", stringer, 8 + 0 }, |
5373 | { "stringz", stringer, 8 + 1 }, | |
800eeca4 | 5374 | |
542d6675 | 5375 | /* unaligned versions: */ |
800eeca4 JW |
5376 | { "data2.ua", stmt_cons_ua, 2 }, |
5377 | { "data4.ua", stmt_cons_ua, 4 }, | |
5378 | { "data8.ua", stmt_cons_ua, 8 }, | |
3969b680 | 5379 | { "data16.ua", stmt_cons_ua, 16 }, |
800eeca4 JW |
5380 | { "real4.ua", float_cons, 'f' }, |
5381 | { "real8.ua", float_cons, 'd' }, | |
5382 | { "real10.ua", float_cons, 'x' }, | |
165a7f90 | 5383 | { "real16.ua", float_cons, 'X' }, |
800eeca4 JW |
5384 | }; |
5385 | ||
5386 | /* Declare a register by creating a symbol for it and entering it in | |
5387 | the symbol table. */ | |
542d6675 KH |
5388 | |
5389 | static symbolS * | |
5a49b8ac | 5390 | declare_register (const char *name, unsigned int regnum) |
800eeca4 JW |
5391 | { |
5392 | const char *err; | |
5393 | symbolS *sym; | |
5394 | ||
5e0bd176 | 5395 | sym = symbol_create (name, reg_section, regnum, &zero_address_frag); |
800eeca4 | 5396 | |
5a49b8ac | 5397 | err = hash_insert (md.reg_hash, S_GET_NAME (sym), (void *) sym); |
800eeca4 JW |
5398 | if (err) |
5399 | as_fatal ("Inserting \"%s\" into register table failed: %s", | |
5400 | name, err); | |
5401 | ||
5402 | return sym; | |
5403 | } | |
5404 | ||
5405 | static void | |
5a49b8ac AM |
5406 | declare_register_set (const char *prefix, |
5407 | unsigned int num_regs, | |
5408 | unsigned int base_regnum) | |
800eeca4 JW |
5409 | { |
5410 | char name[8]; | |
8b84be9d | 5411 | unsigned int i; |
800eeca4 JW |
5412 | |
5413 | for (i = 0; i < num_regs; ++i) | |
5414 | { | |
f9f21a03 | 5415 | snprintf (name, sizeof (name), "%s%u", prefix, i); |
800eeca4 JW |
5416 | declare_register (name, base_regnum + i); |
5417 | } | |
5418 | } | |
5419 | ||
5420 | static unsigned int | |
5a49b8ac | 5421 | operand_width (enum ia64_opnd opnd) |
800eeca4 JW |
5422 | { |
5423 | const struct ia64_operand *odesc = &elf64_ia64_operands[opnd]; | |
5424 | unsigned int bits = 0; | |
5425 | int i; | |
5426 | ||
5427 | bits = 0; | |
5428 | for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i) | |
5429 | bits += odesc->field[i].bits; | |
5430 | ||
5431 | return bits; | |
5432 | } | |
5433 | ||
87f8eb97 | 5434 | static enum operand_match_result |
91d6fa6a | 5435 | operand_match (const struct ia64_opcode *idesc, int res_index, expressionS *e) |
800eeca4 | 5436 | { |
91d6fa6a | 5437 | enum ia64_opnd opnd = idesc->operands[res_index]; |
800eeca4 JW |
5438 | int bits, relocatable = 0; |
5439 | struct insn_fix *fix; | |
5440 | bfd_signed_vma val; | |
5441 | ||
5442 | switch (opnd) | |
5443 | { | |
542d6675 | 5444 | /* constants: */ |
800eeca4 JW |
5445 | |
5446 | case IA64_OPND_AR_CCV: | |
5447 | if (e->X_op == O_register && e->X_add_number == REG_AR + 32) | |
87f8eb97 | 5448 | return OPERAND_MATCH; |
800eeca4 JW |
5449 | break; |
5450 | ||
c10d9d8f JW |
5451 | case IA64_OPND_AR_CSD: |
5452 | if (e->X_op == O_register && e->X_add_number == REG_AR + 25) | |
5453 | return OPERAND_MATCH; | |
5454 | break; | |
5455 | ||
800eeca4 JW |
5456 | case IA64_OPND_AR_PFS: |
5457 | if (e->X_op == O_register && e->X_add_number == REG_AR + 64) | |
87f8eb97 | 5458 | return OPERAND_MATCH; |
800eeca4 JW |
5459 | break; |
5460 | ||
5461 | case IA64_OPND_GR0: | |
5462 | if (e->X_op == O_register && e->X_add_number == REG_GR + 0) | |
87f8eb97 | 5463 | return OPERAND_MATCH; |
800eeca4 JW |
5464 | break; |
5465 | ||
5466 | case IA64_OPND_IP: | |
5467 | if (e->X_op == O_register && e->X_add_number == REG_IP) | |
87f8eb97 | 5468 | return OPERAND_MATCH; |
800eeca4 JW |
5469 | break; |
5470 | ||
5471 | case IA64_OPND_PR: | |
5472 | if (e->X_op == O_register && e->X_add_number == REG_PR) | |
87f8eb97 | 5473 | return OPERAND_MATCH; |
800eeca4 JW |
5474 | break; |
5475 | ||
5476 | case IA64_OPND_PR_ROT: | |
5477 | if (e->X_op == O_register && e->X_add_number == REG_PR_ROT) | |
87f8eb97 | 5478 | return OPERAND_MATCH; |
800eeca4 JW |
5479 | break; |
5480 | ||
5481 | case IA64_OPND_PSR: | |
5482 | if (e->X_op == O_register && e->X_add_number == REG_PSR) | |
87f8eb97 | 5483 | return OPERAND_MATCH; |
800eeca4 JW |
5484 | break; |
5485 | ||
5486 | case IA64_OPND_PSR_L: | |
5487 | if (e->X_op == O_register && e->X_add_number == REG_PSR_L) | |
87f8eb97 | 5488 | return OPERAND_MATCH; |
800eeca4 JW |
5489 | break; |
5490 | ||
5491 | case IA64_OPND_PSR_UM: | |
5492 | if (e->X_op == O_register && e->X_add_number == REG_PSR_UM) | |
87f8eb97 | 5493 | return OPERAND_MATCH; |
800eeca4 JW |
5494 | break; |
5495 | ||
5496 | case IA64_OPND_C1: | |
87f8eb97 JW |
5497 | if (e->X_op == O_constant) |
5498 | { | |
5499 | if (e->X_add_number == 1) | |
5500 | return OPERAND_MATCH; | |
5501 | else | |
5502 | return OPERAND_OUT_OF_RANGE; | |
5503 | } | |
800eeca4 JW |
5504 | break; |
5505 | ||
5506 | case IA64_OPND_C8: | |
87f8eb97 JW |
5507 | if (e->X_op == O_constant) |
5508 | { | |
5509 | if (e->X_add_number == 8) | |
5510 | return OPERAND_MATCH; | |
5511 | else | |
5512 | return OPERAND_OUT_OF_RANGE; | |
5513 | } | |
800eeca4 JW |
5514 | break; |
5515 | ||
5516 | case IA64_OPND_C16: | |
87f8eb97 JW |
5517 | if (e->X_op == O_constant) |
5518 | { | |
5519 | if (e->X_add_number == 16) | |
5520 | return OPERAND_MATCH; | |
5521 | else | |
5522 | return OPERAND_OUT_OF_RANGE; | |
5523 | } | |
800eeca4 JW |
5524 | break; |
5525 | ||
542d6675 | 5526 | /* register operands: */ |
800eeca4 JW |
5527 | |
5528 | case IA64_OPND_AR3: | |
5529 | if (e->X_op == O_register && e->X_add_number >= REG_AR | |
5530 | && e->X_add_number < REG_AR + 128) | |
87f8eb97 | 5531 | return OPERAND_MATCH; |
800eeca4 JW |
5532 | break; |
5533 | ||
5534 | case IA64_OPND_B1: | |
5535 | case IA64_OPND_B2: | |
5536 | if (e->X_op == O_register && e->X_add_number >= REG_BR | |
5537 | && e->X_add_number < REG_BR + 8) | |
87f8eb97 | 5538 | return OPERAND_MATCH; |
800eeca4 JW |
5539 | break; |
5540 | ||
5541 | case IA64_OPND_CR3: | |
5542 | if (e->X_op == O_register && e->X_add_number >= REG_CR | |
5543 | && e->X_add_number < REG_CR + 128) | |
87f8eb97 | 5544 | return OPERAND_MATCH; |
800eeca4 JW |
5545 | break; |
5546 | ||
b3e14eda L |
5547 | case IA64_OPND_DAHR3: |
5548 | if (e->X_op == O_register && e->X_add_number >= REG_DAHR | |
5549 | && e->X_add_number < REG_DAHR + 8) | |
5550 | return OPERAND_MATCH; | |
5551 | break; | |
5552 | ||
800eeca4 JW |
5553 | case IA64_OPND_F1: |
5554 | case IA64_OPND_F2: | |
5555 | case IA64_OPND_F3: | |
5556 | case IA64_OPND_F4: | |
5557 | if (e->X_op == O_register && e->X_add_number >= REG_FR | |
5558 | && e->X_add_number < REG_FR + 128) | |
87f8eb97 | 5559 | return OPERAND_MATCH; |
800eeca4 JW |
5560 | break; |
5561 | ||
5562 | case IA64_OPND_P1: | |
5563 | case IA64_OPND_P2: | |
5564 | if (e->X_op == O_register && e->X_add_number >= REG_P | |
5565 | && e->X_add_number < REG_P + 64) | |
87f8eb97 | 5566 | return OPERAND_MATCH; |
800eeca4 JW |
5567 | break; |
5568 | ||
5569 | case IA64_OPND_R1: | |
5570 | case IA64_OPND_R2: | |
5571 | case IA64_OPND_R3: | |
5572 | if (e->X_op == O_register && e->X_add_number >= REG_GR | |
5573 | && e->X_add_number < REG_GR + 128) | |
87f8eb97 | 5574 | return OPERAND_MATCH; |
800eeca4 JW |
5575 | break; |
5576 | ||
5577 | case IA64_OPND_R3_2: | |
87f8eb97 | 5578 | if (e->X_op == O_register && e->X_add_number >= REG_GR) |
40449e9f | 5579 | { |
87f8eb97 JW |
5580 | if (e->X_add_number < REG_GR + 4) |
5581 | return OPERAND_MATCH; | |
5582 | else if (e->X_add_number < REG_GR + 128) | |
5583 | return OPERAND_OUT_OF_RANGE; | |
5584 | } | |
800eeca4 JW |
5585 | break; |
5586 | ||
542d6675 | 5587 | /* indirect operands: */ |
800eeca4 JW |
5588 | case IA64_OPND_CPUID_R3: |
5589 | case IA64_OPND_DBR_R3: | |
5590 | case IA64_OPND_DTR_R3: | |
5591 | case IA64_OPND_ITR_R3: | |
5592 | case IA64_OPND_IBR_R3: | |
5593 | case IA64_OPND_MSR_R3: | |
5594 | case IA64_OPND_PKR_R3: | |
5595 | case IA64_OPND_PMC_R3: | |
5596 | case IA64_OPND_PMD_R3: | |
b3e14eda | 5597 | case IA64_OPND_DAHR_R3: |
800eeca4 JW |
5598 | case IA64_OPND_RR_R3: |
5599 | if (e->X_op == O_index && e->X_op_symbol | |
5600 | && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID | |
5601 | == opnd - IA64_OPND_CPUID_R3)) | |
87f8eb97 | 5602 | return OPERAND_MATCH; |
800eeca4 JW |
5603 | break; |
5604 | ||
5605 | case IA64_OPND_MR3: | |
5606 | if (e->X_op == O_index && !e->X_op_symbol) | |
87f8eb97 | 5607 | return OPERAND_MATCH; |
800eeca4 JW |
5608 | break; |
5609 | ||
542d6675 | 5610 | /* immediate operands: */ |
800eeca4 JW |
5611 | case IA64_OPND_CNT2a: |
5612 | case IA64_OPND_LEN4: | |
5613 | case IA64_OPND_LEN6: | |
91d6fa6a | 5614 | bits = operand_width (idesc->operands[res_index]); |
87f8eb97 JW |
5615 | if (e->X_op == O_constant) |
5616 | { | |
5617 | if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits)) | |
5618 | return OPERAND_MATCH; | |
5619 | else | |
5620 | return OPERAND_OUT_OF_RANGE; | |
5621 | } | |
800eeca4 JW |
5622 | break; |
5623 | ||
5624 | case IA64_OPND_CNT2b: | |
87f8eb97 JW |
5625 | if (e->X_op == O_constant) |
5626 | { | |
5627 | if ((bfd_vma) (e->X_add_number - 1) < 3) | |
5628 | return OPERAND_MATCH; | |
5629 | else | |
5630 | return OPERAND_OUT_OF_RANGE; | |
5631 | } | |
800eeca4 JW |
5632 | break; |
5633 | ||
5634 | case IA64_OPND_CNT2c: | |
5635 | val = e->X_add_number; | |
87f8eb97 JW |
5636 | if (e->X_op == O_constant) |
5637 | { | |
5638 | if ((val == 0 || val == 7 || val == 15 || val == 16)) | |
5639 | return OPERAND_MATCH; | |
5640 | else | |
5641 | return OPERAND_OUT_OF_RANGE; | |
5642 | } | |
800eeca4 JW |
5643 | break; |
5644 | ||
5645 | case IA64_OPND_SOR: | |
5646 | /* SOR must be an integer multiple of 8 */ | |
87f8eb97 JW |
5647 | if (e->X_op == O_constant && e->X_add_number & 0x7) |
5648 | return OPERAND_OUT_OF_RANGE; | |
800eeca4 JW |
5649 | case IA64_OPND_SOF: |
5650 | case IA64_OPND_SOL: | |
87f8eb97 JW |
5651 | if (e->X_op == O_constant) |
5652 | { | |
5653 | if ((bfd_vma) e->X_add_number <= 96) | |
5654 | return OPERAND_MATCH; | |
5655 | else | |
5656 | return OPERAND_OUT_OF_RANGE; | |
5657 | } | |
800eeca4 JW |
5658 | break; |
5659 | ||
5660 | case IA64_OPND_IMMU62: | |
5661 | if (e->X_op == O_constant) | |
542d6675 | 5662 | { |
800eeca4 | 5663 | if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62)) |
87f8eb97 JW |
5664 | return OPERAND_MATCH; |
5665 | else | |
5666 | return OPERAND_OUT_OF_RANGE; | |
542d6675 | 5667 | } |
197865e8 | 5668 | else |
542d6675 KH |
5669 | { |
5670 | /* FIXME -- need 62-bit relocation type */ | |
5671 | as_bad (_("62-bit relocation not yet implemented")); | |
5672 | } | |
800eeca4 JW |
5673 | break; |
5674 | ||
5675 | case IA64_OPND_IMMU64: | |
5676 | if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup | |
5677 | || e->X_op == O_subtract) | |
5678 | { | |
5679 | fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups; | |
5680 | fix->code = BFD_RELOC_IA64_IMM64; | |
5681 | if (e->X_op != O_subtract) | |
5682 | { | |
5683 | fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code); | |
5684 | if (e->X_op == O_pseudo_fixup) | |
5685 | e->X_op = O_symbol; | |
5686 | } | |
5687 | ||
91d6fa6a | 5688 | fix->opnd = idesc->operands[res_index]; |
800eeca4 JW |
5689 | fix->expr = *e; |
5690 | fix->is_pcrel = 0; | |
5691 | ++CURR_SLOT.num_fixups; | |
87f8eb97 | 5692 | return OPERAND_MATCH; |
800eeca4 JW |
5693 | } |
5694 | else if (e->X_op == O_constant) | |
87f8eb97 | 5695 | return OPERAND_MATCH; |
800eeca4 JW |
5696 | break; |
5697 | ||
59cf82fe L |
5698 | case IA64_OPND_IMMU5b: |
5699 | if (e->X_op == O_constant) | |
5700 | { | |
5701 | val = e->X_add_number; | |
5702 | if (val >= 32 && val <= 63) | |
5703 | return OPERAND_MATCH; | |
5704 | else | |
5705 | return OPERAND_OUT_OF_RANGE; | |
5706 | } | |
5707 | break; | |
5708 | ||
800eeca4 JW |
5709 | case IA64_OPND_CCNT5: |
5710 | case IA64_OPND_CNT5: | |
5711 | case IA64_OPND_CNT6: | |
5712 | case IA64_OPND_CPOS6a: | |
5713 | case IA64_OPND_CPOS6b: | |
5714 | case IA64_OPND_CPOS6c: | |
5715 | case IA64_OPND_IMMU2: | |
5716 | case IA64_OPND_IMMU7a: | |
5717 | case IA64_OPND_IMMU7b: | |
b3e14eda L |
5718 | case IA64_OPND_IMMU16: |
5719 | case IA64_OPND_IMMU19: | |
800eeca4 JW |
5720 | case IA64_OPND_IMMU21: |
5721 | case IA64_OPND_IMMU24: | |
5722 | case IA64_OPND_MBTYPE4: | |
5723 | case IA64_OPND_MHTYPE8: | |
5724 | case IA64_OPND_POS6: | |
91d6fa6a | 5725 | bits = operand_width (idesc->operands[res_index]); |
87f8eb97 JW |
5726 | if (e->X_op == O_constant) |
5727 | { | |
5728 | if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits)) | |
5729 | return OPERAND_MATCH; | |
5730 | else | |
5731 | return OPERAND_OUT_OF_RANGE; | |
5732 | } | |
800eeca4 JW |
5733 | break; |
5734 | ||
bf3ca999 | 5735 | case IA64_OPND_IMMU9: |
91d6fa6a | 5736 | bits = operand_width (idesc->operands[res_index]); |
87f8eb97 | 5737 | if (e->X_op == O_constant) |
542d6675 | 5738 | { |
87f8eb97 JW |
5739 | if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits)) |
5740 | { | |
5741 | int lobits = e->X_add_number & 0x3; | |
5742 | if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0) | |
5743 | e->X_add_number |= (bfd_vma) 0x3; | |
5744 | return OPERAND_MATCH; | |
5745 | } | |
5746 | else | |
5747 | return OPERAND_OUT_OF_RANGE; | |
542d6675 | 5748 | } |
bf3ca999 TW |
5749 | break; |
5750 | ||
800eeca4 JW |
5751 | case IA64_OPND_IMM44: |
5752 | /* least 16 bits must be zero */ | |
5753 | if ((e->X_add_number & 0xffff) != 0) | |
87f8eb97 JW |
5754 | /* XXX technically, this is wrong: we should not be issuing warning |
5755 | messages until we're sure this instruction pattern is going to | |
5756 | be used! */ | |
542d6675 | 5757 | as_warn (_("lower 16 bits of mask ignored")); |
800eeca4 | 5758 | |
87f8eb97 | 5759 | if (e->X_op == O_constant) |
542d6675 | 5760 | { |
87f8eb97 JW |
5761 | if (((e->X_add_number >= 0 |
5762 | && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44)) | |
5763 | || (e->X_add_number < 0 | |
5764 | && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44)))) | |
542d6675 | 5765 | { |
87f8eb97 JW |
5766 | /* sign-extend */ |
5767 | if (e->X_add_number >= 0 | |
5768 | && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0) | |
5769 | { | |
5770 | e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1); | |
5771 | } | |
5772 | return OPERAND_MATCH; | |
542d6675 | 5773 | } |
87f8eb97 JW |
5774 | else |
5775 | return OPERAND_OUT_OF_RANGE; | |
542d6675 | 5776 | } |
800eeca4 JW |
5777 | break; |
5778 | ||
5779 | case IA64_OPND_IMM17: | |
5780 | /* bit 0 is a don't care (pr0 is hardwired to 1) */ | |
87f8eb97 | 5781 | if (e->X_op == O_constant) |
542d6675 | 5782 | { |
87f8eb97 JW |
5783 | if (((e->X_add_number >= 0 |
5784 | && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17)) | |
5785 | || (e->X_add_number < 0 | |
5786 | && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17)))) | |
542d6675 | 5787 | { |
87f8eb97 JW |
5788 | /* sign-extend */ |
5789 | if (e->X_add_number >= 0 | |
5790 | && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0) | |
5791 | { | |
5792 | e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1); | |
5793 | } | |
5794 | return OPERAND_MATCH; | |
542d6675 | 5795 | } |
87f8eb97 JW |
5796 | else |
5797 | return OPERAND_OUT_OF_RANGE; | |
542d6675 | 5798 | } |
800eeca4 JW |
5799 | break; |
5800 | ||
5801 | case IA64_OPND_IMM14: | |
5802 | case IA64_OPND_IMM22: | |
5803 | relocatable = 1; | |
5804 | case IA64_OPND_IMM1: | |
5805 | case IA64_OPND_IMM8: | |
5806 | case IA64_OPND_IMM8U4: | |
5807 | case IA64_OPND_IMM8M1: | |
5808 | case IA64_OPND_IMM8M1U4: | |
5809 | case IA64_OPND_IMM8M1U8: | |
5810 | case IA64_OPND_IMM9a: | |
5811 | case IA64_OPND_IMM9b: | |
91d6fa6a | 5812 | bits = operand_width (idesc->operands[res_index]); |
800eeca4 JW |
5813 | if (relocatable && (e->X_op == O_symbol |
5814 | || e->X_op == O_subtract | |
5815 | || e->X_op == O_pseudo_fixup)) | |
5816 | { | |
5817 | fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups; | |
5818 | ||
91d6fa6a | 5819 | if (idesc->operands[res_index] == IA64_OPND_IMM14) |
800eeca4 JW |
5820 | fix->code = BFD_RELOC_IA64_IMM14; |
5821 | else | |
5822 | fix->code = BFD_RELOC_IA64_IMM22; | |
5823 | ||
5824 | if (e->X_op != O_subtract) | |
5825 | { | |
5826 | fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code); | |
5827 | if (e->X_op == O_pseudo_fixup) | |
5828 | e->X_op = O_symbol; | |
5829 | } | |
5830 | ||
91d6fa6a | 5831 | fix->opnd = idesc->operands[res_index]; |
800eeca4 JW |
5832 | fix->expr = *e; |
5833 | fix->is_pcrel = 0; | |
5834 | ++CURR_SLOT.num_fixups; | |
87f8eb97 | 5835 | return OPERAND_MATCH; |
800eeca4 JW |
5836 | } |
5837 | else if (e->X_op != O_constant | |
5838 | && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8)) | |
87f8eb97 | 5839 | return OPERAND_MISMATCH; |
800eeca4 JW |
5840 | |
5841 | if (opnd == IA64_OPND_IMM8M1U4) | |
5842 | { | |
5843 | /* Zero is not valid for unsigned compares that take an adjusted | |
5844 | constant immediate range. */ | |
5845 | if (e->X_add_number == 0) | |
87f8eb97 | 5846 | return OPERAND_OUT_OF_RANGE; |
800eeca4 JW |
5847 | |
5848 | /* Sign-extend 32-bit unsigned numbers, so that the following range | |
5849 | checks will work. */ | |
5850 | val = e->X_add_number; | |
197865e8 KH |
5851 | if (((val & (~(bfd_vma) 0 << 32)) == 0) |
5852 | && ((val & ((bfd_vma) 1 << 31)) != 0)) | |
800eeca4 JW |
5853 | val = ((val << 32) >> 32); |
5854 | ||
5855 | /* Check for 0x100000000. This is valid because | |
5856 | 0x100000000-1 is the same as ((uint32_t) -1). */ | |
5857 | if (val == ((bfd_signed_vma) 1 << 32)) | |
87f8eb97 | 5858 | return OPERAND_MATCH; |
800eeca4 JW |
5859 | |
5860 | val = val - 1; | |
5861 | } | |
5862 | else if (opnd == IA64_OPND_IMM8M1U8) | |
5863 | { | |
5864 | /* Zero is not valid for unsigned compares that take an adjusted | |
5865 | constant immediate range. */ | |
5866 | if (e->X_add_number == 0) | |
87f8eb97 | 5867 | return OPERAND_OUT_OF_RANGE; |
800eeca4 JW |
5868 | |
5869 | /* Check for 0x10000000000000000. */ | |
5870 | if (e->X_op == O_big) | |
5871 | { | |
5872 | if (generic_bignum[0] == 0 | |
5873 | && generic_bignum[1] == 0 | |
5874 | && generic_bignum[2] == 0 | |
5875 | && generic_bignum[3] == 0 | |
5876 | && generic_bignum[4] == 1) | |
87f8eb97 | 5877 | return OPERAND_MATCH; |
800eeca4 | 5878 | else |
87f8eb97 | 5879 | return OPERAND_OUT_OF_RANGE; |
800eeca4 JW |
5880 | } |
5881 | else | |
5882 | val = e->X_add_number - 1; | |
5883 | } | |
5884 | else if (opnd == IA64_OPND_IMM8M1) | |
5885 | val = e->X_add_number - 1; | |
5886 | else if (opnd == IA64_OPND_IMM8U4) | |
5887 | { | |
5888 | /* Sign-extend 32-bit unsigned numbers, so that the following range | |
5889 | checks will work. */ | |
5890 | val = e->X_add_number; | |
197865e8 KH |
5891 | if (((val & (~(bfd_vma) 0 << 32)) == 0) |
5892 | && ((val & ((bfd_vma) 1 << 31)) != 0)) | |
800eeca4 JW |
5893 | val = ((val << 32) >> 32); |
5894 | } | |
5895 | else | |
5896 | val = e->X_add_number; | |
5897 | ||
2434f565 JW |
5898 | if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1))) |
5899 | || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1)))) | |
87f8eb97 JW |
5900 | return OPERAND_MATCH; |
5901 | else | |
5902 | return OPERAND_OUT_OF_RANGE; | |
800eeca4 JW |
5903 | |
5904 | case IA64_OPND_INC3: | |
5905 | /* +/- 1, 4, 8, 16 */ | |
5906 | val = e->X_add_number; | |
5907 | if (val < 0) | |
5908 | val = -val; | |
87f8eb97 JW |
5909 | if (e->X_op == O_constant) |
5910 | { | |
5911 | if ((val == 1 || val == 4 || val == 8 || val == 16)) | |
5912 | return OPERAND_MATCH; | |
5913 | else | |
5914 | return OPERAND_OUT_OF_RANGE; | |
5915 | } | |
800eeca4 JW |
5916 | break; |
5917 | ||
5918 | case IA64_OPND_TGT25: | |
5919 | case IA64_OPND_TGT25b: | |
5920 | case IA64_OPND_TGT25c: | |
5921 | case IA64_OPND_TGT64: | |
5922 | if (e->X_op == O_symbol) | |
5923 | { | |
5924 | fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups; | |
5925 | if (opnd == IA64_OPND_TGT25) | |
5926 | fix->code = BFD_RELOC_IA64_PCREL21F; | |
5927 | else if (opnd == IA64_OPND_TGT25b) | |
5928 | fix->code = BFD_RELOC_IA64_PCREL21M; | |
5929 | else if (opnd == IA64_OPND_TGT25c) | |
5930 | fix->code = BFD_RELOC_IA64_PCREL21B; | |
542d6675 | 5931 | else if (opnd == IA64_OPND_TGT64) |
c67e42c9 RH |
5932 | fix->code = BFD_RELOC_IA64_PCREL60B; |
5933 | else | |
5934 | abort (); | |
5935 | ||
800eeca4 | 5936 | fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code); |
91d6fa6a | 5937 | fix->opnd = idesc->operands[res_index]; |
800eeca4 JW |
5938 | fix->expr = *e; |
5939 | fix->is_pcrel = 1; | |
5940 | ++CURR_SLOT.num_fixups; | |
87f8eb97 | 5941 | return OPERAND_MATCH; |
800eeca4 JW |
5942 | } |
5943 | case IA64_OPND_TAG13: | |
5944 | case IA64_OPND_TAG13b: | |
5945 | switch (e->X_op) | |
5946 | { | |
5947 | case O_constant: | |
87f8eb97 | 5948 | return OPERAND_MATCH; |
800eeca4 JW |
5949 | |
5950 | case O_symbol: | |
5951 | fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups; | |
fa1cb89c | 5952 | /* There are no external relocs for TAG13/TAG13b fields, so we |
55cf6793 | 5953 | create a dummy reloc. This will not live past md_apply_fix. */ |
fa1cb89c JW |
5954 | fix->code = BFD_RELOC_UNUSED; |
5955 | fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code); | |
91d6fa6a | 5956 | fix->opnd = idesc->operands[res_index]; |
800eeca4 JW |
5957 | fix->expr = *e; |
5958 | fix->is_pcrel = 1; | |
5959 | ++CURR_SLOT.num_fixups; | |
87f8eb97 | 5960 | return OPERAND_MATCH; |
800eeca4 JW |
5961 | |
5962 | default: | |
5963 | break; | |
5964 | } | |
5965 | break; | |
5966 | ||
a823923b RH |
5967 | case IA64_OPND_LDXMOV: |
5968 | fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups; | |
5969 | fix->code = BFD_RELOC_IA64_LDXMOV; | |
91d6fa6a | 5970 | fix->opnd = idesc->operands[res_index]; |
a823923b RH |
5971 | fix->expr = *e; |
5972 | fix->is_pcrel = 0; | |
5973 | ++CURR_SLOT.num_fixups; | |
5974 | return OPERAND_MATCH; | |
5975 | ||
b3e14eda L |
5976 | case IA64_OPND_STRD5b: |
5977 | if (e->X_op == O_constant) | |
5978 | { | |
5979 | /* 5-bit signed scaled by 64 */ | |
3739860c | 5980 | if ((e->X_add_number <= ( 0xf << 6 )) |
b3e14eda L |
5981 | && (e->X_add_number >= -( 0x10 << 6 ))) |
5982 | { | |
3739860c | 5983 | |
b3e14eda L |
5984 | /* Must be a multiple of 64 */ |
5985 | if ((e->X_add_number & 0x3f) != 0) | |
5986 | as_warn (_("stride must be a multiple of 64; lower 6 bits ignored")); | |
5987 | ||
5988 | e->X_add_number &= ~ 0x3f; | |
5989 | return OPERAND_MATCH; | |
5990 | } | |
5991 | else | |
5992 | return OPERAND_OUT_OF_RANGE; | |
5993 | } | |
5994 | break; | |
5995 | case IA64_OPND_CNT6a: | |
5996 | if (e->X_op == O_constant) | |
5997 | { | |
5998 | /* 6-bit unsigned biased by 1 -- count 0 is meaningless */ | |
3739860c | 5999 | if ((e->X_add_number <= 64) |
b3e14eda L |
6000 | && (e->X_add_number > 0) ) |
6001 | { | |
6002 | return OPERAND_MATCH; | |
6003 | } | |
6004 | else | |
6005 | return OPERAND_OUT_OF_RANGE; | |
6006 | } | |
6007 | break; | |
6008 | ||
800eeca4 JW |
6009 | default: |
6010 | break; | |
6011 | } | |
87f8eb97 | 6012 | return OPERAND_MISMATCH; |
800eeca4 JW |
6013 | } |
6014 | ||
6015 | static int | |
5a49b8ac | 6016 | parse_operand (expressionS *e, int more) |
800eeca4 JW |
6017 | { |
6018 | int sep = '\0'; | |
6019 | ||
6020 | memset (e, 0, sizeof (*e)); | |
6021 | e->X_op = O_absent; | |
6022 | SKIP_WHITESPACE (); | |
cd42ff9c | 6023 | expression (e); |
e4e8248d JB |
6024 | sep = *input_line_pointer; |
6025 | if (more && (sep == ',' || sep == more)) | |
6026 | ++input_line_pointer; | |
800eeca4 JW |
6027 | return sep; |
6028 | } | |
6029 | ||
cd42ff9c AM |
6030 | static int |
6031 | parse_operand_and_eval (expressionS *e, int more) | |
6032 | { | |
6033 | int sep = parse_operand (e, more); | |
6034 | resolve_expression (e); | |
6035 | return sep; | |
6036 | } | |
6037 | ||
6038 | static int | |
6039 | parse_operand_maybe_eval (expressionS *e, int more, enum ia64_opnd op) | |
6040 | { | |
6041 | int sep = parse_operand (e, more); | |
6042 | switch (op) | |
6043 | { | |
6044 | case IA64_OPND_IMM14: | |
6045 | case IA64_OPND_IMM22: | |
6046 | case IA64_OPND_IMMU64: | |
6047 | case IA64_OPND_TGT25: | |
6048 | case IA64_OPND_TGT25b: | |
6049 | case IA64_OPND_TGT25c: | |
6050 | case IA64_OPND_TGT64: | |
6051 | case IA64_OPND_TAG13: | |
6052 | case IA64_OPND_TAG13b: | |
6053 | case IA64_OPND_LDXMOV: | |
6054 | break; | |
6055 | default: | |
6056 | resolve_expression (e); | |
6057 | break; | |
6058 | } | |
6059 | return sep; | |
6060 | } | |
6061 | ||
800eeca4 JW |
6062 | /* Returns the next entry in the opcode table that matches the one in |
6063 | IDESC, and frees the entry in IDESC. If no matching entry is | |
197865e8 | 6064 | found, NULL is returned instead. */ |
800eeca4 JW |
6065 | |
6066 | static struct ia64_opcode * | |
6067 | get_next_opcode (struct ia64_opcode *idesc) | |
6068 | { | |
6069 | struct ia64_opcode *next = ia64_find_next_opcode (idesc); | |
6070 | ia64_free_opcode (idesc); | |
6071 | return next; | |
6072 | } | |
6073 | ||
6074 | /* Parse the operands for the opcode and find the opcode variant that | |
6075 | matches the specified operands, or NULL if no match is possible. */ | |
542d6675 KH |
6076 | |
6077 | static struct ia64_opcode * | |
5a49b8ac | 6078 | parse_operands (struct ia64_opcode *idesc) |
800eeca4 JW |
6079 | { |
6080 | int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0; | |
87f8eb97 | 6081 | int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0; |
4b09e828 JB |
6082 | int reg1, reg2; |
6083 | char reg_class; | |
800eeca4 | 6084 | enum ia64_opnd expected_operand = IA64_OPND_NIL; |
87f8eb97 | 6085 | enum operand_match_result result; |
800eeca4 JW |
6086 | char mnemonic[129]; |
6087 | char *first_arg = 0, *end, *saved_input_pointer; | |
6088 | unsigned int sof; | |
6089 | ||
9c2799c2 | 6090 | gas_assert (strlen (idesc->name) <= 128); |
800eeca4 JW |
6091 | |
6092 | strcpy (mnemonic, idesc->name); | |
60b9a617 JB |
6093 | if (idesc->operands[2] == IA64_OPND_SOF |
6094 | || idesc->operands[1] == IA64_OPND_SOF) | |
800eeca4 JW |
6095 | { |
6096 | /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we | |
6097 | can't parse the first operand until we have parsed the | |
6098 | remaining operands of the "alloc" instruction. */ | |
6099 | SKIP_WHITESPACE (); | |
6100 | first_arg = input_line_pointer; | |
6101 | end = strchr (input_line_pointer, '='); | |
6102 | if (!end) | |
6103 | { | |
ad4b42b4 | 6104 | as_bad (_("Expected separator `='")); |
800eeca4 JW |
6105 | return 0; |
6106 | } | |
6107 | input_line_pointer = end + 1; | |
6108 | ++i; | |
6109 | ++num_outputs; | |
6110 | } | |
6111 | ||
d3156ecc | 6112 | for (; ; ++i) |
800eeca4 | 6113 | { |
3739860c | 6114 | if (i < NELEMS (CURR_SLOT.opnd)) |
d3156ecc | 6115 | { |
cd42ff9c AM |
6116 | sep = parse_operand_maybe_eval (CURR_SLOT.opnd + i, '=', |
6117 | idesc->operands[i]); | |
d3156ecc JB |
6118 | if (CURR_SLOT.opnd[i].X_op == O_absent) |
6119 | break; | |
6120 | } | |
6121 | else | |
6122 | { | |
6123 | expressionS dummy; | |
6124 | ||
e4e8248d | 6125 | sep = parse_operand (&dummy, '='); |
d3156ecc JB |
6126 | if (dummy.X_op == O_absent) |
6127 | break; | |
6128 | } | |
800eeca4 JW |
6129 | |
6130 | ++num_operands; | |
6131 | ||
6132 | if (sep != '=' && sep != ',') | |
6133 | break; | |
6134 | ||
6135 | if (sep == '=') | |
6136 | { | |
6137 | if (num_outputs > 0) | |
ad4b42b4 | 6138 | as_bad (_("Duplicate equal sign (=) in instruction")); |
800eeca4 JW |
6139 | else |
6140 | num_outputs = i + 1; | |
6141 | } | |
6142 | } | |
6143 | if (sep != '\0') | |
6144 | { | |
ad4b42b4 | 6145 | as_bad (_("Illegal operand separator `%c'"), sep); |
800eeca4 JW |
6146 | return 0; |
6147 | } | |
197865e8 | 6148 | |
60b9a617 JB |
6149 | if (idesc->operands[2] == IA64_OPND_SOF |
6150 | || idesc->operands[1] == IA64_OPND_SOF) | |
800eeca4 | 6151 | { |
ef0241e7 JB |
6152 | /* Map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r. |
6153 | Note, however, that due to that mapping operand numbers in error | |
6154 | messages for any of the constant operands will not be correct. */ | |
800eeca4 | 6155 | know (strcmp (idesc->name, "alloc") == 0); |
ef0241e7 JB |
6156 | /* The first operand hasn't been parsed/initialized, yet (but |
6157 | num_operands intentionally doesn't account for that). */ | |
6158 | i = num_operands > 4 ? 2 : 1; | |
6159 | #define FORCE_CONST(n) (CURR_SLOT.opnd[n].X_op == O_constant \ | |
6160 | ? CURR_SLOT.opnd[n].X_add_number \ | |
6161 | : 0) | |
6162 | sof = set_regstack (FORCE_CONST(i), | |
6163 | FORCE_CONST(i + 1), | |
6164 | FORCE_CONST(i + 2), | |
6165 | FORCE_CONST(i + 3)); | |
6166 | #undef FORCE_CONST | |
6167 | ||
6168 | /* now we can parse the first arg: */ | |
6169 | saved_input_pointer = input_line_pointer; | |
6170 | input_line_pointer = first_arg; | |
cd42ff9c AM |
6171 | sep = parse_operand_maybe_eval (CURR_SLOT.opnd + 0, '=', |
6172 | idesc->operands[0]); | |
ef0241e7 JB |
6173 | if (sep != '=') |
6174 | --num_outputs; /* force error */ | |
6175 | input_line_pointer = saved_input_pointer; | |
6176 | ||
6177 | CURR_SLOT.opnd[i].X_add_number = sof; | |
6178 | if (CURR_SLOT.opnd[i + 1].X_op == O_constant | |
6179 | && CURR_SLOT.opnd[i + 2].X_op == O_constant) | |
6180 | CURR_SLOT.opnd[i + 1].X_add_number | |
6181 | = sof - CURR_SLOT.opnd[i + 2].X_add_number; | |
6182 | else | |
6183 | CURR_SLOT.opnd[i + 1].X_op = O_illegal; | |
6184 | CURR_SLOT.opnd[i + 2] = CURR_SLOT.opnd[i + 3]; | |
800eeca4 JW |
6185 | } |
6186 | ||
d3156ecc | 6187 | highest_unmatched_operand = -4; |
87f8eb97 JW |
6188 | curr_out_of_range_pos = -1; |
6189 | error_pos = 0; | |
800eeca4 JW |
6190 | for (; idesc; idesc = get_next_opcode (idesc)) |
6191 | { | |
6192 | if (num_outputs != idesc->num_outputs) | |
6193 | continue; /* mismatch in # of outputs */ | |
d3156ecc JB |
6194 | if (highest_unmatched_operand < 0) |
6195 | highest_unmatched_operand |= 1; | |
6196 | if (num_operands > NELEMS (idesc->operands) | |
6197 | || (num_operands < NELEMS (idesc->operands) | |
6198 | && idesc->operands[num_operands]) | |
6199 | || (num_operands > 0 && !idesc->operands[num_operands - 1])) | |
6200 | continue; /* mismatch in number of arguments */ | |
6201 | if (highest_unmatched_operand < 0) | |
6202 | highest_unmatched_operand |= 2; | |
800eeca4 JW |
6203 | |
6204 | CURR_SLOT.num_fixups = 0; | |
87f8eb97 JW |
6205 | |
6206 | /* Try to match all operands. If we see an out-of-range operand, | |
6207 | then continue trying to match the rest of the operands, since if | |
6208 | the rest match, then this idesc will give the best error message. */ | |
6209 | ||
6210 | out_of_range_pos = -1; | |
800eeca4 | 6211 | for (i = 0; i < num_operands && idesc->operands[i]; ++i) |
87f8eb97 JW |
6212 | { |
6213 | result = operand_match (idesc, i, CURR_SLOT.opnd + i); | |
6214 | if (result != OPERAND_MATCH) | |
6215 | { | |
6216 | if (result != OPERAND_OUT_OF_RANGE) | |
6217 | break; | |
6218 | if (out_of_range_pos < 0) | |
6219 | /* remember position of the first out-of-range operand: */ | |
6220 | out_of_range_pos = i; | |
6221 | } | |
6222 | } | |
800eeca4 | 6223 | |
87f8eb97 JW |
6224 | /* If we did not match all operands, or if at least one operand was |
6225 | out-of-range, then this idesc does not match. Keep track of which | |
6226 | idesc matched the most operands before failing. If we have two | |
6227 | idescs that failed at the same position, and one had an out-of-range | |
6228 | operand, then prefer the out-of-range operand. Thus if we have | |
6229 | "add r0=0x1000000,r1" we get an error saying the constant is out | |
6230 | of range instead of an error saying that the constant should have been | |
6231 | a register. */ | |
6232 | ||
6233 | if (i != num_operands || out_of_range_pos >= 0) | |
800eeca4 | 6234 | { |
87f8eb97 JW |
6235 | if (i > highest_unmatched_operand |
6236 | || (i == highest_unmatched_operand | |
6237 | && out_of_range_pos > curr_out_of_range_pos)) | |
800eeca4 JW |
6238 | { |
6239 | highest_unmatched_operand = i; | |
87f8eb97 JW |
6240 | if (out_of_range_pos >= 0) |
6241 | { | |
6242 | expected_operand = idesc->operands[out_of_range_pos]; | |
6243 | error_pos = out_of_range_pos; | |
6244 | } | |
6245 | else | |
6246 | { | |
6247 | expected_operand = idesc->operands[i]; | |
6248 | error_pos = i; | |
6249 | } | |
6250 | curr_out_of_range_pos = out_of_range_pos; | |
800eeca4 JW |
6251 | } |
6252 | continue; | |
6253 | } | |
6254 | ||
800eeca4 JW |
6255 | break; |
6256 | } | |
6257 | if (!idesc) | |
6258 | { | |
6259 | if (expected_operand) | |
ad4b42b4 | 6260 | as_bad (_("Operand %u of `%s' should be %s"), |
87f8eb97 | 6261 | error_pos + 1, mnemonic, |
800eeca4 | 6262 | elf64_ia64_operands[expected_operand].desc); |
d3156ecc | 6263 | else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 1)) |
ad4b42b4 | 6264 | as_bad (_("Wrong number of output operands")); |
d3156ecc | 6265 | else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 2)) |
ad4b42b4 | 6266 | as_bad (_("Wrong number of input operands")); |
800eeca4 | 6267 | else |
ad4b42b4 | 6268 | as_bad (_("Operand mismatch")); |
800eeca4 JW |
6269 | return 0; |
6270 | } | |
4b09e828 JB |
6271 | |
6272 | /* Check that the instruction doesn't use | |
6273 | - r0, f0, or f1 as output operands | |
6274 | - the same predicate twice as output operands | |
6275 | - r0 as address of a base update load or store | |
6276 | - the same GR as output and address of a base update load | |
6277 | - two even- or two odd-numbered FRs as output operands of a floating | |
6278 | point parallel load. | |
6279 | At most two (conflicting) output (or output-like) operands can exist, | |
6280 | (floating point parallel loads have three outputs, but the base register, | |
6281 | if updated, cannot conflict with the actual outputs). */ | |
6282 | reg2 = reg1 = -1; | |
6283 | for (i = 0; i < num_operands; ++i) | |
6284 | { | |
6285 | int regno = 0; | |
6286 | ||
6287 | reg_class = 0; | |
6288 | switch (idesc->operands[i]) | |
6289 | { | |
6290 | case IA64_OPND_R1: | |
6291 | case IA64_OPND_R2: | |
6292 | case IA64_OPND_R3: | |
6293 | if (i < num_outputs) | |
6294 | { | |
6295 | if (CURR_SLOT.opnd[i].X_add_number == REG_GR) | |
6296 | reg_class = 'r'; | |
6297 | else if (reg1 < 0) | |
6298 | reg1 = CURR_SLOT.opnd[i].X_add_number; | |
6299 | else if (reg2 < 0) | |
6300 | reg2 = CURR_SLOT.opnd[i].X_add_number; | |
6301 | } | |
6302 | break; | |
6303 | case IA64_OPND_P1: | |
6304 | case IA64_OPND_P2: | |
6305 | if (i < num_outputs) | |
6306 | { | |
6307 | if (reg1 < 0) | |
6308 | reg1 = CURR_SLOT.opnd[i].X_add_number; | |
6309 | else if (reg2 < 0) | |
6310 | reg2 = CURR_SLOT.opnd[i].X_add_number; | |
6311 | } | |
6312 | break; | |
6313 | case IA64_OPND_F1: | |
6314 | case IA64_OPND_F2: | |
6315 | case IA64_OPND_F3: | |
6316 | case IA64_OPND_F4: | |
6317 | if (i < num_outputs) | |
6318 | { | |
6319 | if (CURR_SLOT.opnd[i].X_add_number >= REG_FR | |
6320 | && CURR_SLOT.opnd[i].X_add_number <= REG_FR + 1) | |
6321 | { | |
6322 | reg_class = 'f'; | |
6323 | regno = CURR_SLOT.opnd[i].X_add_number - REG_FR; | |
6324 | } | |
6325 | else if (reg1 < 0) | |
6326 | reg1 = CURR_SLOT.opnd[i].X_add_number; | |
6327 | else if (reg2 < 0) | |
6328 | reg2 = CURR_SLOT.opnd[i].X_add_number; | |
6329 | } | |
6330 | break; | |
6331 | case IA64_OPND_MR3: | |
6332 | if (idesc->flags & IA64_OPCODE_POSTINC) | |
6333 | { | |
6334 | if (CURR_SLOT.opnd[i].X_add_number == REG_GR) | |
6335 | reg_class = 'm'; | |
6336 | else if (reg1 < 0) | |
6337 | reg1 = CURR_SLOT.opnd[i].X_add_number; | |
6338 | else if (reg2 < 0) | |
6339 | reg2 = CURR_SLOT.opnd[i].X_add_number; | |
6340 | } | |
6341 | break; | |
6342 | default: | |
6343 | break; | |
6344 | } | |
6345 | switch (reg_class) | |
6346 | { | |
6347 | case 0: | |
6348 | break; | |
6349 | default: | |
ad4b42b4 | 6350 | as_warn (_("Invalid use of `%c%d' as output operand"), reg_class, regno); |
4b09e828 JB |
6351 | break; |
6352 | case 'm': | |
ad4b42b4 | 6353 | as_warn (_("Invalid use of `r%d' as base update address operand"), regno); |
4b09e828 JB |
6354 | break; |
6355 | } | |
6356 | } | |
6357 | if (reg1 == reg2) | |
6358 | { | |
6359 | if (reg1 >= REG_GR && reg1 <= REG_GR + 127) | |
6360 | { | |
6361 | reg1 -= REG_GR; | |
6362 | reg_class = 'r'; | |
6363 | } | |
6364 | else if (reg1 >= REG_P && reg1 <= REG_P + 63) | |
6365 | { | |
6366 | reg1 -= REG_P; | |
6367 | reg_class = 'p'; | |
6368 | } | |
6369 | else if (reg1 >= REG_FR && reg1 <= REG_FR + 127) | |
6370 | { | |
6371 | reg1 -= REG_FR; | |
6372 | reg_class = 'f'; | |
6373 | } | |
6374 | else | |
6375 | reg_class = 0; | |
6376 | if (reg_class) | |
ad4b42b4 | 6377 | as_warn (_("Invalid duplicate use of `%c%d'"), reg_class, reg1); |
4b09e828 JB |
6378 | } |
6379 | else if (((reg1 >= REG_FR && reg1 <= REG_FR + 31 | |
6380 | && reg2 >= REG_FR && reg2 <= REG_FR + 31) | |
6381 | || (reg1 >= REG_FR + 32 && reg1 <= REG_FR + 127 | |
6382 | && reg2 >= REG_FR + 32 && reg2 <= REG_FR + 127)) | |
6383 | && ! ((reg1 ^ reg2) & 1)) | |
ad4b42b4 | 6384 | as_warn (_("Invalid simultaneous use of `f%d' and `f%d'"), |
4b09e828 JB |
6385 | reg1 - REG_FR, reg2 - REG_FR); |
6386 | else if ((reg1 >= REG_FR && reg1 <= REG_FR + 31 | |
6387 | && reg2 >= REG_FR + 32 && reg2 <= REG_FR + 127) | |
6388 | || (reg1 >= REG_FR + 32 && reg1 <= REG_FR + 127 | |
6389 | && reg2 >= REG_FR && reg2 <= REG_FR + 31)) | |
ad4b42b4 | 6390 | as_warn (_("Dangerous simultaneous use of `f%d' and `f%d'"), |
4b09e828 | 6391 | reg1 - REG_FR, reg2 - REG_FR); |
800eeca4 JW |
6392 | return idesc; |
6393 | } | |
6394 | ||
6395 | static void | |
5a49b8ac | 6396 | build_insn (struct slot *slot, bfd_vma *insnp) |
800eeca4 JW |
6397 | { |
6398 | const struct ia64_operand *odesc, *o2desc; | |
6399 | struct ia64_opcode *idesc = slot->idesc; | |
2132e3a3 AM |
6400 | bfd_vma insn; |
6401 | bfd_signed_vma val; | |
800eeca4 JW |
6402 | const char *err; |
6403 | int i; | |
6404 | ||
6405 | insn = idesc->opcode | slot->qp_regno; | |
6406 | ||
6407 | for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i) | |
6408 | { | |
c67e42c9 RH |
6409 | if (slot->opnd[i].X_op == O_register |
6410 | || slot->opnd[i].X_op == O_constant | |
6411 | || slot->opnd[i].X_op == O_index) | |
6412 | val = slot->opnd[i].X_add_number; | |
6413 | else if (slot->opnd[i].X_op == O_big) | |
800eeca4 | 6414 | { |
c67e42c9 | 6415 | /* This must be the value 0x10000000000000000. */ |
9c2799c2 | 6416 | gas_assert (idesc->operands[i] == IA64_OPND_IMM8M1U8); |
c67e42c9 RH |
6417 | val = 0; |
6418 | } | |
6419 | else | |
6420 | val = 0; | |
6421 | ||
6422 | switch (idesc->operands[i]) | |
6423 | { | |
6424 | case IA64_OPND_IMMU64: | |
800eeca4 JW |
6425 | *insnp++ = (val >> 22) & 0x1ffffffffffLL; |
6426 | insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27) | |
6427 | | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21) | |
6428 | | (((val >> 63) & 0x1) << 36)); | |
c67e42c9 RH |
6429 | continue; |
6430 | ||
6431 | case IA64_OPND_IMMU62: | |
542d6675 KH |
6432 | val &= 0x3fffffffffffffffULL; |
6433 | if (val != slot->opnd[i].X_add_number) | |
6434 | as_warn (_("Value truncated to 62 bits")); | |
6435 | *insnp++ = (val >> 21) & 0x1ffffffffffLL; | |
6436 | insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36)); | |
c67e42c9 | 6437 | continue; |
800eeca4 | 6438 | |
c67e42c9 RH |
6439 | case IA64_OPND_TGT64: |
6440 | val >>= 4; | |
6441 | *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2; | |
6442 | insn |= ((((val >> 59) & 0x1) << 36) | |
6443 | | (((val >> 0) & 0xfffff) << 13)); | |
6444 | continue; | |
800eeca4 | 6445 | |
c67e42c9 RH |
6446 | case IA64_OPND_AR3: |
6447 | val -= REG_AR; | |
6448 | break; | |
6449 | ||
6450 | case IA64_OPND_B1: | |
6451 | case IA64_OPND_B2: | |
6452 | val -= REG_BR; | |
6453 | break; | |
6454 | ||
6455 | case IA64_OPND_CR3: | |
6456 | val -= REG_CR; | |
6457 | break; | |
6458 | ||
b3e14eda L |
6459 | case IA64_OPND_DAHR3: |
6460 | val -= REG_DAHR; | |
6461 | break; | |
6462 | ||
c67e42c9 RH |
6463 | case IA64_OPND_F1: |
6464 | case IA64_OPND_F2: | |
6465 | case IA64_OPND_F3: | |
6466 | case IA64_OPND_F4: | |
6467 | val -= REG_FR; | |
6468 | break; | |
6469 | ||
6470 | case IA64_OPND_P1: | |
6471 | case IA64_OPND_P2: | |
6472 | val -= REG_P; | |
6473 | break; | |
6474 | ||
6475 | case IA64_OPND_R1: | |
6476 | case IA64_OPND_R2: | |
6477 | case IA64_OPND_R3: | |
6478 | case IA64_OPND_R3_2: | |
6479 | case IA64_OPND_CPUID_R3: | |
6480 | case IA64_OPND_DBR_R3: | |
6481 | case IA64_OPND_DTR_R3: | |
6482 | case IA64_OPND_ITR_R3: | |
6483 | case IA64_OPND_IBR_R3: | |
6484 | case IA64_OPND_MR3: | |
6485 | case IA64_OPND_MSR_R3: | |
6486 | case IA64_OPND_PKR_R3: | |
6487 | case IA64_OPND_PMC_R3: | |
6488 | case IA64_OPND_PMD_R3: | |
b3e14eda | 6489 | case IA64_OPND_DAHR_R3: |
197865e8 | 6490 | case IA64_OPND_RR_R3: |
c67e42c9 RH |
6491 | val -= REG_GR; |
6492 | break; | |
6493 | ||
6494 | default: | |
6495 | break; | |
6496 | } | |
6497 | ||
6498 | odesc = elf64_ia64_operands + idesc->operands[i]; | |
6499 | err = (*odesc->insert) (odesc, val, &insn); | |
6500 | if (err) | |
6501 | as_bad_where (slot->src_file, slot->src_line, | |
ad4b42b4 | 6502 | _("Bad operand value: %s"), err); |
c67e42c9 RH |
6503 | if (idesc->flags & IA64_OPCODE_PSEUDO) |
6504 | { | |
6505 | if ((idesc->flags & IA64_OPCODE_F2_EQ_F3) | |
6506 | && odesc == elf64_ia64_operands + IA64_OPND_F3) | |
6507 | { | |
6508 | o2desc = elf64_ia64_operands + IA64_OPND_F2; | |
6509 | (*o2desc->insert) (o2desc, val, &insn); | |
800eeca4 | 6510 | } |
c67e42c9 RH |
6511 | if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT) |
6512 | && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a | |
6513 | || odesc == elf64_ia64_operands + IA64_OPND_POS6)) | |
800eeca4 | 6514 | { |
c67e42c9 RH |
6515 | o2desc = elf64_ia64_operands + IA64_OPND_LEN6; |
6516 | (*o2desc->insert) (o2desc, 64 - val, &insn); | |
800eeca4 JW |
6517 | } |
6518 | } | |
6519 | } | |
6520 | *insnp = insn; | |
6521 | } | |
6522 | ||
6523 | static void | |
5a49b8ac | 6524 | emit_one_bundle (void) |
800eeca4 | 6525 | { |
f4660e2c | 6526 | int manual_bundling_off = 0, manual_bundling = 0; |
800eeca4 JW |
6527 | enum ia64_unit required_unit, insn_unit = 0; |
6528 | enum ia64_insn_type type[3], insn_type; | |
d3ce72d0 | 6529 | unsigned int template_val, orig_template; |
542d6675 | 6530 | bfd_vma insn[3] = { -1, -1, -1 }; |
800eeca4 JW |
6531 | struct ia64_opcode *idesc; |
6532 | int end_of_insn_group = 0, user_template = -1; | |
9b505842 | 6533 | int n, i, j, first, curr, last_slot; |
800eeca4 JW |
6534 | bfd_vma t0 = 0, t1 = 0; |
6535 | struct label_fix *lfix; | |
07a53e5c | 6536 | bfd_boolean mark_label; |
800eeca4 JW |
6537 | struct insn_fix *ifix; |
6538 | char mnemonic[16]; | |
6539 | fixS *fix; | |
6540 | char *f; | |
5a9ff93d | 6541 | int addr_mod; |
800eeca4 JW |
6542 | |
6543 | first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS; | |
c13781b8 | 6544 | know (first >= 0 && first < NUM_SLOTS); |
800eeca4 JW |
6545 | n = MIN (3, md.num_slots_in_use); |
6546 | ||
6547 | /* Determine template: user user_template if specified, best match | |
542d6675 | 6548 | otherwise: */ |
800eeca4 JW |
6549 | |
6550 | if (md.slot[first].user_template >= 0) | |
d3ce72d0 | 6551 | user_template = template_val = md.slot[first].user_template; |
800eeca4 JW |
6552 | else |
6553 | { | |
032efc85 | 6554 | /* Auto select appropriate template. */ |
800eeca4 JW |
6555 | memset (type, 0, sizeof (type)); |
6556 | curr = first; | |
6557 | for (i = 0; i < n; ++i) | |
6558 | { | |
032efc85 RH |
6559 | if (md.slot[curr].label_fixups && i != 0) |
6560 | break; | |
800eeca4 JW |
6561 | type[i] = md.slot[curr].idesc->type; |
6562 | curr = (curr + 1) % NUM_SLOTS; | |
6563 | } | |
d3ce72d0 | 6564 | template_val = best_template[type[0]][type[1]][type[2]]; |
800eeca4 JW |
6565 | } |
6566 | ||
542d6675 | 6567 | /* initialize instructions with appropriate nops: */ |
800eeca4 | 6568 | for (i = 0; i < 3; ++i) |
d3ce72d0 | 6569 | insn[i] = nop[ia64_templ_desc[template_val].exec_unit[i]]; |
800eeca4 JW |
6570 | |
6571 | f = frag_more (16); | |
6572 | ||
5a9ff93d JW |
6573 | /* Check to see if this bundle is at an offset that is a multiple of 16-bytes |
6574 | from the start of the frag. */ | |
6575 | addr_mod = frag_now_fix () & 15; | |
6576 | if (frag_now->has_code && frag_now->insn_addr != addr_mod) | |
6577 | as_bad (_("instruction address is not a multiple of 16")); | |
6578 | frag_now->insn_addr = addr_mod; | |
6579 | frag_now->has_code = 1; | |
6580 | ||
542d6675 | 6581 | /* now fill in slots with as many insns as possible: */ |
800eeca4 JW |
6582 | curr = first; |
6583 | idesc = md.slot[curr].idesc; | |
6584 | end_of_insn_group = 0; | |
9b505842 | 6585 | last_slot = -1; |
800eeca4 JW |
6586 | for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i) |
6587 | { | |
d6e78c11 | 6588 | /* If we have unwind records, we may need to update some now. */ |
75214fb0 JB |
6589 | unw_rec_list *ptr = md.slot[curr].unwind_record; |
6590 | unw_rec_list *end_ptr = NULL; | |
6591 | ||
d6e78c11 JW |
6592 | if (ptr) |
6593 | { | |
6594 | /* Find the last prologue/body record in the list for the current | |
6595 | insn, and set the slot number for all records up to that point. | |
6596 | This needs to be done now, because prologue/body records refer to | |
6597 | the current point, not the point after the instruction has been | |
6598 | issued. This matters because there may have been nops emitted | |
6599 | meanwhile. Any non-prologue non-body record followed by a | |
6600 | prologue/body record must also refer to the current point. */ | |
75214fb0 JB |
6601 | unw_rec_list *last_ptr; |
6602 | ||
6603 | for (j = 1; end_ptr == NULL && j < md.num_slots_in_use; ++j) | |
6604 | end_ptr = md.slot[(curr + j) % NUM_SLOTS].unwind_record; | |
6605 | for (last_ptr = NULL; ptr != end_ptr; ptr = ptr->next) | |
d6e78c11 JW |
6606 | if (ptr->r.type == prologue || ptr->r.type == prologue_gr |
6607 | || ptr->r.type == body) | |
6608 | last_ptr = ptr; | |
6609 | if (last_ptr) | |
6610 | { | |
6611 | /* Make last_ptr point one after the last prologue/body | |
6612 | record. */ | |
6613 | last_ptr = last_ptr->next; | |
6614 | for (ptr = md.slot[curr].unwind_record; ptr != last_ptr; | |
6615 | ptr = ptr->next) | |
6616 | { | |
6617 | ptr->slot_number = (unsigned long) f + i; | |
6618 | ptr->slot_frag = frag_now; | |
6619 | } | |
6620 | /* Remove the initialized records, so that we won't accidentally | |
6621 | update them again if we insert a nop and continue. */ | |
6622 | md.slot[curr].unwind_record = last_ptr; | |
6623 | } | |
6624 | } | |
e0c9811a | 6625 | |
f4660e2c JB |
6626 | manual_bundling_off = md.slot[curr].manual_bundling_off; |
6627 | if (md.slot[curr].manual_bundling_on) | |
800eeca4 | 6628 | { |
f4660e2c JB |
6629 | if (curr == first) |
6630 | manual_bundling = 1; | |
800eeca4 | 6631 | else |
f4660e2c JB |
6632 | break; /* Need to start a new bundle. */ |
6633 | } | |
6634 | ||
744b6414 JW |
6635 | /* If this instruction specifies a template, then it must be the first |
6636 | instruction of a bundle. */ | |
6637 | if (curr != first && md.slot[curr].user_template >= 0) | |
6638 | break; | |
6639 | ||
f4660e2c JB |
6640 | if (idesc->flags & IA64_OPCODE_SLOT2) |
6641 | { | |
6642 | if (manual_bundling && !manual_bundling_off) | |
6643 | { | |
6644 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6645 | _("`%s' must be last in bundle"), idesc->name); |
f4660e2c JB |
6646 | if (i < 2) |
6647 | manual_bundling = -1; /* Suppress meaningless post-loop errors. */ | |
6648 | } | |
6649 | i = 2; | |
800eeca4 JW |
6650 | } |
6651 | if (idesc->flags & IA64_OPCODE_LAST) | |
6652 | { | |
2434f565 JW |
6653 | int required_slot; |
6654 | unsigned int required_template; | |
800eeca4 JW |
6655 | |
6656 | /* If we need a stop bit after an M slot, our only choice is | |
6657 | template 5 (M;;MI). If we need a stop bit after a B | |
6658 | slot, our only choice is to place it at the end of the | |
6659 | bundle, because the only available templates are MIB, | |
6660 | MBB, BBB, MMB, and MFB. We don't handle anything other | |
6661 | than M and B slots because these are the only kind of | |
6662 | instructions that can have the IA64_OPCODE_LAST bit set. */ | |
d3ce72d0 | 6663 | required_template = template_val; |
800eeca4 JW |
6664 | switch (idesc->type) |
6665 | { | |
6666 | case IA64_TYPE_M: | |
6667 | required_slot = 0; | |
6668 | required_template = 5; | |
6669 | break; | |
6670 | ||
6671 | case IA64_TYPE_B: | |
6672 | required_slot = 2; | |
6673 | break; | |
6674 | ||
6675 | default: | |
6676 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 NC |
6677 | _("Internal error: don't know how to force %s to end of instruction group"), |
6678 | idesc->name); | |
800eeca4 JW |
6679 | required_slot = i; |
6680 | break; | |
6681 | } | |
f4660e2c JB |
6682 | if (manual_bundling |
6683 | && (i > required_slot | |
6684 | || (required_slot == 2 && !manual_bundling_off) | |
6685 | || (user_template >= 0 | |
6686 | /* Changing from MMI to M;MI is OK. */ | |
d3ce72d0 | 6687 | && (template_val ^ required_template) > 1))) |
f4660e2c JB |
6688 | { |
6689 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6690 | _("`%s' must be last in instruction group"), |
f4660e2c JB |
6691 | idesc->name); |
6692 | if (i < 2 && required_slot == 2 && !manual_bundling_off) | |
6693 | manual_bundling = -1; /* Suppress meaningless post-loop errors. */ | |
6694 | } | |
800eeca4 JW |
6695 | if (required_slot < i) |
6696 | /* Can't fit this instruction. */ | |
6697 | break; | |
6698 | ||
6699 | i = required_slot; | |
d3ce72d0 | 6700 | if (required_template != template_val) |
800eeca4 JW |
6701 | { |
6702 | /* If we switch the template, we need to reset the NOPs | |
6703 | after slot i. The slot-types of the instructions ahead | |
6704 | of i never change, so we don't need to worry about | |
6705 | changing NOPs in front of this slot. */ | |
6706 | for (j = i; j < 3; ++j) | |
6707 | insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]]; | |
53022e4a JW |
6708 | |
6709 | /* We just picked a template that includes the stop bit in the | |
6710 | middle, so we don't need another one emitted later. */ | |
6711 | md.slot[curr].end_of_insn_group = 0; | |
800eeca4 | 6712 | } |
d3ce72d0 | 6713 | template_val = required_template; |
800eeca4 JW |
6714 | } |
6715 | if (curr != first && md.slot[curr].label_fixups) | |
6716 | { | |
f4660e2c JB |
6717 | if (manual_bundling) |
6718 | { | |
6719 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6720 | _("Label must be first in a bundle")); |
f4660e2c JB |
6721 | manual_bundling = -1; /* Suppress meaningless post-loop errors. */ |
6722 | } | |
800eeca4 JW |
6723 | /* This insn must go into the first slot of a bundle. */ |
6724 | break; | |
6725 | } | |
6726 | ||
800eeca4 JW |
6727 | if (end_of_insn_group && md.num_slots_in_use >= 1) |
6728 | { | |
6729 | /* We need an instruction group boundary in the middle of a | |
6730 | bundle. See if we can switch to an other template with | |
6731 | an appropriate boundary. */ | |
6732 | ||
d3ce72d0 | 6733 | orig_template = template_val; |
800eeca4 JW |
6734 | if (i == 1 && (user_template == 4 |
6735 | || (user_template < 0 | |
d3ce72d0 | 6736 | && (ia64_templ_desc[template_val].exec_unit[0] |
800eeca4 JW |
6737 | == IA64_UNIT_M)))) |
6738 | { | |
d3ce72d0 | 6739 | template_val = 5; |
800eeca4 JW |
6740 | end_of_insn_group = 0; |
6741 | } | |
6742 | else if (i == 2 && (user_template == 0 | |
6743 | || (user_template < 0 | |
d3ce72d0 | 6744 | && (ia64_templ_desc[template_val].exec_unit[1] |
800eeca4 JW |
6745 | == IA64_UNIT_I))) |
6746 | /* This test makes sure we don't switch the template if | |
6747 | the next instruction is one that needs to be first in | |
6748 | an instruction group. Since all those instructions are | |
6749 | in the M group, there is no way such an instruction can | |
6750 | fit in this bundle even if we switch the template. The | |
6751 | reason we have to check for this is that otherwise we | |
6752 | may end up generating "MI;;I M.." which has the deadly | |
6753 | effect that the second M instruction is no longer the | |
f4660e2c | 6754 | first in the group! --davidm 99/12/16 */ |
800eeca4 JW |
6755 | && (idesc->flags & IA64_OPCODE_FIRST) == 0) |
6756 | { | |
d3ce72d0 | 6757 | template_val = 1; |
800eeca4 JW |
6758 | end_of_insn_group = 0; |
6759 | } | |
f4660e2c JB |
6760 | else if (i == 1 |
6761 | && user_template == 0 | |
6762 | && !(idesc->flags & IA64_OPCODE_FIRST)) | |
6763 | /* Use the next slot. */ | |
6764 | continue; | |
800eeca4 JW |
6765 | else if (curr != first) |
6766 | /* can't fit this insn */ | |
6767 | break; | |
6768 | ||
d3ce72d0 | 6769 | if (template_val != orig_template) |
800eeca4 JW |
6770 | /* if we switch the template, we need to reset the NOPs |
6771 | after slot i. The slot-types of the instructions ahead | |
6772 | of i never change, so we don't need to worry about | |
6773 | changing NOPs in front of this slot. */ | |
6774 | for (j = i; j < 3; ++j) | |
d3ce72d0 | 6775 | insn[j] = nop[ia64_templ_desc[template_val].exec_unit[j]]; |
800eeca4 | 6776 | } |
d3ce72d0 | 6777 | required_unit = ia64_templ_desc[template_val].exec_unit[i]; |
800eeca4 | 6778 | |
c10d9d8f | 6779 | /* resolve dynamic opcodes such as "break", "hint", and "nop": */ |
800eeca4 JW |
6780 | if (idesc->type == IA64_TYPE_DYN) |
6781 | { | |
97762d08 JB |
6782 | enum ia64_opnd opnd1, opnd2; |
6783 | ||
800eeca4 JW |
6784 | if ((strcmp (idesc->name, "nop") == 0) |
6785 | || (strcmp (idesc->name, "break") == 0)) | |
6786 | insn_unit = required_unit; | |
91d777ee L |
6787 | else if (strcmp (idesc->name, "hint") == 0) |
6788 | { | |
6789 | insn_unit = required_unit; | |
6790 | if (required_unit == IA64_UNIT_B) | |
6791 | { | |
6792 | switch (md.hint_b) | |
6793 | { | |
6794 | case hint_b_ok: | |
6795 | break; | |
6796 | case hint_b_warning: | |
ad4b42b4 | 6797 | as_warn (_("hint in B unit may be treated as nop")); |
91d777ee L |
6798 | break; |
6799 | case hint_b_error: | |
6800 | /* When manual bundling is off and there is no | |
6801 | user template, we choose a different unit so | |
6802 | that hint won't go into the current slot. We | |
6803 | will fill the current bundle with nops and | |
6804 | try to put hint into the next bundle. */ | |
6805 | if (!manual_bundling && user_template < 0) | |
6806 | insn_unit = IA64_UNIT_I; | |
6807 | else | |
ad4b42b4 | 6808 | as_bad (_("hint in B unit can't be used")); |
91d777ee L |
6809 | break; |
6810 | } | |
6811 | } | |
6812 | } | |
97762d08 JB |
6813 | else if (strcmp (idesc->name, "chk.s") == 0 |
6814 | || strcmp (idesc->name, "mov") == 0) | |
800eeca4 JW |
6815 | { |
6816 | insn_unit = IA64_UNIT_M; | |
97762d08 | 6817 | if (required_unit == IA64_UNIT_I |
d3ce72d0 | 6818 | || (required_unit == IA64_UNIT_F && template_val == 6)) |
800eeca4 JW |
6819 | insn_unit = IA64_UNIT_I; |
6820 | } | |
6821 | else | |
ad4b42b4 | 6822 | as_fatal (_("emit_one_bundle: unexpected dynamic op")); |
800eeca4 | 6823 | |
f9f21a03 L |
6824 | snprintf (mnemonic, sizeof (mnemonic), "%s.%c", |
6825 | idesc->name, "?imbfxx"[insn_unit]); | |
97762d08 JB |
6826 | opnd1 = idesc->operands[0]; |
6827 | opnd2 = idesc->operands[1]; | |
3d56ab85 | 6828 | ia64_free_opcode (idesc); |
97762d08 JB |
6829 | idesc = ia64_find_opcode (mnemonic); |
6830 | /* moves to/from ARs have collisions */ | |
6831 | if (opnd1 == IA64_OPND_AR3 || opnd2 == IA64_OPND_AR3) | |
6832 | { | |
6833 | while (idesc != NULL | |
6834 | && (idesc->operands[0] != opnd1 | |
6835 | || idesc->operands[1] != opnd2)) | |
6836 | idesc = get_next_opcode (idesc); | |
6837 | } | |
97762d08 | 6838 | md.slot[curr].idesc = idesc; |
800eeca4 JW |
6839 | } |
6840 | else | |
6841 | { | |
6842 | insn_type = idesc->type; | |
6843 | insn_unit = IA64_UNIT_NIL; | |
6844 | switch (insn_type) | |
6845 | { | |
6846 | case IA64_TYPE_A: | |
6847 | if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M) | |
6848 | insn_unit = required_unit; | |
6849 | break; | |
542d6675 | 6850 | case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break; |
800eeca4 JW |
6851 | case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break; |
6852 | case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break; | |
6853 | case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break; | |
6854 | case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break; | |
6855 | default: break; | |
6856 | } | |
6857 | } | |
6858 | ||
6859 | if (insn_unit != required_unit) | |
9b505842 | 6860 | continue; /* Try next slot. */ |
800eeca4 | 6861 | |
07a53e5c RH |
6862 | /* Now is a good time to fix up the labels for this insn. */ |
6863 | mark_label = FALSE; | |
6864 | for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next) | |
6865 | { | |
6866 | S_SET_VALUE (lfix->sym, frag_now_fix () - 16); | |
6867 | symbol_set_frag (lfix->sym, frag_now); | |
6868 | mark_label |= lfix->dw2_mark_labels; | |
6869 | } | |
6870 | for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next) | |
6871 | { | |
6872 | S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i); | |
6873 | symbol_set_frag (lfix->sym, frag_now); | |
6874 | } | |
6875 | ||
6876 | if (debug_type == DEBUG_DWARF2 | |
6877 | || md.slot[curr].loc_directive_seen | |
6878 | || mark_label) | |
196e8040 JW |
6879 | { |
6880 | bfd_vma addr = frag_now->fr_address + frag_now_fix () - 16 + i; | |
800eeca4 | 6881 | |
196e8040 | 6882 | md.slot[curr].loc_directive_seen = 0; |
07a53e5c RH |
6883 | if (mark_label) |
6884 | md.slot[curr].debug_line.flags |= DWARF2_FLAG_BASIC_BLOCK; | |
6885 | ||
196e8040 JW |
6886 | dwarf2_gen_line_info (addr, &md.slot[curr].debug_line); |
6887 | } | |
800eeca4 JW |
6888 | |
6889 | build_insn (md.slot + curr, insn + i); | |
6890 | ||
d6e78c11 JW |
6891 | ptr = md.slot[curr].unwind_record; |
6892 | if (ptr) | |
6893 | { | |
6894 | /* Set slot numbers for all remaining unwind records belonging to the | |
6895 | current insn. There can not be any prologue/body unwind records | |
6896 | here. */ | |
d6e78c11 JW |
6897 | for (; ptr != end_ptr; ptr = ptr->next) |
6898 | { | |
6899 | ptr->slot_number = (unsigned long) f + i; | |
6900 | ptr->slot_frag = frag_now; | |
6901 | } | |
6902 | md.slot[curr].unwind_record = NULL; | |
6903 | } | |
10850f29 | 6904 | |
800eeca4 JW |
6905 | for (j = 0; j < md.slot[curr].num_fixups; ++j) |
6906 | { | |
6907 | ifix = md.slot[curr].fixup + j; | |
5a080f89 | 6908 | fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8, |
800eeca4 JW |
6909 | &ifix->expr, ifix->is_pcrel, ifix->code); |
6910 | fix->tc_fix_data.opnd = ifix->opnd; | |
800eeca4 JW |
6911 | fix->fx_file = md.slot[curr].src_file; |
6912 | fix->fx_line = md.slot[curr].src_line; | |
6913 | } | |
6914 | ||
6915 | end_of_insn_group = md.slot[curr].end_of_insn_group; | |
6916 | ||
9699c833 TG |
6917 | /* This adjustment to "i" must occur after the fix, otherwise the fix |
6918 | is assigned to the wrong slot, and the VMS linker complains. */ | |
6919 | if (required_unit == IA64_UNIT_L) | |
6920 | { | |
6921 | know (i == 1); | |
6922 | /* skip one slot for long/X-unit instructions */ | |
6923 | ++i; | |
6924 | } | |
6925 | --md.num_slots_in_use; | |
6926 | last_slot = i; | |
6927 | ||
542d6675 | 6928 | /* clear slot: */ |
800eeca4 JW |
6929 | ia64_free_opcode (md.slot[curr].idesc); |
6930 | memset (md.slot + curr, 0, sizeof (md.slot[curr])); | |
6931 | md.slot[curr].user_template = -1; | |
6932 | ||
6933 | if (manual_bundling_off) | |
6934 | { | |
6935 | manual_bundling = 0; | |
6936 | break; | |
6937 | } | |
6938 | curr = (curr + 1) % NUM_SLOTS; | |
6939 | idesc = md.slot[curr].idesc; | |
6940 | } | |
6abae71c JW |
6941 | |
6942 | /* A user template was specified, but the first following instruction did | |
6943 | not fit. This can happen with or without manual bundling. */ | |
6944 | if (md.num_slots_in_use > 0 && last_slot < 0) | |
6945 | { | |
6946 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6947 | _("`%s' does not fit into %s template"), |
d3ce72d0 | 6948 | idesc->name, ia64_templ_desc[template_val].name); |
6abae71c JW |
6949 | /* Drop first insn so we don't livelock. */ |
6950 | --md.num_slots_in_use; | |
6951 | know (curr == first); | |
6952 | ia64_free_opcode (md.slot[curr].idesc); | |
6953 | memset (md.slot + curr, 0, sizeof (md.slot[curr])); | |
6954 | md.slot[curr].user_template = -1; | |
6955 | } | |
6956 | else if (manual_bundling > 0) | |
800eeca4 JW |
6957 | { |
6958 | if (md.num_slots_in_use > 0) | |
ac025970 | 6959 | { |
9b505842 JB |
6960 | if (last_slot >= 2) |
6961 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6962 | _("`%s' does not fit into bundle"), idesc->name); |
9b505842 JB |
6963 | else |
6964 | { | |
6965 | const char *where; | |
6966 | ||
d3ce72d0 | 6967 | if (template_val == 2) |
9b505842 JB |
6968 | where = "X slot"; |
6969 | else if (last_slot == 0) | |
6970 | where = "slots 2 or 3"; | |
6971 | else | |
6972 | where = "slot 3"; | |
6973 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6974 | _("`%s' can't go in %s of %s template"), |
d3ce72d0 | 6975 | idesc->name, where, ia64_templ_desc[template_val].name); |
9b505842 | 6976 | } |
ac025970 | 6977 | } |
800eeca4 JW |
6978 | else |
6979 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6980 | _("Missing '}' at end of file")); |
800eeca4 | 6981 | } |
3739860c | 6982 | |
800eeca4 JW |
6983 | know (md.num_slots_in_use < NUM_SLOTS); |
6984 | ||
d3ce72d0 | 6985 | t0 = end_of_insn_group | (template_val << 1) | (insn[0] << 5) | (insn[1] << 46); |
800eeca4 JW |
6986 | t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23); |
6987 | ||
44f5c83a JW |
6988 | number_to_chars_littleendian (f + 0, t0, 8); |
6989 | number_to_chars_littleendian (f + 8, t1, 8); | |
800eeca4 JW |
6990 | } |
6991 | ||
6992 | int | |
5a49b8ac | 6993 | md_parse_option (int c, char *arg) |
800eeca4 | 6994 | { |
7463c317 | 6995 | |
800eeca4 JW |
6996 | switch (c) |
6997 | { | |
c43c2cc5 | 6998 | /* Switches from the Intel assembler. */ |
44f5c83a | 6999 | case 'm': |
800eeca4 JW |
7000 | if (strcmp (arg, "ilp64") == 0 |
7001 | || strcmp (arg, "lp64") == 0 | |
7002 | || strcmp (arg, "p64") == 0) | |
7003 | { | |
7004 | md.flags |= EF_IA_64_ABI64; | |
7005 | } | |
7006 | else if (strcmp (arg, "ilp32") == 0) | |
7007 | { | |
7008 | md.flags &= ~EF_IA_64_ABI64; | |
7009 | } | |
7010 | else if (strcmp (arg, "le") == 0) | |
7011 | { | |
7012 | md.flags &= ~EF_IA_64_BE; | |
549f748d | 7013 | default_big_endian = 0; |
800eeca4 JW |
7014 | } |
7015 | else if (strcmp (arg, "be") == 0) | |
7016 | { | |
7017 | md.flags |= EF_IA_64_BE; | |
549f748d | 7018 | default_big_endian = 1; |
800eeca4 | 7019 | } |
970d6792 L |
7020 | else if (strncmp (arg, "unwind-check=", 13) == 0) |
7021 | { | |
7022 | arg += 13; | |
7023 | if (strcmp (arg, "warning") == 0) | |
7024 | md.unwind_check = unwind_check_warning; | |
7025 | else if (strcmp (arg, "error") == 0) | |
7026 | md.unwind_check = unwind_check_error; | |
7027 | else | |
7028 | return 0; | |
7029 | } | |
91d777ee L |
7030 | else if (strncmp (arg, "hint.b=", 7) == 0) |
7031 | { | |
7032 | arg += 7; | |
7033 | if (strcmp (arg, "ok") == 0) | |
7034 | md.hint_b = hint_b_ok; | |
7035 | else if (strcmp (arg, "warning") == 0) | |
7036 | md.hint_b = hint_b_warning; | |
7037 | else if (strcmp (arg, "error") == 0) | |
7038 | md.hint_b = hint_b_error; | |
7039 | else | |
7040 | return 0; | |
7041 | } | |
8c2fda1d L |
7042 | else if (strncmp (arg, "tune=", 5) == 0) |
7043 | { | |
7044 | arg += 5; | |
7045 | if (strcmp (arg, "itanium1") == 0) | |
7046 | md.tune = itanium1; | |
7047 | else if (strcmp (arg, "itanium2") == 0) | |
7048 | md.tune = itanium2; | |
7049 | else | |
7050 | return 0; | |
7051 | } | |
800eeca4 JW |
7052 | else |
7053 | return 0; | |
7054 | break; | |
7055 | ||
7056 | case 'N': | |
7057 | if (strcmp (arg, "so") == 0) | |
7058 | { | |
542d6675 | 7059 | /* Suppress signon message. */ |
800eeca4 JW |
7060 | } |
7061 | else if (strcmp (arg, "pi") == 0) | |
7062 | { | |
7063 | /* Reject privileged instructions. FIXME */ | |
7064 | } | |
7065 | else if (strcmp (arg, "us") == 0) | |
7066 | { | |
7067 | /* Allow union of signed and unsigned range. FIXME */ | |
7068 | } | |
7069 | else if (strcmp (arg, "close_fcalls") == 0) | |
7070 | { | |
7071 | /* Do not resolve global function calls. */ | |
7072 | } | |
7073 | else | |
7074 | return 0; | |
7075 | break; | |
7076 | ||
7077 | case 'C': | |
7078 | /* temp[="prefix"] Insert temporary labels into the object file | |
7079 | symbol table prefixed by "prefix". | |
7080 | Default prefix is ":temp:". | |
7081 | */ | |
7082 | break; | |
7083 | ||
7084 | case 'a': | |
800eeca4 JW |
7085 | /* indirect=<tgt> Assume unannotated indirect branches behavior |
7086 | according to <tgt> -- | |
7087 | exit: branch out from the current context (default) | |
7088 | labels: all labels in context may be branch targets | |
7089 | */ | |
85b40035 L |
7090 | if (strncmp (arg, "indirect=", 9) != 0) |
7091 | return 0; | |
800eeca4 JW |
7092 | break; |
7093 | ||
7094 | case 'x': | |
7095 | /* -X conflicts with an ignored option, use -x instead */ | |
7096 | md.detect_dv = 1; | |
7097 | if (!arg || strcmp (arg, "explicit") == 0) | |
542d6675 KH |
7098 | { |
7099 | /* set default mode to explicit */ | |
7100 | md.default_explicit_mode = 1; | |
7101 | break; | |
7102 | } | |
800eeca4 | 7103 | else if (strcmp (arg, "auto") == 0) |
542d6675 KH |
7104 | { |
7105 | md.default_explicit_mode = 0; | |
7106 | } | |
f1dab70d JB |
7107 | else if (strcmp (arg, "none") == 0) |
7108 | { | |
7109 | md.detect_dv = 0; | |
7110 | } | |
800eeca4 | 7111 | else if (strcmp (arg, "debug") == 0) |
542d6675 KH |
7112 | { |
7113 | md.debug_dv = 1; | |
7114 | } | |
800eeca4 | 7115 | else if (strcmp (arg, "debugx") == 0) |
542d6675 KH |
7116 | { |
7117 | md.default_explicit_mode = 1; | |
7118 | md.debug_dv = 1; | |
7119 | } | |
f1dab70d JB |
7120 | else if (strcmp (arg, "debugn") == 0) |
7121 | { | |
7122 | md.debug_dv = 1; | |
7123 | md.detect_dv = 0; | |
7124 | } | |
800eeca4 | 7125 | else |
542d6675 KH |
7126 | { |
7127 | as_bad (_("Unrecognized option '-x%s'"), arg); | |
7128 | } | |
800eeca4 JW |
7129 | break; |
7130 | ||
7131 | case 'S': | |
7132 | /* nops Print nops statistics. */ | |
7133 | break; | |
7134 | ||
c43c2cc5 JW |
7135 | /* GNU specific switches for gcc. */ |
7136 | case OPTION_MCONSTANT_GP: | |
7137 | md.flags |= EF_IA_64_CONS_GP; | |
7138 | break; | |
7139 | ||
7140 | case OPTION_MAUTO_PIC: | |
7141 | md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP; | |
7142 | break; | |
7143 | ||
800eeca4 JW |
7144 | default: |
7145 | return 0; | |
7146 | } | |
7147 | ||
7148 | return 1; | |
7149 | } | |
7150 | ||
7151 | void | |
5a49b8ac | 7152 | md_show_usage (FILE *stream) |
800eeca4 | 7153 | { |
542d6675 | 7154 | fputs (_("\ |
800eeca4 | 7155 | IA-64 options:\n\ |
6290819d NC |
7156 | --mconstant-gp mark output file as using the constant-GP model\n\ |
7157 | (sets ELF header flag EF_IA_64_CONS_GP)\n\ | |
7158 | --mauto-pic mark output file as using the constant-GP model\n\ | |
7159 | without function descriptors (sets ELF header flag\n\ | |
7160 | EF_IA_64_NOFUNCDESC_CONS_GP)\n\ | |
44f5c83a JW |
7161 | -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\ |
7162 | -mle | -mbe select little- or big-endian byte order (default -mle)\n\ | |
8c2fda1d L |
7163 | -mtune=[itanium1|itanium2]\n\ |
7164 | tune for a specific CPU (default -mtune=itanium2)\n\ | |
970d6792 L |
7165 | -munwind-check=[warning|error]\n\ |
7166 | unwind directive check (default -munwind-check=warning)\n\ | |
91d777ee L |
7167 | -mhint.b=[ok|warning|error]\n\ |
7168 | hint.b check (default -mhint.b=error)\n\ | |
a1727c1a NC |
7169 | -x | -xexplicit turn on dependency violation checking\n"), stream); |
7170 | /* Note for translators: "automagically" can be translated as "automatically" here. */ | |
7171 | fputs (_("\ | |
f1dab70d JB |
7172 | -xauto automagically remove dependency violations (default)\n\ |
7173 | -xnone turn off dependency violation checking\n\ | |
7174 | -xdebug debug dependency violation checker\n\ | |
7175 | -xdebugn debug dependency violation checker but turn off\n\ | |
7176 | dependency violation checking\n\ | |
7177 | -xdebugx debug dependency violation checker and turn on\n\ | |
7178 | dependency violation checking\n"), | |
800eeca4 JW |
7179 | stream); |
7180 | } | |
7181 | ||
acebd4ce | 7182 | void |
5a49b8ac | 7183 | ia64_after_parse_args (void) |
acebd4ce AS |
7184 | { |
7185 | if (debug_type == DEBUG_STABS) | |
7186 | as_fatal (_("--gstabs is not supported for ia64")); | |
7187 | } | |
7188 | ||
44576e1f RH |
7189 | /* Return true if TYPE fits in TEMPL at SLOT. */ |
7190 | ||
7191 | static int | |
800eeca4 JW |
7192 | match (int templ, int type, int slot) |
7193 | { | |
7194 | enum ia64_unit unit; | |
7195 | int result; | |
7196 | ||
7197 | unit = ia64_templ_desc[templ].exec_unit[slot]; | |
7198 | switch (type) | |
7199 | { | |
7200 | case IA64_TYPE_DYN: result = 1; break; /* for nop and break */ | |
7201 | case IA64_TYPE_A: | |
7202 | result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M); | |
7203 | break; | |
7204 | case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break; | |
7205 | case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break; | |
7206 | case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break; | |
7207 | case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break; | |
7208 | case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break; | |
7209 | default: result = 0; break; | |
7210 | } | |
7211 | return result; | |
7212 | } | |
7213 | ||
7c06efaa JW |
7214 | /* For Itanium 1, add a bit of extra goodness if a nop of type F or B would fit |
7215 | in TEMPL at SLOT. For Itanium 2, add a bit of extra goodness if a nop of | |
7216 | type M or I would fit in TEMPL at SLOT. */ | |
44576e1f RH |
7217 | |
7218 | static inline int | |
7219 | extra_goodness (int templ, int slot) | |
7220 | { | |
8c2fda1d L |
7221 | switch (md.tune) |
7222 | { | |
7223 | case itanium1: | |
7224 | if (slot == 1 && match (templ, IA64_TYPE_F, slot)) | |
7225 | return 2; | |
7226 | else if (slot == 2 && match (templ, IA64_TYPE_B, slot)) | |
7227 | return 1; | |
7228 | else | |
7229 | return 0; | |
7230 | break; | |
7231 | case itanium2: | |
7232 | if (match (templ, IA64_TYPE_M, slot) | |
7233 | || match (templ, IA64_TYPE_I, slot)) | |
7234 | /* Favor M- and I-unit NOPs. We definitely want to avoid | |
7235 | F-unit and B-unit may cause split-issue or less-than-optimal | |
7236 | branch-prediction. */ | |
7237 | return 2; | |
7238 | else | |
7239 | return 0; | |
7240 | break; | |
7241 | default: | |
7242 | abort (); | |
7243 | return 0; | |
7244 | } | |
44576e1f RH |
7245 | } |
7246 | ||
800eeca4 JW |
7247 | /* This function is called once, at assembler startup time. It sets |
7248 | up all the tables, etc. that the MD part of the assembler will need | |
7249 | that can be determined before arguments are parsed. */ | |
7250 | void | |
5a49b8ac | 7251 | md_begin (void) |
800eeca4 | 7252 | { |
8b84be9d | 7253 | int i, j, k, t, goodness, best, ok; |
800eeca4 JW |
7254 | const char *err; |
7255 | char name[8]; | |
7256 | ||
7257 | md.auto_align = 1; | |
7258 | md.explicit_mode = md.default_explicit_mode; | |
7259 | ||
7260 | bfd_set_section_alignment (stdoutput, text_section, 4); | |
7261 | ||
0234cb7c | 7262 | /* Make sure function pointers get initialized. */ |
10a98291 | 7263 | target_big_endian = -1; |
549f748d | 7264 | dot_byteorder (default_big_endian); |
10a98291 | 7265 | |
35f5df7f L |
7266 | alias_hash = hash_new (); |
7267 | alias_name_hash = hash_new (); | |
7268 | secalias_hash = hash_new (); | |
7269 | secalias_name_hash = hash_new (); | |
7270 | ||
13ae64f3 JJ |
7271 | pseudo_func[FUNC_DTP_MODULE].u.sym = |
7272 | symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE, | |
7273 | &zero_address_frag); | |
7274 | ||
7275 | pseudo_func[FUNC_DTP_RELATIVE].u.sym = | |
7276 | symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE, | |
7277 | &zero_address_frag); | |
7278 | ||
800eeca4 | 7279 | pseudo_func[FUNC_FPTR_RELATIVE].u.sym = |
542d6675 KH |
7280 | symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE, |
7281 | &zero_address_frag); | |
800eeca4 JW |
7282 | |
7283 | pseudo_func[FUNC_GP_RELATIVE].u.sym = | |
542d6675 KH |
7284 | symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE, |
7285 | &zero_address_frag); | |
800eeca4 JW |
7286 | |
7287 | pseudo_func[FUNC_LT_RELATIVE].u.sym = | |
542d6675 KH |
7288 | symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE, |
7289 | &zero_address_frag); | |
800eeca4 | 7290 | |
fa2c7eff RH |
7291 | pseudo_func[FUNC_LT_RELATIVE_X].u.sym = |
7292 | symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X, | |
7293 | &zero_address_frag); | |
7294 | ||
c67e42c9 | 7295 | pseudo_func[FUNC_PC_RELATIVE].u.sym = |
542d6675 KH |
7296 | symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE, |
7297 | &zero_address_frag); | |
c67e42c9 | 7298 | |
800eeca4 | 7299 | pseudo_func[FUNC_PLT_RELATIVE].u.sym = |
542d6675 KH |
7300 | symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE, |
7301 | &zero_address_frag); | |
800eeca4 JW |
7302 | |
7303 | pseudo_func[FUNC_SEC_RELATIVE].u.sym = | |
542d6675 KH |
7304 | symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE, |
7305 | &zero_address_frag); | |
800eeca4 JW |
7306 | |
7307 | pseudo_func[FUNC_SEG_RELATIVE].u.sym = | |
542d6675 KH |
7308 | symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE, |
7309 | &zero_address_frag); | |
800eeca4 | 7310 | |
13ae64f3 JJ |
7311 | pseudo_func[FUNC_TP_RELATIVE].u.sym = |
7312 | symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE, | |
7313 | &zero_address_frag); | |
7314 | ||
800eeca4 | 7315 | pseudo_func[FUNC_LTV_RELATIVE].u.sym = |
542d6675 KH |
7316 | symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE, |
7317 | &zero_address_frag); | |
800eeca4 JW |
7318 | |
7319 | pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym = | |
542d6675 KH |
7320 | symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE, |
7321 | &zero_address_frag); | |
800eeca4 | 7322 | |
13ae64f3 JJ |
7323 | pseudo_func[FUNC_LT_DTP_MODULE].u.sym = |
7324 | symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE, | |
7325 | &zero_address_frag); | |
7326 | ||
7327 | pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym = | |
7328 | symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE, | |
7329 | &zero_address_frag); | |
7330 | ||
7331 | pseudo_func[FUNC_LT_TP_RELATIVE].u.sym = | |
7332 | symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE, | |
7333 | &zero_address_frag); | |
7334 | ||
3969b680 RH |
7335 | pseudo_func[FUNC_IPLT_RELOC].u.sym = |
7336 | symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC, | |
7337 | &zero_address_frag); | |
7338 | ||
9d0e8497 TG |
7339 | #ifdef TE_VMS |
7340 | pseudo_func[FUNC_SLOTCOUNT_RELOC].u.sym = | |
7341 | symbol_new (".<slotcount>", undefined_section, FUNC_SLOTCOUNT_RELOC, | |
7342 | &zero_address_frag); | |
7343 | #endif | |
7344 | ||
f6fe78d6 JW |
7345 | if (md.tune != itanium1) |
7346 | { | |
7347 | /* Convert MFI NOPs bundles into MMI NOPs bundles. */ | |
7348 | le_nop[0] = 0x8; | |
7349 | le_nop_stop[0] = 0x9; | |
7350 | } | |
7351 | ||
197865e8 | 7352 | /* Compute the table of best templates. We compute goodness as a |
8c2fda1d L |
7353 | base 4 value, in which each match counts for 3. Match-failures |
7354 | result in NOPs and we use extra_goodness() to pick the execution | |
7355 | units that are best suited for issuing the NOP. */ | |
800eeca4 JW |
7356 | for (i = 0; i < IA64_NUM_TYPES; ++i) |
7357 | for (j = 0; j < IA64_NUM_TYPES; ++j) | |
7358 | for (k = 0; k < IA64_NUM_TYPES; ++k) | |
7359 | { | |
7360 | best = 0; | |
7361 | for (t = 0; t < NELEMS (ia64_templ_desc); ++t) | |
7362 | { | |
7363 | goodness = 0; | |
7364 | if (match (t, i, 0)) | |
7365 | { | |
7366 | if (match (t, j, 1)) | |
7367 | { | |
286cee81 | 7368 | if ((t == 2 && j == IA64_TYPE_X) || match (t, k, 2)) |
44576e1f | 7369 | goodness = 3 + 3 + 3; |
800eeca4 | 7370 | else |
44576e1f | 7371 | goodness = 3 + 3 + extra_goodness (t, 2); |
800eeca4 JW |
7372 | } |
7373 | else if (match (t, j, 2)) | |
44576e1f | 7374 | goodness = 3 + 3 + extra_goodness (t, 1); |
800eeca4 | 7375 | else |
44576e1f RH |
7376 | { |
7377 | goodness = 3; | |
7378 | goodness += extra_goodness (t, 1); | |
7379 | goodness += extra_goodness (t, 2); | |
7380 | } | |
800eeca4 JW |
7381 | } |
7382 | else if (match (t, i, 1)) | |
7383 | { | |
286cee81 | 7384 | if ((t == 2 && i == IA64_TYPE_X) || match (t, j, 2)) |
44576e1f | 7385 | goodness = 3 + 3; |
800eeca4 | 7386 | else |
44576e1f | 7387 | goodness = 3 + extra_goodness (t, 2); |
800eeca4 JW |
7388 | } |
7389 | else if (match (t, i, 2)) | |
44576e1f | 7390 | goodness = 3 + extra_goodness (t, 1); |
800eeca4 JW |
7391 | |
7392 | if (goodness > best) | |
7393 | { | |
7394 | best = goodness; | |
7395 | best_template[i][j][k] = t; | |
7396 | } | |
7397 | } | |
7398 | } | |
7399 | ||
7c06efaa JW |
7400 | #ifdef DEBUG_TEMPLATES |
7401 | /* For debugging changes to the best_template calculations. We don't care | |
7402 | about combinations with invalid instructions, so start the loops at 1. */ | |
7403 | for (i = 0; i < IA64_NUM_TYPES; ++i) | |
7404 | for (j = 0; j < IA64_NUM_TYPES; ++j) | |
7405 | for (k = 0; k < IA64_NUM_TYPES; ++k) | |
7406 | { | |
7407 | char type_letter[IA64_NUM_TYPES] = { 'n', 'a', 'i', 'm', 'b', 'f', | |
7408 | 'x', 'd' }; | |
7409 | fprintf (stderr, "%c%c%c %s\n", type_letter[i], type_letter[j], | |
7410 | type_letter[k], | |
7411 | ia64_templ_desc[best_template[i][j][k]].name); | |
7412 | } | |
7413 | #endif | |
7414 | ||
800eeca4 JW |
7415 | for (i = 0; i < NUM_SLOTS; ++i) |
7416 | md.slot[i].user_template = -1; | |
7417 | ||
7418 | md.pseudo_hash = hash_new (); | |
7419 | for (i = 0; i < NELEMS (pseudo_opcode); ++i) | |
7420 | { | |
7421 | err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name, | |
7422 | (void *) (pseudo_opcode + i)); | |
7423 | if (err) | |
ad4b42b4 | 7424 | as_fatal (_("ia64.md_begin: can't hash `%s': %s"), |
800eeca4 JW |
7425 | pseudo_opcode[i].name, err); |
7426 | } | |
7427 | ||
7428 | md.reg_hash = hash_new (); | |
7429 | md.dynreg_hash = hash_new (); | |
7430 | md.const_hash = hash_new (); | |
7431 | md.entry_hash = hash_new (); | |
7432 | ||
542d6675 | 7433 | /* general registers: */ |
8b84be9d JB |
7434 | declare_register_set ("r", 128, REG_GR); |
7435 | declare_register ("gp", REG_GR + 1); | |
7436 | declare_register ("sp", REG_GR + 12); | |
7437 | declare_register ("tp", REG_GR + 13); | |
7438 | declare_register_set ("ret", 4, REG_GR + 8); | |
800eeca4 | 7439 | |
542d6675 | 7440 | /* floating point registers: */ |
8b84be9d JB |
7441 | declare_register_set ("f", 128, REG_FR); |
7442 | declare_register_set ("farg", 8, REG_FR + 8); | |
7443 | declare_register_set ("fret", 8, REG_FR + 8); | |
800eeca4 | 7444 | |
542d6675 | 7445 | /* branch registers: */ |
8b84be9d JB |
7446 | declare_register_set ("b", 8, REG_BR); |
7447 | declare_register ("rp", REG_BR + 0); | |
800eeca4 | 7448 | |
8b84be9d JB |
7449 | /* predicate registers: */ |
7450 | declare_register_set ("p", 64, REG_P); | |
7451 | declare_register ("pr", REG_PR); | |
7452 | declare_register ("pr.rot", REG_PR_ROT); | |
800eeca4 | 7453 | |
8b84be9d JB |
7454 | /* application registers: */ |
7455 | declare_register_set ("ar", 128, REG_AR); | |
5e0bd176 JB |
7456 | for (i = 0; i < NELEMS (ar); ++i) |
7457 | declare_register (ar[i].name, REG_AR + ar[i].regnum); | |
800eeca4 | 7458 | |
8b84be9d JB |
7459 | /* control registers: */ |
7460 | declare_register_set ("cr", 128, REG_CR); | |
5e0bd176 JB |
7461 | for (i = 0; i < NELEMS (cr); ++i) |
7462 | declare_register (cr[i].name, REG_CR + cr[i].regnum); | |
800eeca4 | 7463 | |
b3e14eda L |
7464 | /* dahr registers: */ |
7465 | declare_register_set ("dahr", 8, REG_DAHR); | |
7466 | ||
8b84be9d JB |
7467 | declare_register ("ip", REG_IP); |
7468 | declare_register ("cfm", REG_CFM); | |
7469 | declare_register ("psr", REG_PSR); | |
7470 | declare_register ("psr.l", REG_PSR_L); | |
7471 | declare_register ("psr.um", REG_PSR_UM); | |
7472 | ||
7473 | for (i = 0; i < NELEMS (indirect_reg); ++i) | |
7474 | { | |
7475 | unsigned int regnum = indirect_reg[i].regnum; | |
7476 | ||
7477 | md.indregsym[regnum - IND_CPUID] = declare_register (indirect_reg[i].name, regnum); | |
7478 | } | |
800eeca4 | 7479 | |
542d6675 | 7480 | /* pseudo-registers used to specify unwind info: */ |
e0c9811a JW |
7481 | declare_register ("psp", REG_PSP); |
7482 | ||
800eeca4 JW |
7483 | for (i = 0; i < NELEMS (const_bits); ++i) |
7484 | { | |
7485 | err = hash_insert (md.const_hash, const_bits[i].name, | |
5a49b8ac | 7486 | (void *) (const_bits + i)); |
800eeca4 | 7487 | if (err) |
ad4b42b4 | 7488 | as_fatal (_("Inserting \"%s\" into constant hash table failed: %s"), |
800eeca4 JW |
7489 | name, err); |
7490 | } | |
7491 | ||
44f5c83a JW |
7492 | /* Set the architecture and machine depending on defaults and command line |
7493 | options. */ | |
7494 | if (md.flags & EF_IA_64_ABI64) | |
7495 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64); | |
7496 | else | |
7497 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32); | |
7498 | ||
7499 | if (! ok) | |
7500 | as_warn (_("Could not set architecture and machine")); | |
800eeca4 | 7501 | |
557debba JW |
7502 | /* Set the pointer size and pointer shift size depending on md.flags */ |
7503 | ||
7504 | if (md.flags & EF_IA_64_ABI64) | |
7505 | { | |
7506 | md.pointer_size = 8; /* pointers are 8 bytes */ | |
7507 | md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */ | |
7508 | } | |
7509 | else | |
7510 | { | |
7511 | md.pointer_size = 4; /* pointers are 4 bytes */ | |
7512 | md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */ | |
7513 | } | |
7514 | ||
800eeca4 JW |
7515 | md.mem_offset.hint = 0; |
7516 | md.path = 0; | |
7517 | md.maxpaths = 0; | |
7518 | md.entry_labels = NULL; | |
7519 | } | |
7520 | ||
970d6792 L |
7521 | /* Set the default options in md. Cannot do this in md_begin because |
7522 | that is called after md_parse_option which is where we set the | |
7523 | options in md based on command line options. */ | |
44f5c83a JW |
7524 | |
7525 | void | |
5a49b8ac | 7526 | ia64_init (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) |
44f5c83a | 7527 | { |
1cd8ff38 | 7528 | md.flags = MD_FLAGS_DEFAULT; |
01e1a5bc NC |
7529 | #ifndef TE_VMS |
7530 | /* Don't turn on dependency checking for VMS, doesn't work. */ | |
f1dab70d | 7531 | md.detect_dv = 1; |
01e1a5bc | 7532 | #endif |
970d6792 L |
7533 | /* FIXME: We should change it to unwind_check_error someday. */ |
7534 | md.unwind_check = unwind_check_warning; | |
91d777ee | 7535 | md.hint_b = hint_b_error; |
8c2fda1d | 7536 | md.tune = itanium2; |
44f5c83a JW |
7537 | } |
7538 | ||
7539 | /* Return a string for the target object file format. */ | |
7540 | ||
7541 | const char * | |
5a49b8ac | 7542 | ia64_target_format (void) |
44f5c83a JW |
7543 | { |
7544 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
7545 | { | |
72a76794 JW |
7546 | if (md.flags & EF_IA_64_BE) |
7547 | { | |
7548 | if (md.flags & EF_IA_64_ABI64) | |
1cd8ff38 | 7549 | #if defined(TE_AIX50) |
7463c317 | 7550 | return "elf64-ia64-aix-big"; |
1cd8ff38 NC |
7551 | #elif defined(TE_HPUX) |
7552 | return "elf64-ia64-hpux-big"; | |
7463c317 | 7553 | #else |
72a76794 | 7554 | return "elf64-ia64-big"; |
7463c317 | 7555 | #endif |
72a76794 | 7556 | else |
1cd8ff38 | 7557 | #if defined(TE_AIX50) |
7463c317 | 7558 | return "elf32-ia64-aix-big"; |
1cd8ff38 NC |
7559 | #elif defined(TE_HPUX) |
7560 | return "elf32-ia64-hpux-big"; | |
7463c317 | 7561 | #else |
72a76794 | 7562 | return "elf32-ia64-big"; |
7463c317 | 7563 | #endif |
72a76794 | 7564 | } |
44f5c83a | 7565 | else |
72a76794 JW |
7566 | { |
7567 | if (md.flags & EF_IA_64_ABI64) | |
01e1a5bc | 7568 | #if defined (TE_AIX50) |
7463c317 | 7569 | return "elf64-ia64-aix-little"; |
01e1a5bc NC |
7570 | #elif defined (TE_VMS) |
7571 | { | |
7572 | md.flags |= EF_IA_64_ARCHVER_1; | |
7573 | return "elf64-ia64-vms"; | |
7574 | } | |
7463c317 | 7575 | #else |
72a76794 | 7576 | return "elf64-ia64-little"; |
7463c317 | 7577 | #endif |
72a76794 | 7578 | else |
7463c317 TW |
7579 | #ifdef TE_AIX50 |
7580 | return "elf32-ia64-aix-little"; | |
7581 | #else | |
72a76794 | 7582 | return "elf32-ia64-little"; |
7463c317 | 7583 | #endif |
72a76794 | 7584 | } |
44f5c83a JW |
7585 | } |
7586 | else | |
7587 | return "unknown-format"; | |
7588 | } | |
7589 | ||
800eeca4 | 7590 | void |
5a49b8ac | 7591 | ia64_end_of_source (void) |
800eeca4 | 7592 | { |
542d6675 | 7593 | /* terminate insn group upon reaching end of file: */ |
800eeca4 JW |
7594 | insn_group_break (1, 0, 0); |
7595 | ||
542d6675 | 7596 | /* emits slots we haven't written yet: */ |
800eeca4 JW |
7597 | ia64_flush_insns (); |
7598 | ||
7599 | bfd_set_private_flags (stdoutput, md.flags); | |
7600 | ||
800eeca4 JW |
7601 | md.mem_offset.hint = 0; |
7602 | } | |
7603 | ||
7604 | void | |
5a49b8ac | 7605 | ia64_start_line (void) |
800eeca4 | 7606 | { |
e4e8248d JB |
7607 | static int first; |
7608 | ||
7609 | if (!first) { | |
7610 | /* Make sure we don't reference input_line_pointer[-1] when that's | |
7611 | not valid. */ | |
7612 | first = 1; | |
7613 | return; | |
7614 | } | |
7615 | ||
f1bcba5b | 7616 | if (md.qp.X_op == O_register) |
ad4b42b4 | 7617 | as_bad (_("qualifying predicate not followed by instruction")); |
800eeca4 JW |
7618 | md.qp.X_op = O_absent; |
7619 | ||
7620 | if (ignore_input ()) | |
7621 | return; | |
7622 | ||
7623 | if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';') | |
7624 | { | |
7625 | if (md.detect_dv && !md.explicit_mode) | |
f1dab70d JB |
7626 | { |
7627 | static int warned; | |
7628 | ||
7629 | if (!warned) | |
7630 | { | |
7631 | warned = 1; | |
7632 | as_warn (_("Explicit stops are ignored in auto mode")); | |
7633 | } | |
7634 | } | |
800eeca4 | 7635 | else |
542d6675 | 7636 | insn_group_break (1, 0, 0); |
800eeca4 | 7637 | } |
e4e8248d | 7638 | else if (input_line_pointer[-1] == '{') |
800eeca4 | 7639 | { |
800eeca4 | 7640 | if (md.manual_bundling) |
ad4b42b4 | 7641 | as_warn (_("Found '{' when manual bundling is already turned on")); |
800eeca4 JW |
7642 | else |
7643 | CURR_SLOT.manual_bundling_on = 1; | |
7644 | md.manual_bundling = 1; | |
7645 | ||
542d6675 KH |
7646 | /* Bundling is only acceptable in explicit mode |
7647 | or when in default automatic mode. */ | |
800eeca4 | 7648 | if (md.detect_dv && !md.explicit_mode) |
542d6675 KH |
7649 | { |
7650 | if (!md.mode_explicitly_set | |
7651 | && !md.default_explicit_mode) | |
7652 | dot_dv_mode ('E'); | |
7653 | else | |
7654 | as_warn (_("Found '{' after explicit switch to automatic mode")); | |
7655 | } | |
e4e8248d JB |
7656 | } |
7657 | else if (input_line_pointer[-1] == '}') | |
7658 | { | |
800eeca4 | 7659 | if (!md.manual_bundling) |
ad4b42b4 | 7660 | as_warn (_("Found '}' when manual bundling is off")); |
800eeca4 JW |
7661 | else |
7662 | PREV_SLOT.manual_bundling_off = 1; | |
7663 | md.manual_bundling = 0; | |
7664 | ||
7665 | /* switch back to automatic mode, if applicable */ | |
197865e8 | 7666 | if (md.detect_dv |
542d6675 KH |
7667 | && md.explicit_mode |
7668 | && !md.mode_explicitly_set | |
7669 | && !md.default_explicit_mode) | |
7670 | dot_dv_mode ('A'); | |
e4e8248d JB |
7671 | } |
7672 | } | |
800eeca4 | 7673 | |
e4e8248d JB |
7674 | /* This is a hook for ia64_frob_label, so that it can distinguish tags from |
7675 | labels. */ | |
7676 | static int defining_tag = 0; | |
7677 | ||
7678 | int | |
5a49b8ac | 7679 | ia64_unrecognized_line (int ch) |
e4e8248d JB |
7680 | { |
7681 | switch (ch) | |
7682 | { | |
7683 | case '(': | |
60d11e55 | 7684 | expression_and_evaluate (&md.qp); |
e4e8248d | 7685 | if (*input_line_pointer++ != ')') |
800eeca4 | 7686 | { |
ad4b42b4 | 7687 | as_bad (_("Expected ')'")); |
e4e8248d JB |
7688 | return 0; |
7689 | } | |
7690 | if (md.qp.X_op != O_register) | |
7691 | { | |
ad4b42b4 | 7692 | as_bad (_("Qualifying predicate expected")); |
e4e8248d JB |
7693 | return 0; |
7694 | } | |
7695 | if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64) | |
7696 | { | |
ad4b42b4 | 7697 | as_bad (_("Predicate register expected")); |
e4e8248d | 7698 | return 0; |
800eeca4 | 7699 | } |
800eeca4 JW |
7700 | return 1; |
7701 | ||
f1bcba5b JW |
7702 | case '[': |
7703 | { | |
7704 | char *s; | |
7705 | char c; | |
7706 | symbolS *tag; | |
4d5a53ff | 7707 | int temp; |
f1bcba5b JW |
7708 | |
7709 | if (md.qp.X_op == O_register) | |
7710 | { | |
ad4b42b4 | 7711 | as_bad (_("Tag must come before qualifying predicate.")); |
f1bcba5b JW |
7712 | return 0; |
7713 | } | |
4d5a53ff JW |
7714 | |
7715 | /* This implements just enough of read_a_source_file in read.c to | |
7716 | recognize labels. */ | |
7717 | if (is_name_beginner (*input_line_pointer)) | |
7718 | { | |
d02603dc | 7719 | c = get_symbol_name (&s); |
4d5a53ff JW |
7720 | } |
7721 | else if (LOCAL_LABELS_FB | |
3882b010 | 7722 | && ISDIGIT (*input_line_pointer)) |
4d5a53ff JW |
7723 | { |
7724 | temp = 0; | |
3882b010 | 7725 | while (ISDIGIT (*input_line_pointer)) |
4d5a53ff JW |
7726 | temp = (temp * 10) + *input_line_pointer++ - '0'; |
7727 | fb_label_instance_inc (temp); | |
7728 | s = fb_label_name (temp, 0); | |
7729 | c = *input_line_pointer; | |
7730 | } | |
7731 | else | |
7732 | { | |
7733 | s = NULL; | |
7734 | c = '\0'; | |
7735 | } | |
f1bcba5b JW |
7736 | if (c != ':') |
7737 | { | |
7738 | /* Put ':' back for error messages' sake. */ | |
7739 | *input_line_pointer++ = ':'; | |
ad4b42b4 | 7740 | as_bad (_("Expected ':'")); |
f1bcba5b JW |
7741 | return 0; |
7742 | } | |
4d5a53ff | 7743 | |
f1bcba5b JW |
7744 | defining_tag = 1; |
7745 | tag = colon (s); | |
7746 | defining_tag = 0; | |
7747 | /* Put ':' back for error messages' sake. */ | |
7748 | *input_line_pointer++ = ':'; | |
7749 | if (*input_line_pointer++ != ']') | |
7750 | { | |
ad4b42b4 | 7751 | as_bad (_("Expected ']'")); |
f1bcba5b JW |
7752 | return 0; |
7753 | } | |
7754 | if (! tag) | |
7755 | { | |
ad4b42b4 | 7756 | as_bad (_("Tag name expected")); |
f1bcba5b JW |
7757 | return 0; |
7758 | } | |
7759 | return 1; | |
7760 | } | |
7761 | ||
800eeca4 JW |
7762 | default: |
7763 | break; | |
7764 | } | |
542d6675 KH |
7765 | |
7766 | /* Not a valid line. */ | |
7767 | return 0; | |
800eeca4 JW |
7768 | } |
7769 | ||
7770 | void | |
5a49b8ac | 7771 | ia64_frob_label (struct symbol *sym) |
800eeca4 JW |
7772 | { |
7773 | struct label_fix *fix; | |
7774 | ||
f1bcba5b JW |
7775 | /* Tags need special handling since they are not bundle breaks like |
7776 | labels. */ | |
7777 | if (defining_tag) | |
7778 | { | |
7779 | fix = obstack_alloc (¬es, sizeof (*fix)); | |
7780 | fix->sym = sym; | |
7781 | fix->next = CURR_SLOT.tag_fixups; | |
07a53e5c | 7782 | fix->dw2_mark_labels = FALSE; |
f1bcba5b JW |
7783 | CURR_SLOT.tag_fixups = fix; |
7784 | ||
7785 | return; | |
7786 | } | |
7787 | ||
800eeca4 JW |
7788 | if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) |
7789 | { | |
7790 | md.last_text_seg = now_seg; | |
7791 | fix = obstack_alloc (¬es, sizeof (*fix)); | |
7792 | fix->sym = sym; | |
7793 | fix->next = CURR_SLOT.label_fixups; | |
07a53e5c | 7794 | fix->dw2_mark_labels = dwarf2_loc_mark_labels; |
800eeca4 JW |
7795 | CURR_SLOT.label_fixups = fix; |
7796 | ||
542d6675 | 7797 | /* Keep track of how many code entry points we've seen. */ |
800eeca4 | 7798 | if (md.path == md.maxpaths) |
542d6675 KH |
7799 | { |
7800 | md.maxpaths += 20; | |
7801 | md.entry_labels = (const char **) | |
7802 | xrealloc ((void *) md.entry_labels, | |
7803 | md.maxpaths * sizeof (char *)); | |
7804 | } | |
800eeca4 JW |
7805 | md.entry_labels[md.path++] = S_GET_NAME (sym); |
7806 | } | |
7807 | } | |
7808 | ||
936cf02e JW |
7809 | #ifdef TE_HPUX |
7810 | /* The HP-UX linker will give unresolved symbol errors for symbols | |
7811 | that are declared but unused. This routine removes declared, | |
7812 | unused symbols from an object. */ | |
7813 | int | |
5a49b8ac | 7814 | ia64_frob_symbol (struct symbol *sym) |
936cf02e | 7815 | { |
45dfa85a | 7816 | if ((S_GET_SEGMENT (sym) == bfd_und_section_ptr && ! symbol_used_p (sym) && |
936cf02e | 7817 | ELF_ST_VISIBILITY (S_GET_OTHER (sym)) == STV_DEFAULT) |
45dfa85a | 7818 | || (S_GET_SEGMENT (sym) == bfd_abs_section_ptr |
936cf02e JW |
7819 | && ! S_IS_EXTERNAL (sym))) |
7820 | return 1; | |
7821 | return 0; | |
7822 | } | |
7823 | #endif | |
7824 | ||
800eeca4 | 7825 | void |
5a49b8ac | 7826 | ia64_flush_pending_output (void) |
800eeca4 | 7827 | { |
4d5a53ff JW |
7828 | if (!md.keep_pending_output |
7829 | && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) | |
800eeca4 JW |
7830 | { |
7831 | /* ??? This causes many unnecessary stop bits to be emitted. | |
7832 | Unfortunately, it isn't clear if it is safe to remove this. */ | |
7833 | insn_group_break (1, 0, 0); | |
7834 | ia64_flush_insns (); | |
7835 | } | |
7836 | } | |
7837 | ||
7838 | /* Do ia64-specific expression optimization. All that's done here is | |
7839 | to transform index expressions that are either due to the indexing | |
7840 | of rotating registers or due to the indexing of indirect register | |
7841 | sets. */ | |
7842 | int | |
5a49b8ac | 7843 | ia64_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
800eeca4 | 7844 | { |
6a2375c6 JB |
7845 | if (op != O_index) |
7846 | return 0; | |
7847 | resolve_expression (l); | |
7848 | if (l->X_op == O_register) | |
800eeca4 | 7849 | { |
6a2375c6 JB |
7850 | unsigned num_regs = l->X_add_number >> 16; |
7851 | ||
7852 | resolve_expression (r); | |
7853 | if (num_regs) | |
800eeca4 | 7854 | { |
6a2375c6 JB |
7855 | /* Left side is a .rotX-allocated register. */ |
7856 | if (r->X_op != O_constant) | |
800eeca4 | 7857 | { |
ad4b42b4 | 7858 | as_bad (_("Rotating register index must be a non-negative constant")); |
6a2375c6 JB |
7859 | r->X_add_number = 0; |
7860 | } | |
7861 | else if ((valueT) r->X_add_number >= num_regs) | |
7862 | { | |
ad4b42b4 | 7863 | as_bad (_("Index out of range 0..%u"), num_regs - 1); |
800eeca4 JW |
7864 | r->X_add_number = 0; |
7865 | } | |
7866 | l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number; | |
7867 | return 1; | |
7868 | } | |
6a2375c6 | 7869 | else if (l->X_add_number >= IND_CPUID && l->X_add_number <= IND_RR) |
800eeca4 | 7870 | { |
6a2375c6 JB |
7871 | if (r->X_op != O_register |
7872 | || r->X_add_number < REG_GR | |
7873 | || r->X_add_number > REG_GR + 127) | |
800eeca4 | 7874 | { |
ad4b42b4 | 7875 | as_bad (_("Indirect register index must be a general register")); |
6a2375c6 | 7876 | r->X_add_number = REG_GR; |
800eeca4 JW |
7877 | } |
7878 | l->X_op = O_index; | |
8b84be9d | 7879 | l->X_op_symbol = md.indregsym[l->X_add_number - IND_CPUID]; |
800eeca4 JW |
7880 | l->X_add_number = r->X_add_number; |
7881 | return 1; | |
7882 | } | |
7883 | } | |
ad4b42b4 | 7884 | as_bad (_("Index can only be applied to rotating or indirect registers")); |
6a2375c6 JB |
7885 | /* Fall back to some register use of which has as little as possible |
7886 | side effects, to minimize subsequent error messages. */ | |
7887 | l->X_op = O_register; | |
7888 | l->X_add_number = REG_GR + 3; | |
7889 | return 1; | |
800eeca4 JW |
7890 | } |
7891 | ||
7892 | int | |
5a49b8ac | 7893 | ia64_parse_name (char *name, expressionS *e, char *nextcharP) |
800eeca4 JW |
7894 | { |
7895 | struct const_desc *cdesc; | |
7896 | struct dynreg *dr = 0; | |
16a48f83 | 7897 | unsigned int idx; |
800eeca4 JW |
7898 | struct symbol *sym; |
7899 | char *end; | |
7900 | ||
16a48f83 JB |
7901 | if (*name == '@') |
7902 | { | |
7903 | enum pseudo_type pseudo_type = PSEUDO_FUNC_NONE; | |
7904 | ||
7905 | /* Find what relocation pseudo-function we're dealing with. */ | |
7906 | for (idx = 0; idx < NELEMS (pseudo_func); ++idx) | |
7907 | if (pseudo_func[idx].name | |
7908 | && pseudo_func[idx].name[0] == name[1] | |
7909 | && strcmp (pseudo_func[idx].name + 1, name + 2) == 0) | |
7910 | { | |
7911 | pseudo_type = pseudo_func[idx].type; | |
7912 | break; | |
7913 | } | |
7914 | switch (pseudo_type) | |
7915 | { | |
7916 | case PSEUDO_FUNC_RELOC: | |
7917 | end = input_line_pointer; | |
7918 | if (*nextcharP != '(') | |
7919 | { | |
ad4b42b4 | 7920 | as_bad (_("Expected '('")); |
2f6d622e | 7921 | break; |
16a48f83 JB |
7922 | } |
7923 | /* Skip '('. */ | |
7924 | ++input_line_pointer; | |
7925 | expression (e); | |
7926 | if (*input_line_pointer != ')') | |
7927 | { | |
ad4b42b4 | 7928 | as_bad (_("Missing ')'")); |
16a48f83 JB |
7929 | goto done; |
7930 | } | |
7931 | /* Skip ')'. */ | |
7932 | ++input_line_pointer; | |
9d0e8497 TG |
7933 | #ifdef TE_VMS |
7934 | if (idx == FUNC_SLOTCOUNT_RELOC) | |
7935 | { | |
7936 | /* @slotcount can accept any expression. Canonicalize. */ | |
7937 | e->X_add_symbol = make_expr_symbol (e); | |
7938 | e->X_op = O_symbol; | |
7939 | e->X_add_number = 0; | |
7940 | } | |
7941 | #endif | |
16a48f83 JB |
7942 | if (e->X_op != O_symbol) |
7943 | { | |
7944 | if (e->X_op != O_pseudo_fixup) | |
7945 | { | |
ad4b42b4 | 7946 | as_bad (_("Not a symbolic expression")); |
16a48f83 JB |
7947 | goto done; |
7948 | } | |
7949 | if (idx != FUNC_LT_RELATIVE) | |
7950 | { | |
ad4b42b4 | 7951 | as_bad (_("Illegal combination of relocation functions")); |
16a48f83 JB |
7952 | goto done; |
7953 | } | |
7954 | switch (S_GET_VALUE (e->X_op_symbol)) | |
7955 | { | |
7956 | case FUNC_FPTR_RELATIVE: | |
7957 | idx = FUNC_LT_FPTR_RELATIVE; break; | |
7958 | case FUNC_DTP_MODULE: | |
7959 | idx = FUNC_LT_DTP_MODULE; break; | |
7960 | case FUNC_DTP_RELATIVE: | |
7961 | idx = FUNC_LT_DTP_RELATIVE; break; | |
7962 | case FUNC_TP_RELATIVE: | |
7963 | idx = FUNC_LT_TP_RELATIVE; break; | |
7964 | default: | |
ad4b42b4 | 7965 | as_bad (_("Illegal combination of relocation functions")); |
16a48f83 JB |
7966 | goto done; |
7967 | } | |
7968 | } | |
7969 | /* Make sure gas doesn't get rid of local symbols that are used | |
7970 | in relocs. */ | |
7971 | e->X_op = O_pseudo_fixup; | |
7972 | e->X_op_symbol = pseudo_func[idx].u.sym; | |
2f6d622e JB |
7973 | done: |
7974 | *nextcharP = *input_line_pointer; | |
16a48f83 JB |
7975 | break; |
7976 | ||
7977 | case PSEUDO_FUNC_CONST: | |
7978 | e->X_op = O_constant; | |
7979 | e->X_add_number = pseudo_func[idx].u.ival; | |
7980 | break; | |
7981 | ||
7982 | case PSEUDO_FUNC_REG: | |
7983 | e->X_op = O_register; | |
7984 | e->X_add_number = pseudo_func[idx].u.ival; | |
7985 | break; | |
7986 | ||
7987 | default: | |
7988 | return 0; | |
7989 | } | |
16a48f83 JB |
7990 | return 1; |
7991 | } | |
7992 | ||
542d6675 | 7993 | /* first see if NAME is a known register name: */ |
800eeca4 JW |
7994 | sym = hash_find (md.reg_hash, name); |
7995 | if (sym) | |
7996 | { | |
7997 | e->X_op = O_register; | |
7998 | e->X_add_number = S_GET_VALUE (sym); | |
7999 | return 1; | |
8000 | } | |
8001 | ||
8002 | cdesc = hash_find (md.const_hash, name); | |
8003 | if (cdesc) | |
8004 | { | |
8005 | e->X_op = O_constant; | |
8006 | e->X_add_number = cdesc->value; | |
8007 | return 1; | |
8008 | } | |
8009 | ||
542d6675 | 8010 | /* check for inN, locN, or outN: */ |
26b810ce | 8011 | idx = 0; |
800eeca4 JW |
8012 | switch (name[0]) |
8013 | { | |
8014 | case 'i': | |
3882b010 | 8015 | if (name[1] == 'n' && ISDIGIT (name[2])) |
800eeca4 JW |
8016 | { |
8017 | dr = &md.in; | |
26b810ce | 8018 | idx = 2; |
800eeca4 JW |
8019 | } |
8020 | break; | |
8021 | ||
8022 | case 'l': | |
3882b010 | 8023 | if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3])) |
800eeca4 JW |
8024 | { |
8025 | dr = &md.loc; | |
26b810ce | 8026 | idx = 3; |
800eeca4 JW |
8027 | } |
8028 | break; | |
8029 | ||
8030 | case 'o': | |
3882b010 | 8031 | if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3])) |
800eeca4 JW |
8032 | { |
8033 | dr = &md.out; | |
26b810ce | 8034 | idx = 3; |
800eeca4 JW |
8035 | } |
8036 | break; | |
8037 | ||
8038 | default: | |
8039 | break; | |
8040 | } | |
8041 | ||
26b810ce JB |
8042 | /* Ignore register numbers with leading zeroes, except zero itself. */ |
8043 | if (dr && (name[idx] != '0' || name[idx + 1] == '\0')) | |
800eeca4 | 8044 | { |
26b810ce JB |
8045 | unsigned long regnum; |
8046 | ||
542d6675 | 8047 | /* The name is inN, locN, or outN; parse the register number. */ |
26b810ce JB |
8048 | regnum = strtoul (name + idx, &end, 10); |
8049 | if (end > name + idx && *end == '\0' && regnum < 96) | |
800eeca4 | 8050 | { |
26b810ce | 8051 | if (regnum >= dr->num_regs) |
800eeca4 JW |
8052 | { |
8053 | if (!dr->num_regs) | |
ad4b42b4 | 8054 | as_bad (_("No current frame")); |
800eeca4 | 8055 | else |
ad4b42b4 | 8056 | as_bad (_("Register number out of range 0..%u"), |
542d6675 | 8057 | dr->num_regs - 1); |
800eeca4 JW |
8058 | regnum = 0; |
8059 | } | |
8060 | e->X_op = O_register; | |
8061 | e->X_add_number = dr->base + regnum; | |
8062 | return 1; | |
8063 | } | |
8064 | } | |
8065 | ||
e1fa0163 | 8066 | end = xstrdup (name); |
20b36a95 | 8067 | name = ia64_canonicalize_symbol_name (end); |
800eeca4 JW |
8068 | if ((dr = hash_find (md.dynreg_hash, name))) |
8069 | { | |
8070 | /* We've got ourselves the name of a rotating register set. | |
542d6675 KH |
8071 | Store the base register number in the low 16 bits of |
8072 | X_add_number and the size of the register set in the top 16 | |
8073 | bits. */ | |
800eeca4 JW |
8074 | e->X_op = O_register; |
8075 | e->X_add_number = dr->base | (dr->num_regs << 16); | |
e1fa0163 | 8076 | free (end); |
800eeca4 JW |
8077 | return 1; |
8078 | } | |
e1fa0163 | 8079 | free (end); |
800eeca4 JW |
8080 | return 0; |
8081 | } | |
8082 | ||
8083 | /* Remove the '#' suffix that indicates a symbol as opposed to a register. */ | |
8084 | ||
8085 | char * | |
5a49b8ac | 8086 | ia64_canonicalize_symbol_name (char *name) |
800eeca4 | 8087 | { |
20b36a95 JB |
8088 | size_t len = strlen (name), full = len; |
8089 | ||
8090 | while (len > 0 && name[len - 1] == '#') | |
8091 | --len; | |
8092 | if (len <= 0) | |
8093 | { | |
8094 | if (full > 0) | |
ad4b42b4 | 8095 | as_bad (_("Standalone `#' is illegal")); |
20b36a95 JB |
8096 | } |
8097 | else if (len < full - 1) | |
ad4b42b4 | 8098 | as_warn (_("Redundant `#' suffix operators")); |
20b36a95 | 8099 | name[len] = '\0'; |
800eeca4 JW |
8100 | return name; |
8101 | } | |
8102 | ||
3e37788f JW |
8103 | /* Return true if idesc is a conditional branch instruction. This excludes |
8104 | the modulo scheduled branches, and br.ia. Mod-sched branches are excluded | |
8105 | because they always read/write resources regardless of the value of the | |
8106 | qualifying predicate. br.ia must always use p0, and hence is always | |
8107 | taken. Thus this function returns true for branches which can fall | |
8108 | through, and which use no resources if they do fall through. */ | |
1deb8127 | 8109 | |
800eeca4 | 8110 | static int |
5a49b8ac | 8111 | is_conditional_branch (struct ia64_opcode *idesc) |
800eeca4 | 8112 | { |
1deb8127 | 8113 | /* br is a conditional branch. Everything that starts with br. except |
3e37788f JW |
8114 | br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch. |
8115 | Everything that starts with brl is a conditional branch. */ | |
1deb8127 JW |
8116 | return (idesc->name[0] == 'b' && idesc->name[1] == 'r' |
8117 | && (idesc->name[2] == '\0' | |
3e37788f JW |
8118 | || (idesc->name[2] == '.' && idesc->name[3] != 'i' |
8119 | && idesc->name[3] != 'c' && idesc->name[3] != 'w') | |
8120 | || idesc->name[2] == 'l' | |
8121 | /* br.cond, br.call, br.clr */ | |
8122 | || (idesc->name[2] == '.' && idesc->name[3] == 'c' | |
8123 | && (idesc->name[4] == 'a' || idesc->name[4] == 'o' | |
8124 | || (idesc->name[4] == 'l' && idesc->name[5] == 'r'))))); | |
800eeca4 JW |
8125 | } |
8126 | ||
8127 | /* Return whether the given opcode is a taken branch. If there's any doubt, | |
542d6675 KH |
8128 | returns zero. */ |
8129 | ||
800eeca4 | 8130 | static int |
5a49b8ac | 8131 | is_taken_branch (struct ia64_opcode *idesc) |
800eeca4 JW |
8132 | { |
8133 | return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0) | |
542d6675 | 8134 | || strncmp (idesc->name, "br.ia", 5) == 0); |
800eeca4 JW |
8135 | } |
8136 | ||
8137 | /* Return whether the given opcode is an interruption or rfi. If there's any | |
542d6675 KH |
8138 | doubt, returns zero. */ |
8139 | ||
800eeca4 | 8140 | static int |
5a49b8ac | 8141 | is_interruption_or_rfi (struct ia64_opcode *idesc) |
800eeca4 JW |
8142 | { |
8143 | if (strcmp (idesc->name, "rfi") == 0) | |
8144 | return 1; | |
8145 | return 0; | |
8146 | } | |
8147 | ||
8148 | /* Returns the index of the given dependency in the opcode's list of chks, or | |
8149 | -1 if there is no dependency. */ | |
542d6675 | 8150 | |
800eeca4 | 8151 | static int |
5a49b8ac | 8152 | depends_on (int depind, struct ia64_opcode *idesc) |
800eeca4 JW |
8153 | { |
8154 | int i; | |
8155 | const struct ia64_opcode_dependency *dep = idesc->dependencies; | |
542d6675 | 8156 | for (i = 0; i < dep->nchks; i++) |
800eeca4 | 8157 | { |
542d6675 KH |
8158 | if (depind == DEP (dep->chks[i])) |
8159 | return i; | |
800eeca4 JW |
8160 | } |
8161 | return -1; | |
8162 | } | |
8163 | ||
8164 | /* Determine a set of specific resources used for a particular resource | |
8165 | class. Returns the number of specific resources identified For those | |
8166 | cases which are not determinable statically, the resource returned is | |
197865e8 | 8167 | marked nonspecific. |
800eeca4 JW |
8168 | |
8169 | Meanings of value in 'NOTE': | |
8170 | 1) only read/write when the register number is explicitly encoded in the | |
8171 | insn. | |
8172 | 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only | |
197865e8 | 8173 | accesses CFM when qualifying predicate is in the rotating region. |
800eeca4 JW |
8174 | 3) general register value is used to specify an indirect register; not |
8175 | determinable statically. | |
8176 | 4) only read the given resource when bits 7:0 of the indirect index | |
8177 | register value does not match the register number of the resource; not | |
8178 | determinable statically. | |
8179 | 5) all rules are implementation specific. | |
8180 | 6) only when both the index specified by the reader and the index specified | |
8181 | by the writer have the same value in bits 63:61; not determinable | |
197865e8 | 8182 | statically. |
800eeca4 | 8183 | 7) only access the specified resource when the corresponding mask bit is |
197865e8 | 8184 | set |
800eeca4 JW |
8185 | 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is |
8186 | only read when these insns reference FR2-31 | |
8187 | 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only | |
8188 | written when these insns write FR32-127 | |
8189 | 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the | |
8190 | instruction | |
8191 | 11) The target predicates are written independently of PR[qp], but source | |
8192 | registers are only read if PR[qp] is true. Since the state of PR[qp] | |
8193 | cannot statically be determined, all source registers are marked used. | |
8194 | 12) This insn only reads the specified predicate register when that | |
8195 | register is the PR[qp]. | |
ad4b42b4 | 8196 | 13) This reference to ld-c only applies to the GR whose value is loaded |
197865e8 | 8197 | with data returned from memory, not the post-incremented address register. |
800eeca4 JW |
8198 | 14) The RSE resource includes the implementation-specific RSE internal |
8199 | state resources. At least one (and possibly more) of these resources are | |
8200 | read by each instruction listed in IC:rse-readers. At least one (and | |
8201 | possibly more) of these resources are written by each insn listed in | |
197865e8 | 8202 | IC:rse-writers. |
800eeca4 | 8203 | 15+16) Represents reserved instructions, which the assembler does not |
197865e8 | 8204 | generate. |
7f3dfb9c L |
8205 | 17) CR[TPR] has a RAW dependency only between mov-to-CR-TPR and |
8206 | mov-to-PSR-l or ssm instructions that set PSR.i, PSR.pp or PSR.up. | |
800eeca4 JW |
8207 | |
8208 | Memory resources (i.e. locations in memory) are *not* marked or tracked by | |
8209 | this code; there are no dependency violations based on memory access. | |
800eeca4 JW |
8210 | */ |
8211 | ||
8212 | #define MAX_SPECS 256 | |
8213 | #define DV_CHK 1 | |
8214 | #define DV_REG 0 | |
8215 | ||
8216 | static int | |
5a49b8ac AM |
8217 | specify_resource (const struct ia64_dependency *dep, |
8218 | struct ia64_opcode *idesc, | |
8219 | /* is this a DV chk or a DV reg? */ | |
8220 | int type, | |
8221 | /* returned specific resources */ | |
8222 | struct rsrc specs[MAX_SPECS], | |
8223 | /* resource note for this insn's usage */ | |
8224 | int note, | |
8225 | /* which execution path to examine */ | |
8226 | int path) | |
800eeca4 JW |
8227 | { |
8228 | int count = 0; | |
8229 | int i; | |
8230 | int rsrc_write = 0; | |
8231 | struct rsrc tmpl; | |
197865e8 | 8232 | |
800eeca4 JW |
8233 | if (dep->mode == IA64_DV_WAW |
8234 | || (dep->mode == IA64_DV_RAW && type == DV_REG) | |
8235 | || (dep->mode == IA64_DV_WAR && type == DV_CHK)) | |
8236 | rsrc_write = 1; | |
8237 | ||
8238 | /* template for any resources we identify */ | |
8239 | tmpl.dependency = dep; | |
8240 | tmpl.note = note; | |
8241 | tmpl.insn_srlz = tmpl.data_srlz = 0; | |
8242 | tmpl.qp_regno = CURR_SLOT.qp_regno; | |
8243 | tmpl.link_to_qp_branch = 1; | |
8244 | tmpl.mem_offset.hint = 0; | |
1f8b1395 AS |
8245 | tmpl.mem_offset.offset = 0; |
8246 | tmpl.mem_offset.base = 0; | |
800eeca4 | 8247 | tmpl.specific = 1; |
a66d2bb7 | 8248 | tmpl.index = -1; |
7484b8e6 | 8249 | tmpl.cmp_type = CMP_NONE; |
1f8b1395 AS |
8250 | tmpl.depind = 0; |
8251 | tmpl.file = NULL; | |
8252 | tmpl.line = 0; | |
8253 | tmpl.path = 0; | |
800eeca4 JW |
8254 | |
8255 | #define UNHANDLED \ | |
8256 | as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \ | |
8257 | dep->name, idesc->name, (rsrc_write?"write":"read"), note) | |
8258 | #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path) | |
8259 | ||
8260 | /* we don't need to track these */ | |
8261 | if (dep->semantics == IA64_DVS_NONE) | |
8262 | return 0; | |
8263 | ||
8264 | switch (dep->specifier) | |
8265 | { | |
8266 | case IA64_RS_AR_K: | |
8267 | if (note == 1) | |
542d6675 KH |
8268 | { |
8269 | if (idesc->operands[!rsrc_write] == IA64_OPND_AR3) | |
8270 | { | |
8271 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR; | |
8272 | if (regno >= 0 && regno <= 7) | |
8273 | { | |
8274 | specs[count] = tmpl; | |
8275 | specs[count++].index = regno; | |
8276 | } | |
8277 | } | |
8278 | } | |
800eeca4 | 8279 | else if (note == 0) |
542d6675 KH |
8280 | { |
8281 | for (i = 0; i < 8; i++) | |
8282 | { | |
8283 | specs[count] = tmpl; | |
8284 | specs[count++].index = i; | |
8285 | } | |
8286 | } | |
800eeca4 | 8287 | else |
542d6675 KH |
8288 | { |
8289 | UNHANDLED; | |
8290 | } | |
800eeca4 JW |
8291 | break; |
8292 | ||
8293 | case IA64_RS_AR_UNAT: | |
8294 | /* This is a mov =AR or mov AR= instruction. */ | |
8295 | if (idesc->operands[!rsrc_write] == IA64_OPND_AR3) | |
8296 | { | |
8297 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR; | |
8298 | if (regno == AR_UNAT) | |
8299 | { | |
8300 | specs[count++] = tmpl; | |
8301 | } | |
8302 | } | |
8303 | else | |
8304 | { | |
8305 | /* This is a spill/fill, or other instruction that modifies the | |
8306 | unat register. */ | |
8307 | ||
8308 | /* Unless we can determine the specific bits used, mark the whole | |
8309 | thing; bits 8:3 of the memory address indicate the bit used in | |
8310 | UNAT. The .mem.offset hint may be used to eliminate a small | |
8311 | subset of conflicts. */ | |
8312 | specs[count] = tmpl; | |
8313 | if (md.mem_offset.hint) | |
8314 | { | |
542d6675 KH |
8315 | if (md.debug_dv) |
8316 | fprintf (stderr, " Using hint for spill/fill\n"); | |
8317 | /* The index isn't actually used, just set it to something | |
8318 | approximating the bit index. */ | |
800eeca4 JW |
8319 | specs[count].index = (md.mem_offset.offset >> 3) & 0x3F; |
8320 | specs[count].mem_offset.hint = 1; | |
8321 | specs[count].mem_offset.offset = md.mem_offset.offset; | |
8322 | specs[count++].mem_offset.base = md.mem_offset.base; | |
8323 | } | |
8324 | else | |
8325 | { | |
8326 | specs[count++].specific = 0; | |
8327 | } | |
8328 | } | |
8329 | break; | |
8330 | ||
8331 | case IA64_RS_AR: | |
8332 | if (note == 1) | |
542d6675 KH |
8333 | { |
8334 | if (idesc->operands[!rsrc_write] == IA64_OPND_AR3) | |
8335 | { | |
8336 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR; | |
8337 | if ((regno >= 8 && regno <= 15) | |
8338 | || (regno >= 20 && regno <= 23) | |
8339 | || (regno >= 31 && regno <= 39) | |
8340 | || (regno >= 41 && regno <= 47) | |
8341 | || (regno >= 67 && regno <= 111)) | |
8342 | { | |
8343 | specs[count] = tmpl; | |
8344 | specs[count++].index = regno; | |
8345 | } | |
8346 | } | |
8347 | } | |
800eeca4 | 8348 | else |
542d6675 KH |
8349 | { |
8350 | UNHANDLED; | |
8351 | } | |
800eeca4 JW |
8352 | break; |
8353 | ||
8354 | case IA64_RS_ARb: | |
8355 | if (note == 1) | |
542d6675 KH |
8356 | { |
8357 | if (idesc->operands[!rsrc_write] == IA64_OPND_AR3) | |
8358 | { | |
8359 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR; | |
8360 | if ((regno >= 48 && regno <= 63) | |
8361 | || (regno >= 112 && regno <= 127)) | |
8362 | { | |
8363 | specs[count] = tmpl; | |
8364 | specs[count++].index = regno; | |
8365 | } | |
8366 | } | |
8367 | } | |
800eeca4 | 8368 | else if (note == 0) |
542d6675 KH |
8369 | { |
8370 | for (i = 48; i < 64; i++) | |
8371 | { | |
8372 | specs[count] = tmpl; | |
8373 | specs[count++].index = i; | |
8374 | } | |
8375 | for (i = 112; i < 128; i++) | |
8376 | { | |
8377 | specs[count] = tmpl; | |
8378 | specs[count++].index = i; | |
8379 | } | |
8380 | } | |
197865e8 | 8381 | else |
542d6675 KH |
8382 | { |
8383 | UNHANDLED; | |
8384 | } | |
800eeca4 JW |
8385 | break; |
8386 | ||
8387 | case IA64_RS_BR: | |
8388 | if (note != 1) | |
542d6675 KH |
8389 | { |
8390 | UNHANDLED; | |
8391 | } | |
800eeca4 | 8392 | else |
542d6675 KH |
8393 | { |
8394 | if (rsrc_write) | |
8395 | { | |
8396 | for (i = 0; i < idesc->num_outputs; i++) | |
8397 | if (idesc->operands[i] == IA64_OPND_B1 | |
8398 | || idesc->operands[i] == IA64_OPND_B2) | |
8399 | { | |
8400 | specs[count] = tmpl; | |
8401 | specs[count++].index = | |
8402 | CURR_SLOT.opnd[i].X_add_number - REG_BR; | |
8403 | } | |
8404 | } | |
8405 | else | |
8406 | { | |
40449e9f | 8407 | for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++) |
542d6675 KH |
8408 | if (idesc->operands[i] == IA64_OPND_B1 |
8409 | || idesc->operands[i] == IA64_OPND_B2) | |
8410 | { | |
8411 | specs[count] = tmpl; | |
8412 | specs[count++].index = | |
8413 | CURR_SLOT.opnd[i].X_add_number - REG_BR; | |
8414 | } | |
8415 | } | |
8416 | } | |
800eeca4 JW |
8417 | break; |
8418 | ||
8419 | case IA64_RS_CPUID: /* four or more registers */ | |
8420 | if (note == 3) | |
542d6675 KH |
8421 | { |
8422 | if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3) | |
8423 | { | |
8424 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR; | |
8425 | if (regno >= 0 && regno < NELEMS (gr_values) | |
8426 | && KNOWN (regno)) | |
8427 | { | |
8428 | specs[count] = tmpl; | |
8429 | specs[count++].index = gr_values[regno].value & 0xFF; | |
8430 | } | |
8431 | else | |
8432 | { | |
8433 | specs[count] = tmpl; | |
8434 | specs[count++].specific = 0; | |
8435 | } | |
8436 | } | |
8437 | } | |
800eeca4 | 8438 | else |
542d6675 KH |
8439 | { |
8440 | UNHANDLED; | |
8441 | } | |
800eeca4 JW |
8442 | break; |
8443 | ||
8444 | case IA64_RS_DBR: /* four or more registers */ | |
8445 | if (note == 3) | |
542d6675 KH |
8446 | { |
8447 | if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3) | |
8448 | { | |
8449 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR; | |
8450 | if (regno >= 0 && regno < NELEMS (gr_values) | |
8451 | && KNOWN (regno)) | |
8452 | { | |
8453 | specs[count] = tmpl; | |
8454 | specs[count++].index = gr_values[regno].value & 0xFF; | |
8455 | } | |
8456 | else | |
8457 | { | |
8458 | specs[count] = tmpl; | |
8459 | specs[count++].specific = 0; | |
8460 | } | |
8461 | } | |
8462 | } | |
800eeca4 | 8463 | else if (note == 0 && !rsrc_write) |
542d6675 KH |
8464 | { |
8465 | specs[count] = tmpl; | |
8466 | specs[count++].specific = 0; | |
8467 | } | |
800eeca4 | 8468 | else |
542d6675 KH |
8469 | { |
8470 | UNHANDLED; | |
8471 | } | |
800eeca4 JW |
8472 | break; |
8473 | ||
8474 | case IA64_RS_IBR: /* four or more registers */ | |
8475 | if (note == 3) | |
542d6675 KH |
8476 | { |
8477 | if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3) | |
8478 | { | |
8479 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR; | |
8480 | if (regno >= 0 && regno < NELEMS (gr_values) | |
8481 | && KNOWN (regno)) | |
8482 | { | |
8483 | specs[count] = tmpl; | |
8484 | specs[count++].index = gr_values[regno].value & 0xFF; | |
8485 | } | |
8486 | else | |
8487 | { | |
8488 | specs[count] = tmpl; | |
8489 | specs[count++].specific = 0; | |
8490 | } | |
8491 | } | |
8492 | } | |
800eeca4 | 8493 | else |
542d6675 KH |
8494 | { |
8495 | UNHANDLED; | |
8496 | } | |
800eeca4 JW |
8497 | break; |
8498 | ||
8499 | case IA64_RS_MSR: | |
8500 | if (note == 5) | |
8501 | { | |
8502 | /* These are implementation specific. Force all references to | |
8503 | conflict with all other references. */ | |
8504 | specs[count] = tmpl; | |
8505 | specs[count++].specific = 0; | |
8506 | } | |
8507 | else | |
8508 | { | |
8509 | UNHANDLED; | |
8510 | } | |
8511 | break; | |
8512 | ||
8513 | case IA64_RS_PKR: /* 16 or more registers */ | |
8514 | if (note == 3 || note == 4) | |
542d6675 KH |
8515 | { |
8516 | if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3) | |
8517 | { | |
8518 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR; | |
8519 | if (regno >= 0 && regno < NELEMS (gr_values) | |
8520 | && KNOWN (regno)) | |
8521 | { | |
8522 | if (note == 3) | |
8523 | { | |
8524 | specs[count] = tmpl; | |
8525 | specs[count++].index = gr_values[regno].value & 0xFF; | |
8526 | } | |
8527 | else | |
8528 | for (i = 0; i < NELEMS (gr_values); i++) | |
8529 | { | |
8530 | /* Uses all registers *except* the one in R3. */ | |
2434f565 | 8531 | if ((unsigned)i != (gr_values[regno].value & 0xFF)) |
542d6675 KH |
8532 | { |
8533 | specs[count] = tmpl; | |
8534 | specs[count++].index = i; | |
8535 | } | |
8536 | } | |
8537 | } | |
8538 | else | |
8539 | { | |
8540 | specs[count] = tmpl; | |
8541 | specs[count++].specific = 0; | |
8542 | } | |
8543 | } | |
8544 | } | |
8545 | else if (note == 0) | |
8546 | { | |
8547 | /* probe et al. */ | |
8548 | specs[count] = tmpl; | |
8549 | specs[count++].specific = 0; | |
8550 | } | |
8551 | break; | |
8552 | ||
8553 | case IA64_RS_PMC: /* four or more registers */ | |
8554 | if (note == 3) | |
8555 | { | |
8556 | if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3 | |
8557 | || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3)) | |
8558 | ||
8559 | { | |
91d6fa6a NC |
8560 | int reg_index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write) |
8561 | ? 1 : !rsrc_write); | |
8562 | int regno = CURR_SLOT.opnd[reg_index].X_add_number - REG_GR; | |
542d6675 KH |
8563 | if (regno >= 0 && regno < NELEMS (gr_values) |
8564 | && KNOWN (regno)) | |
8565 | { | |
8566 | specs[count] = tmpl; | |
8567 | specs[count++].index = gr_values[regno].value & 0xFF; | |
8568 | } | |
8569 | else | |
8570 | { | |
8571 | specs[count] = tmpl; | |
8572 | specs[count++].specific = 0; | |
8573 | } | |
8574 | } | |
8575 | } | |
8576 | else | |
8577 | { | |
8578 | UNHANDLED; | |
8579 | } | |
800eeca4 JW |
8580 | break; |
8581 | ||
8582 | case IA64_RS_PMD: /* four or more registers */ | |
8583 | if (note == 3) | |
542d6675 KH |
8584 | { |
8585 | if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3) | |
8586 | { | |
8587 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR; | |
8588 | if (regno >= 0 && regno < NELEMS (gr_values) | |
8589 | && KNOWN (regno)) | |
8590 | { | |
8591 | specs[count] = tmpl; | |
8592 | specs[count++].index = gr_values[regno].value & 0xFF; | |
8593 | } | |
8594 | else | |
8595 | { | |
8596 | specs[count] = tmpl; | |
8597 | specs[count++].specific = 0; | |
8598 | } | |
8599 | } | |
8600 | } | |
800eeca4 | 8601 | else |
542d6675 KH |
8602 | { |
8603 | UNHANDLED; | |
8604 | } | |
800eeca4 JW |
8605 | break; |
8606 | ||
8607 | case IA64_RS_RR: /* eight registers */ | |
8608 | if (note == 6) | |
542d6675 KH |
8609 | { |
8610 | if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3) | |
8611 | { | |
8612 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR; | |
8613 | if (regno >= 0 && regno < NELEMS (gr_values) | |
8614 | && KNOWN (regno)) | |
8615 | { | |
8616 | specs[count] = tmpl; | |
8617 | specs[count++].index = (gr_values[regno].value >> 61) & 0x7; | |
8618 | } | |
8619 | else | |
8620 | { | |
8621 | specs[count] = tmpl; | |
8622 | specs[count++].specific = 0; | |
8623 | } | |
8624 | } | |
8625 | } | |
800eeca4 | 8626 | else if (note == 0 && !rsrc_write) |
542d6675 KH |
8627 | { |
8628 | specs[count] = tmpl; | |
8629 | specs[count++].specific = 0; | |
8630 | } | |
197865e8 | 8631 | else |
542d6675 KH |
8632 | { |
8633 | UNHANDLED; | |
8634 | } | |
800eeca4 JW |
8635 | break; |
8636 | ||
8637 | case IA64_RS_CR_IRR: | |
197865e8 | 8638 | if (note == 0) |
542d6675 KH |
8639 | { |
8640 | /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */ | |
8641 | int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR; | |
8642 | if (rsrc_write | |
8643 | && idesc->operands[1] == IA64_OPND_CR3 | |
8644 | && regno == CR_IVR) | |
8645 | { | |
8646 | for (i = 0; i < 4; i++) | |
8647 | { | |
8648 | specs[count] = tmpl; | |
8649 | specs[count++].index = CR_IRR0 + i; | |
8650 | } | |
8651 | } | |
8652 | } | |
800eeca4 | 8653 | else if (note == 1) |
542d6675 KH |
8654 | { |
8655 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR; | |
8656 | if (idesc->operands[!rsrc_write] == IA64_OPND_CR3 | |
8657 | && regno >= CR_IRR0 | |
8658 | && regno <= CR_IRR3) | |
8659 | { | |
8660 | specs[count] = tmpl; | |
8661 | specs[count++].index = regno; | |
8662 | } | |
8663 | } | |
800eeca4 | 8664 | else |
542d6675 KH |
8665 | { |
8666 | UNHANDLED; | |
8667 | } | |
800eeca4 JW |
8668 | break; |
8669 | ||
1ca35711 L |
8670 | case IA64_RS_CR_IIB: |
8671 | if (note != 0) | |
8672 | { | |
8673 | UNHANDLED; | |
8674 | } | |
8675 | else | |
8676 | { | |
8677 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR; | |
8678 | if (idesc->operands[!rsrc_write] == IA64_OPND_CR3 | |
8679 | && (regno == CR_IIB0 || regno == CR_IIB1)) | |
8680 | { | |
8681 | specs[count] = tmpl; | |
8682 | specs[count++].index = regno; | |
8683 | } | |
8684 | } | |
8685 | break; | |
8686 | ||
800eeca4 JW |
8687 | case IA64_RS_CR_LRR: |
8688 | if (note != 1) | |
542d6675 KH |
8689 | { |
8690 | UNHANDLED; | |
8691 | } | |
197865e8 | 8692 | else |
542d6675 KH |
8693 | { |
8694 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR; | |
8695 | if (idesc->operands[!rsrc_write] == IA64_OPND_CR3 | |
8696 | && (regno == CR_LRR0 || regno == CR_LRR1)) | |
8697 | { | |
8698 | specs[count] = tmpl; | |
8699 | specs[count++].index = regno; | |
8700 | } | |
8701 | } | |
800eeca4 JW |
8702 | break; |
8703 | ||
8704 | case IA64_RS_CR: | |
8705 | if (note == 1) | |
542d6675 KH |
8706 | { |
8707 | if (idesc->operands[!rsrc_write] == IA64_OPND_CR3) | |
8708 | { | |
8709 | specs[count] = tmpl; | |
8710 | specs[count++].index = | |
8711 | CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR; | |
8712 | } | |
8713 | } | |
800eeca4 | 8714 | else |
542d6675 KH |
8715 | { |
8716 | UNHANDLED; | |
8717 | } | |
800eeca4 JW |
8718 | break; |
8719 | ||
b3e14eda L |
8720 | case IA64_RS_DAHR: |
8721 | if (note == 0) | |
8722 | { | |
8723 | if (idesc->operands[!rsrc_write] == IA64_OPND_DAHR3) | |
8724 | { | |
8725 | specs[count] = tmpl; | |
8726 | specs[count++].index = | |
8727 | CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_DAHR; | |
8728 | } | |
8729 | } | |
8730 | else | |
8731 | { | |
8732 | UNHANDLED; | |
8733 | } | |
8734 | break; | |
8735 | ||
800eeca4 JW |
8736 | case IA64_RS_FR: |
8737 | case IA64_RS_FRb: | |
8738 | if (note != 1) | |
542d6675 KH |
8739 | { |
8740 | UNHANDLED; | |
8741 | } | |
800eeca4 | 8742 | else if (rsrc_write) |
542d6675 KH |
8743 | { |
8744 | if (dep->specifier == IA64_RS_FRb | |
8745 | && idesc->operands[0] == IA64_OPND_F1) | |
8746 | { | |
8747 | specs[count] = tmpl; | |
8748 | specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR; | |
8749 | } | |
8750 | } | |
800eeca4 | 8751 | else |
542d6675 KH |
8752 | { |
8753 | for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++) | |
8754 | { | |
8755 | if (idesc->operands[i] == IA64_OPND_F2 | |
8756 | || idesc->operands[i] == IA64_OPND_F3 | |
8757 | || idesc->operands[i] == IA64_OPND_F4) | |
8758 | { | |
8759 | specs[count] = tmpl; | |
8760 | specs[count++].index = | |
8761 | CURR_SLOT.opnd[i].X_add_number - REG_FR; | |
8762 | } | |
8763 | } | |
8764 | } | |
800eeca4 JW |
8765 | break; |
8766 | ||
8767 | case IA64_RS_GR: | |
8768 | if (note == 13) | |
542d6675 KH |
8769 | { |
8770 | /* This reference applies only to the GR whose value is loaded with | |
8771 | data returned from memory. */ | |
8772 | specs[count] = tmpl; | |
8773 | specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR; | |
8774 | } | |
800eeca4 | 8775 | else if (note == 1) |
542d6675 KH |
8776 | { |
8777 | if (rsrc_write) | |
8778 | { | |
8779 | for (i = 0; i < idesc->num_outputs; i++) | |
50b81f19 JW |
8780 | if (idesc->operands[i] == IA64_OPND_R1 |
8781 | || idesc->operands[i] == IA64_OPND_R2 | |
8782 | || idesc->operands[i] == IA64_OPND_R3) | |
8783 | { | |
8784 | specs[count] = tmpl; | |
197865e8 | 8785 | specs[count++].index = |
50b81f19 JW |
8786 | CURR_SLOT.opnd[i].X_add_number - REG_GR; |
8787 | } | |
8788 | if (idesc->flags & IA64_OPCODE_POSTINC) | |
8789 | for (i = 0; i < NELEMS (idesc->operands); i++) | |
8790 | if (idesc->operands[i] == IA64_OPND_MR3) | |
8791 | { | |
8792 | specs[count] = tmpl; | |
8793 | specs[count++].index = | |
8794 | CURR_SLOT.opnd[i].X_add_number - REG_GR; | |
8795 | } | |
542d6675 KH |
8796 | } |
8797 | else | |
8798 | { | |
8799 | /* Look for anything that reads a GR. */ | |
8800 | for (i = 0; i < NELEMS (idesc->operands); i++) | |
8801 | { | |
8802 | if (idesc->operands[i] == IA64_OPND_MR3 | |
8803 | || idesc->operands[i] == IA64_OPND_CPUID_R3 | |
8804 | || idesc->operands[i] == IA64_OPND_DBR_R3 | |
8805 | || idesc->operands[i] == IA64_OPND_IBR_R3 | |
800eeca4 | 8806 | || idesc->operands[i] == IA64_OPND_MSR_R3 |
542d6675 KH |
8807 | || idesc->operands[i] == IA64_OPND_PKR_R3 |
8808 | || idesc->operands[i] == IA64_OPND_PMC_R3 | |
8809 | || idesc->operands[i] == IA64_OPND_PMD_R3 | |
b3e14eda | 8810 | || idesc->operands[i] == IA64_OPND_DAHR_R3 |
542d6675 KH |
8811 | || idesc->operands[i] == IA64_OPND_RR_R3 |
8812 | || ((i >= idesc->num_outputs) | |
8813 | && (idesc->operands[i] == IA64_OPND_R1 | |
8814 | || idesc->operands[i] == IA64_OPND_R2 | |
8815 | || idesc->operands[i] == IA64_OPND_R3 | |
50b81f19 JW |
8816 | /* addl source register. */ |
8817 | || idesc->operands[i] == IA64_OPND_R3_2))) | |
542d6675 KH |
8818 | { |
8819 | specs[count] = tmpl; | |
8820 | specs[count++].index = | |
8821 | CURR_SLOT.opnd[i].X_add_number - REG_GR; | |
8822 | } | |
8823 | } | |
8824 | } | |
8825 | } | |
197865e8 | 8826 | else |
542d6675 KH |
8827 | { |
8828 | UNHANDLED; | |
8829 | } | |
800eeca4 JW |
8830 | break; |
8831 | ||
139368c9 JW |
8832 | /* This is the same as IA64_RS_PRr, except that the register range is |
8833 | from 1 - 15, and there are no rotating register reads/writes here. */ | |
800eeca4 JW |
8834 | case IA64_RS_PR: |
8835 | if (note == 0) | |
542d6675 | 8836 | { |
139368c9 | 8837 | for (i = 1; i < 16; i++) |
542d6675 | 8838 | { |
139368c9 JW |
8839 | specs[count] = tmpl; |
8840 | specs[count++].index = i; | |
8841 | } | |
8842 | } | |
8843 | else if (note == 7) | |
8844 | { | |
8845 | valueT mask = 0; | |
8846 | /* Mark only those registers indicated by the mask. */ | |
8847 | if (rsrc_write) | |
8848 | { | |
8849 | mask = CURR_SLOT.opnd[2].X_add_number; | |
8850 | for (i = 1; i < 16; i++) | |
8851 | if (mask & ((valueT) 1 << i)) | |
8852 | { | |
8853 | specs[count] = tmpl; | |
8854 | specs[count++].index = i; | |
8855 | } | |
8856 | } | |
8857 | else | |
8858 | { | |
8859 | UNHANDLED; | |
8860 | } | |
8861 | } | |
8862 | else if (note == 11) /* note 11 implies note 1 as well */ | |
8863 | { | |
8864 | if (rsrc_write) | |
8865 | { | |
8866 | for (i = 0; i < idesc->num_outputs; i++) | |
8867 | { | |
8868 | if (idesc->operands[i] == IA64_OPND_P1 | |
8869 | || idesc->operands[i] == IA64_OPND_P2) | |
8870 | { | |
8871 | int regno = CURR_SLOT.opnd[i].X_add_number - REG_P; | |
8872 | if (regno >= 1 && regno < 16) | |
8873 | { | |
8874 | specs[count] = tmpl; | |
8875 | specs[count++].index = regno; | |
8876 | } | |
8877 | } | |
8878 | } | |
8879 | } | |
8880 | else | |
8881 | { | |
8882 | UNHANDLED; | |
8883 | } | |
8884 | } | |
8885 | else if (note == 12) | |
8886 | { | |
8887 | if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16) | |
8888 | { | |
8889 | specs[count] = tmpl; | |
8890 | specs[count++].index = CURR_SLOT.qp_regno; | |
8891 | } | |
8892 | } | |
8893 | else if (note == 1) | |
8894 | { | |
8895 | if (rsrc_write) | |
8896 | { | |
8897 | int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P; | |
8898 | int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P; | |
07726851 KH |
8899 | int or_andcm = strstr (idesc->name, "or.andcm") != NULL; |
8900 | int and_orcm = strstr (idesc->name, "and.orcm") != NULL; | |
139368c9 JW |
8901 | |
8902 | if ((idesc->operands[0] == IA64_OPND_P1 | |
8903 | || idesc->operands[0] == IA64_OPND_P2) | |
8904 | && p1 >= 1 && p1 < 16) | |
542d6675 KH |
8905 | { |
8906 | specs[count] = tmpl; | |
139368c9 JW |
8907 | specs[count].cmp_type = |
8908 | (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE)); | |
8909 | specs[count++].index = p1; | |
8910 | } | |
8911 | if ((idesc->operands[1] == IA64_OPND_P1 | |
8912 | || idesc->operands[1] == IA64_OPND_P2) | |
8913 | && p2 >= 1 && p2 < 16) | |
8914 | { | |
8915 | specs[count] = tmpl; | |
8916 | specs[count].cmp_type = | |
8917 | (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE)); | |
8918 | specs[count++].index = p2; | |
542d6675 KH |
8919 | } |
8920 | } | |
8921 | else | |
8922 | { | |
139368c9 | 8923 | if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16) |
542d6675 KH |
8924 | { |
8925 | specs[count] = tmpl; | |
139368c9 JW |
8926 | specs[count++].index = CURR_SLOT.qp_regno; |
8927 | } | |
8928 | if (idesc->operands[1] == IA64_OPND_PR) | |
8929 | { | |
8930 | for (i = 1; i < 16; i++) | |
8931 | { | |
8932 | specs[count] = tmpl; | |
8933 | specs[count++].index = i; | |
8934 | } | |
542d6675 KH |
8935 | } |
8936 | } | |
8937 | } | |
139368c9 JW |
8938 | else |
8939 | { | |
8940 | UNHANDLED; | |
8941 | } | |
8942 | break; | |
8943 | ||
8944 | /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are | |
8945 | simplified cases of this. */ | |
8946 | case IA64_RS_PRr: | |
8947 | if (note == 0) | |
8948 | { | |
8949 | for (i = 16; i < 63; i++) | |
8950 | { | |
8951 | specs[count] = tmpl; | |
8952 | specs[count++].index = i; | |
8953 | } | |
8954 | } | |
800eeca4 | 8955 | else if (note == 7) |
542d6675 KH |
8956 | { |
8957 | valueT mask = 0; | |
8958 | /* Mark only those registers indicated by the mask. */ | |
8959 | if (rsrc_write | |
8960 | && idesc->operands[0] == IA64_OPND_PR) | |
8961 | { | |
8962 | mask = CURR_SLOT.opnd[2].X_add_number; | |
40449e9f | 8963 | if (mask & ((valueT) 1 << 16)) |
139368c9 JW |
8964 | for (i = 16; i < 63; i++) |
8965 | { | |
8966 | specs[count] = tmpl; | |
8967 | specs[count++].index = i; | |
8968 | } | |
542d6675 KH |
8969 | } |
8970 | else if (rsrc_write | |
8971 | && idesc->operands[0] == IA64_OPND_PR_ROT) | |
8972 | { | |
8973 | for (i = 16; i < 63; i++) | |
8974 | { | |
8975 | specs[count] = tmpl; | |
8976 | specs[count++].index = i; | |
8977 | } | |
8978 | } | |
8979 | else | |
8980 | { | |
8981 | UNHANDLED; | |
8982 | } | |
8983 | } | |
800eeca4 | 8984 | else if (note == 11) /* note 11 implies note 1 as well */ |
542d6675 KH |
8985 | { |
8986 | if (rsrc_write) | |
8987 | { | |
8988 | for (i = 0; i < idesc->num_outputs; i++) | |
8989 | { | |
8990 | if (idesc->operands[i] == IA64_OPND_P1 | |
8991 | || idesc->operands[i] == IA64_OPND_P2) | |
8992 | { | |
8993 | int regno = CURR_SLOT.opnd[i].X_add_number - REG_P; | |
139368c9 | 8994 | if (regno >= 16 && regno < 63) |
542d6675 KH |
8995 | { |
8996 | specs[count] = tmpl; | |
8997 | specs[count++].index = regno; | |
8998 | } | |
8999 | } | |
9000 | } | |
9001 | } | |
9002 | else | |
9003 | { | |
9004 | UNHANDLED; | |
9005 | } | |
9006 | } | |
800eeca4 | 9007 | else if (note == 12) |
542d6675 | 9008 | { |
139368c9 | 9009 | if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63) |
542d6675 KH |
9010 | { |
9011 | specs[count] = tmpl; | |
9012 | specs[count++].index = CURR_SLOT.qp_regno; | |
9013 | } | |
9014 | } | |
800eeca4 | 9015 | else if (note == 1) |
542d6675 KH |
9016 | { |
9017 | if (rsrc_write) | |
9018 | { | |
9019 | int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P; | |
9020 | int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P; | |
07726851 KH |
9021 | int or_andcm = strstr (idesc->name, "or.andcm") != NULL; |
9022 | int and_orcm = strstr (idesc->name, "and.orcm") != NULL; | |
7484b8e6 | 9023 | |
542d6675 KH |
9024 | if ((idesc->operands[0] == IA64_OPND_P1 |
9025 | || idesc->operands[0] == IA64_OPND_P2) | |
139368c9 | 9026 | && p1 >= 16 && p1 < 63) |
542d6675 KH |
9027 | { |
9028 | specs[count] = tmpl; | |
4a4f25cf | 9029 | specs[count].cmp_type = |
7484b8e6 | 9030 | (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE)); |
542d6675 KH |
9031 | specs[count++].index = p1; |
9032 | } | |
9033 | if ((idesc->operands[1] == IA64_OPND_P1 | |
9034 | || idesc->operands[1] == IA64_OPND_P2) | |
139368c9 | 9035 | && p2 >= 16 && p2 < 63) |
542d6675 KH |
9036 | { |
9037 | specs[count] = tmpl; | |
4a4f25cf | 9038 | specs[count].cmp_type = |
7484b8e6 | 9039 | (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE)); |
542d6675 KH |
9040 | specs[count++].index = p2; |
9041 | } | |
9042 | } | |
9043 | else | |
9044 | { | |
139368c9 | 9045 | if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63) |
542d6675 KH |
9046 | { |
9047 | specs[count] = tmpl; | |
9048 | specs[count++].index = CURR_SLOT.qp_regno; | |
9049 | } | |
9050 | if (idesc->operands[1] == IA64_OPND_PR) | |
9051 | { | |
139368c9 | 9052 | for (i = 16; i < 63; i++) |
542d6675 KH |
9053 | { |
9054 | specs[count] = tmpl; | |
9055 | specs[count++].index = i; | |
9056 | } | |
9057 | } | |
9058 | } | |
9059 | } | |
197865e8 | 9060 | else |
542d6675 KH |
9061 | { |
9062 | UNHANDLED; | |
9063 | } | |
800eeca4 JW |
9064 | break; |
9065 | ||
9066 | case IA64_RS_PSR: | |
197865e8 | 9067 | /* Verify that the instruction is using the PSR bit indicated in |
542d6675 | 9068 | dep->regindex. */ |
800eeca4 | 9069 | if (note == 0) |
542d6675 KH |
9070 | { |
9071 | if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM) | |
9072 | { | |
9073 | if (dep->regindex < 6) | |
9074 | { | |
9075 | specs[count++] = tmpl; | |
9076 | } | |
9077 | } | |
9078 | else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR) | |
9079 | { | |
9080 | if (dep->regindex < 32 | |
9081 | || dep->regindex == 35 | |
9082 | || dep->regindex == 36 | |
9083 | || (!rsrc_write && dep->regindex == PSR_CPL)) | |
9084 | { | |
9085 | specs[count++] = tmpl; | |
9086 | } | |
9087 | } | |
9088 | else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L) | |
9089 | { | |
9090 | if (dep->regindex < 32 | |
9091 | || dep->regindex == 35 | |
9092 | || dep->regindex == 36 | |
9093 | || (rsrc_write && dep->regindex == PSR_CPL)) | |
9094 | { | |
9095 | specs[count++] = tmpl; | |
9096 | } | |
9097 | } | |
9098 | else | |
9099 | { | |
9100 | /* Several PSR bits have very specific dependencies. */ | |
9101 | switch (dep->regindex) | |
9102 | { | |
9103 | default: | |
9104 | specs[count++] = tmpl; | |
9105 | break; | |
9106 | case PSR_IC: | |
9107 | if (rsrc_write) | |
9108 | { | |
9109 | specs[count++] = tmpl; | |
9110 | } | |
9111 | else | |
9112 | { | |
9113 | /* Only certain CR accesses use PSR.ic */ | |
9114 | if (idesc->operands[0] == IA64_OPND_CR3 | |
9115 | || idesc->operands[1] == IA64_OPND_CR3) | |
9116 | { | |
91d6fa6a | 9117 | int reg_index = |
542d6675 KH |
9118 | ((idesc->operands[0] == IA64_OPND_CR3) |
9119 | ? 0 : 1); | |
9120 | int regno = | |
91d6fa6a | 9121 | CURR_SLOT.opnd[reg_index].X_add_number - REG_CR; |
542d6675 KH |
9122 | |
9123 | switch (regno) | |
9124 | { | |
9125 | default: | |
9126 | break; | |
9127 | case CR_ITIR: | |
9128 | case CR_IFS: | |
9129 | case CR_IIM: | |
9130 | case CR_IIP: | |
9131 | case CR_IPSR: | |
9132 | case CR_ISR: | |
9133 | case CR_IFA: | |
9134 | case CR_IHA: | |
1ca35711 L |
9135 | case CR_IIB0: |
9136 | case CR_IIB1: | |
542d6675 KH |
9137 | case CR_IIPA: |
9138 | specs[count++] = tmpl; | |
9139 | break; | |
9140 | } | |
9141 | } | |
9142 | } | |
9143 | break; | |
9144 | case PSR_CPL: | |
9145 | if (rsrc_write) | |
9146 | { | |
9147 | specs[count++] = tmpl; | |
9148 | } | |
9149 | else | |
9150 | { | |
9151 | /* Only some AR accesses use cpl */ | |
9152 | if (idesc->operands[0] == IA64_OPND_AR3 | |
9153 | || idesc->operands[1] == IA64_OPND_AR3) | |
9154 | { | |
91d6fa6a | 9155 | int reg_index = |
542d6675 KH |
9156 | ((idesc->operands[0] == IA64_OPND_AR3) |
9157 | ? 0 : 1); | |
9158 | int regno = | |
91d6fa6a | 9159 | CURR_SLOT.opnd[reg_index].X_add_number - REG_AR; |
542d6675 KH |
9160 | |
9161 | if (regno == AR_ITC | |
4f8631b1 | 9162 | || regno == AR_RUC |
91d6fa6a | 9163 | || (reg_index == 0 |
4f8631b1 | 9164 | && (regno == AR_RSC |
542d6675 KH |
9165 | || (regno >= AR_K0 |
9166 | && regno <= AR_K7)))) | |
9167 | { | |
9168 | specs[count++] = tmpl; | |
9169 | } | |
9170 | } | |
9171 | else | |
9172 | { | |
9173 | specs[count++] = tmpl; | |
9174 | } | |
9175 | break; | |
9176 | } | |
9177 | } | |
9178 | } | |
9179 | } | |
800eeca4 | 9180 | else if (note == 7) |
542d6675 KH |
9181 | { |
9182 | valueT mask = 0; | |
9183 | if (idesc->operands[0] == IA64_OPND_IMMU24) | |
9184 | { | |
9185 | mask = CURR_SLOT.opnd[0].X_add_number; | |
9186 | } | |
9187 | else | |
9188 | { | |
9189 | UNHANDLED; | |
9190 | } | |
9191 | if (mask & ((valueT) 1 << dep->regindex)) | |
9192 | { | |
9193 | specs[count++] = tmpl; | |
9194 | } | |
9195 | } | |
800eeca4 | 9196 | else if (note == 8) |
542d6675 KH |
9197 | { |
9198 | int min = dep->regindex == PSR_DFL ? 2 : 32; | |
9199 | int max = dep->regindex == PSR_DFL ? 31 : 127; | |
9200 | /* dfh is read on FR32-127; dfl is read on FR2-31 */ | |
9201 | for (i = 0; i < NELEMS (idesc->operands); i++) | |
9202 | { | |
9203 | if (idesc->operands[i] == IA64_OPND_F1 | |
9204 | || idesc->operands[i] == IA64_OPND_F2 | |
9205 | || idesc->operands[i] == IA64_OPND_F3 | |
9206 | || idesc->operands[i] == IA64_OPND_F4) | |
9207 | { | |
9208 | int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR; | |
9209 | if (reg >= min && reg <= max) | |
9210 | { | |
9211 | specs[count++] = tmpl; | |
9212 | } | |
9213 | } | |
9214 | } | |
9215 | } | |
800eeca4 | 9216 | else if (note == 9) |
542d6675 KH |
9217 | { |
9218 | int min = dep->regindex == PSR_MFL ? 2 : 32; | |
9219 | int max = dep->regindex == PSR_MFL ? 31 : 127; | |
9220 | /* mfh is read on writes to FR32-127; mfl is read on writes to | |
9221 | FR2-31 */ | |
9222 | for (i = 0; i < idesc->num_outputs; i++) | |
9223 | { | |
9224 | if (idesc->operands[i] == IA64_OPND_F1) | |
9225 | { | |
9226 | int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR; | |
9227 | if (reg >= min && reg <= max) | |
9228 | { | |
9229 | specs[count++] = tmpl; | |
9230 | } | |
9231 | } | |
9232 | } | |
9233 | } | |
800eeca4 | 9234 | else if (note == 10) |
542d6675 KH |
9235 | { |
9236 | for (i = 0; i < NELEMS (idesc->operands); i++) | |
9237 | { | |
9238 | if (idesc->operands[i] == IA64_OPND_R1 | |
9239 | || idesc->operands[i] == IA64_OPND_R2 | |
9240 | || idesc->operands[i] == IA64_OPND_R3) | |
9241 | { | |
9242 | int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR; | |
9243 | if (regno >= 16 && regno <= 31) | |
9244 | { | |
9245 | specs[count++] = tmpl; | |
9246 | } | |
9247 | } | |
9248 | } | |
9249 | } | |
800eeca4 | 9250 | else |
542d6675 KH |
9251 | { |
9252 | UNHANDLED; | |
9253 | } | |
800eeca4 JW |
9254 | break; |
9255 | ||
9256 | case IA64_RS_AR_FPSR: | |
9257 | if (idesc->operands[!rsrc_write] == IA64_OPND_AR3) | |
542d6675 KH |
9258 | { |
9259 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR; | |
9260 | if (regno == AR_FPSR) | |
9261 | { | |
9262 | specs[count++] = tmpl; | |
9263 | } | |
9264 | } | |
800eeca4 | 9265 | else |
542d6675 KH |
9266 | { |
9267 | specs[count++] = tmpl; | |
9268 | } | |
800eeca4 JW |
9269 | break; |
9270 | ||
197865e8 | 9271 | case IA64_RS_ARX: |
800eeca4 JW |
9272 | /* Handle all AR[REG] resources */ |
9273 | if (note == 0 || note == 1) | |
542d6675 KH |
9274 | { |
9275 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR; | |
9276 | if (idesc->operands[!rsrc_write] == IA64_OPND_AR3 | |
9277 | && regno == dep->regindex) | |
9278 | { | |
9279 | specs[count++] = tmpl; | |
9280 | } | |
9281 | /* other AR[REG] resources may be affected by AR accesses */ | |
9282 | else if (idesc->operands[0] == IA64_OPND_AR3) | |
9283 | { | |
9284 | /* AR[] writes */ | |
9285 | regno = CURR_SLOT.opnd[0].X_add_number - REG_AR; | |
9286 | switch (dep->regindex) | |
9287 | { | |
9288 | default: | |
9289 | break; | |
9290 | case AR_BSP: | |
9291 | case AR_RNAT: | |
9292 | if (regno == AR_BSPSTORE) | |
9293 | { | |
9294 | specs[count++] = tmpl; | |
9295 | } | |
9296 | case AR_RSC: | |
9297 | if (!rsrc_write && | |
9298 | (regno == AR_BSPSTORE | |
9299 | || regno == AR_RNAT)) | |
9300 | { | |
9301 | specs[count++] = tmpl; | |
9302 | } | |
9303 | break; | |
9304 | } | |
9305 | } | |
9306 | else if (idesc->operands[1] == IA64_OPND_AR3) | |
9307 | { | |
9308 | /* AR[] reads */ | |
9309 | regno = CURR_SLOT.opnd[1].X_add_number - REG_AR; | |
9310 | switch (dep->regindex) | |
9311 | { | |
9312 | default: | |
9313 | break; | |
9314 | case AR_RSC: | |
9315 | if (regno == AR_BSPSTORE || regno == AR_RNAT) | |
9316 | { | |
9317 | specs[count++] = tmpl; | |
9318 | } | |
9319 | break; | |
9320 | } | |
9321 | } | |
9322 | else | |
9323 | { | |
9324 | specs[count++] = tmpl; | |
9325 | } | |
9326 | } | |
800eeca4 | 9327 | else |
542d6675 KH |
9328 | { |
9329 | UNHANDLED; | |
9330 | } | |
800eeca4 JW |
9331 | break; |
9332 | ||
9333 | case IA64_RS_CRX: | |
7f3dfb9c L |
9334 | /* Handle all CR[REG] resources. |
9335 | ??? FIXME: The rule 17 isn't really handled correctly. */ | |
9336 | if (note == 0 || note == 1 || note == 17) | |
542d6675 KH |
9337 | { |
9338 | if (idesc->operands[!rsrc_write] == IA64_OPND_CR3) | |
9339 | { | |
9340 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR; | |
9341 | if (regno == dep->regindex) | |
9342 | { | |
9343 | specs[count++] = tmpl; | |
9344 | } | |
9345 | else if (!rsrc_write) | |
9346 | { | |
9347 | /* Reads from CR[IVR] affect other resources. */ | |
9348 | if (regno == CR_IVR) | |
9349 | { | |
9350 | if ((dep->regindex >= CR_IRR0 | |
9351 | && dep->regindex <= CR_IRR3) | |
9352 | || dep->regindex == CR_TPR) | |
9353 | { | |
9354 | specs[count++] = tmpl; | |
9355 | } | |
9356 | } | |
9357 | } | |
9358 | } | |
9359 | else | |
9360 | { | |
9361 | specs[count++] = tmpl; | |
9362 | } | |
9363 | } | |
800eeca4 | 9364 | else |
542d6675 KH |
9365 | { |
9366 | UNHANDLED; | |
9367 | } | |
800eeca4 JW |
9368 | break; |
9369 | ||
9370 | case IA64_RS_INSERVICE: | |
9371 | /* look for write of EOI (67) or read of IVR (65) */ | |
9372 | if ((idesc->operands[0] == IA64_OPND_CR3 | |
542d6675 KH |
9373 | && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI) |
9374 | || (idesc->operands[1] == IA64_OPND_CR3 | |
9375 | && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR)) | |
9376 | { | |
9377 | specs[count++] = tmpl; | |
9378 | } | |
800eeca4 JW |
9379 | break; |
9380 | ||
9381 | case IA64_RS_GR0: | |
9382 | if (note == 1) | |
542d6675 KH |
9383 | { |
9384 | specs[count++] = tmpl; | |
9385 | } | |
800eeca4 | 9386 | else |
542d6675 KH |
9387 | { |
9388 | UNHANDLED; | |
9389 | } | |
800eeca4 JW |
9390 | break; |
9391 | ||
9392 | case IA64_RS_CFM: | |
9393 | if (note != 2) | |
542d6675 KH |
9394 | { |
9395 | specs[count++] = tmpl; | |
9396 | } | |
800eeca4 | 9397 | else |
542d6675 KH |
9398 | { |
9399 | /* Check if any of the registers accessed are in the rotating region. | |
9400 | mov to/from pr accesses CFM only when qp_regno is in the rotating | |
9401 | region */ | |
9402 | for (i = 0; i < NELEMS (idesc->operands); i++) | |
9403 | { | |
9404 | if (idesc->operands[i] == IA64_OPND_R1 | |
9405 | || idesc->operands[i] == IA64_OPND_R2 | |
9406 | || idesc->operands[i] == IA64_OPND_R3) | |
9407 | { | |
9408 | int num = CURR_SLOT.opnd[i].X_add_number - REG_GR; | |
9409 | /* Assumes that md.rot.num_regs is always valid */ | |
9410 | if (md.rot.num_regs > 0 | |
9411 | && num > 31 | |
9412 | && num < 31 + md.rot.num_regs) | |
9413 | { | |
9414 | specs[count] = tmpl; | |
9415 | specs[count++].specific = 0; | |
9416 | } | |
9417 | } | |
9418 | else if (idesc->operands[i] == IA64_OPND_F1 | |
9419 | || idesc->operands[i] == IA64_OPND_F2 | |
9420 | || idesc->operands[i] == IA64_OPND_F3 | |
9421 | || idesc->operands[i] == IA64_OPND_F4) | |
9422 | { | |
9423 | int num = CURR_SLOT.opnd[i].X_add_number - REG_FR; | |
9424 | if (num > 31) | |
9425 | { | |
9426 | specs[count] = tmpl; | |
9427 | specs[count++].specific = 0; | |
9428 | } | |
9429 | } | |
9430 | else if (idesc->operands[i] == IA64_OPND_P1 | |
9431 | || idesc->operands[i] == IA64_OPND_P2) | |
9432 | { | |
9433 | int num = CURR_SLOT.opnd[i].X_add_number - REG_P; | |
9434 | if (num > 15) | |
9435 | { | |
9436 | specs[count] = tmpl; | |
9437 | specs[count++].specific = 0; | |
9438 | } | |
9439 | } | |
9440 | } | |
9441 | if (CURR_SLOT.qp_regno > 15) | |
9442 | { | |
9443 | specs[count] = tmpl; | |
9444 | specs[count++].specific = 0; | |
9445 | } | |
9446 | } | |
800eeca4 JW |
9447 | break; |
9448 | ||
139368c9 JW |
9449 | /* This is the same as IA64_RS_PRr, except simplified to account for |
9450 | the fact that there is only one register. */ | |
800eeca4 JW |
9451 | case IA64_RS_PR63: |
9452 | if (note == 0) | |
542d6675 KH |
9453 | { |
9454 | specs[count++] = tmpl; | |
9455 | } | |
139368c9 | 9456 | else if (note == 7) |
40449e9f KH |
9457 | { |
9458 | valueT mask = 0; | |
9459 | if (idesc->operands[2] == IA64_OPND_IMM17) | |
9460 | mask = CURR_SLOT.opnd[2].X_add_number; | |
9461 | if (mask & ((valueT) 1 << 63)) | |
139368c9 | 9462 | specs[count++] = tmpl; |
40449e9f | 9463 | } |
800eeca4 | 9464 | else if (note == 11) |
542d6675 KH |
9465 | { |
9466 | if ((idesc->operands[0] == IA64_OPND_P1 | |
9467 | && CURR_SLOT.opnd[0].X_add_number - REG_P == 63) | |
9468 | || (idesc->operands[1] == IA64_OPND_P2 | |
9469 | && CURR_SLOT.opnd[1].X_add_number - REG_P == 63)) | |
9470 | { | |
9471 | specs[count++] = tmpl; | |
9472 | } | |
9473 | } | |
800eeca4 | 9474 | else if (note == 12) |
542d6675 KH |
9475 | { |
9476 | if (CURR_SLOT.qp_regno == 63) | |
9477 | { | |
9478 | specs[count++] = tmpl; | |
9479 | } | |
9480 | } | |
800eeca4 | 9481 | else if (note == 1) |
542d6675 KH |
9482 | { |
9483 | if (rsrc_write) | |
9484 | { | |
40449e9f KH |
9485 | int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P; |
9486 | int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P; | |
07726851 KH |
9487 | int or_andcm = strstr (idesc->name, "or.andcm") != NULL; |
9488 | int and_orcm = strstr (idesc->name, "and.orcm") != NULL; | |
7484b8e6 | 9489 | |
4a4f25cf | 9490 | if (p1 == 63 |
7484b8e6 TW |
9491 | && (idesc->operands[0] == IA64_OPND_P1 |
9492 | || idesc->operands[0] == IA64_OPND_P2)) | |
9493 | { | |
40449e9f | 9494 | specs[count] = tmpl; |
4a4f25cf | 9495 | specs[count++].cmp_type = |
7484b8e6 TW |
9496 | (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE)); |
9497 | } | |
9498 | if (p2 == 63 | |
9499 | && (idesc->operands[1] == IA64_OPND_P1 | |
9500 | || idesc->operands[1] == IA64_OPND_P2)) | |
9501 | { | |
40449e9f | 9502 | specs[count] = tmpl; |
4a4f25cf | 9503 | specs[count++].cmp_type = |
7484b8e6 TW |
9504 | (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE)); |
9505 | } | |
542d6675 KH |
9506 | } |
9507 | else | |
9508 | { | |
9509 | if (CURR_SLOT.qp_regno == 63) | |
9510 | { | |
9511 | specs[count++] = tmpl; | |
9512 | } | |
9513 | } | |
9514 | } | |
800eeca4 | 9515 | else |
542d6675 KH |
9516 | { |
9517 | UNHANDLED; | |
9518 | } | |
800eeca4 JW |
9519 | break; |
9520 | ||
9521 | case IA64_RS_RSE: | |
9522 | /* FIXME we can identify some individual RSE written resources, but RSE | |
542d6675 KH |
9523 | read resources have not yet been completely identified, so for now |
9524 | treat RSE as a single resource */ | |
800eeca4 | 9525 | if (strncmp (idesc->name, "mov", 3) == 0) |
542d6675 KH |
9526 | { |
9527 | if (rsrc_write) | |
9528 | { | |
9529 | if (idesc->operands[0] == IA64_OPND_AR3 | |
9530 | && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE) | |
9531 | { | |
a66d2bb7 | 9532 | specs[count++] = tmpl; |
542d6675 KH |
9533 | } |
9534 | } | |
9535 | else | |
9536 | { | |
9537 | if (idesc->operands[0] == IA64_OPND_AR3) | |
9538 | { | |
9539 | if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE | |
9540 | || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT) | |
9541 | { | |
9542 | specs[count++] = tmpl; | |
9543 | } | |
9544 | } | |
9545 | else if (idesc->operands[1] == IA64_OPND_AR3) | |
9546 | { | |
9547 | if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP | |
9548 | || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE | |
9549 | || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT) | |
9550 | { | |
9551 | specs[count++] = tmpl; | |
9552 | } | |
9553 | } | |
9554 | } | |
9555 | } | |
197865e8 | 9556 | else |
542d6675 KH |
9557 | { |
9558 | specs[count++] = tmpl; | |
9559 | } | |
800eeca4 JW |
9560 | break; |
9561 | ||
9562 | case IA64_RS_ANY: | |
9563 | /* FIXME -- do any of these need to be non-specific? */ | |
9564 | specs[count++] = tmpl; | |
9565 | break; | |
9566 | ||
9567 | default: | |
9568 | as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier); | |
9569 | break; | |
9570 | } | |
9571 | ||
9572 | return count; | |
9573 | } | |
9574 | ||
9575 | /* Clear branch flags on marked resources. This breaks the link between the | |
542d6675 KH |
9576 | QP of the marking instruction and a subsequent branch on the same QP. */ |
9577 | ||
800eeca4 | 9578 | static void |
5a49b8ac | 9579 | clear_qp_branch_flag (valueT mask) |
800eeca4 JW |
9580 | { |
9581 | int i; | |
542d6675 | 9582 | for (i = 0; i < regdepslen; i++) |
800eeca4 | 9583 | { |
197865e8 | 9584 | valueT bit = ((valueT) 1 << regdeps[i].qp_regno); |
800eeca4 | 9585 | if ((bit & mask) != 0) |
542d6675 KH |
9586 | { |
9587 | regdeps[i].link_to_qp_branch = 0; | |
9588 | } | |
800eeca4 JW |
9589 | } |
9590 | } | |
9591 | ||
5e2f6673 L |
9592 | /* MASK contains 2 and only 2 PRs which are mutually exclusive. Remove |
9593 | any mutexes which contain one of the PRs and create new ones when | |
9594 | needed. */ | |
9595 | ||
9596 | static int | |
9597 | update_qp_mutex (valueT mask) | |
9598 | { | |
9599 | int i; | |
9600 | int add = 0; | |
9601 | ||
9602 | i = 0; | |
9603 | while (i < qp_mutexeslen) | |
9604 | { | |
9605 | if ((qp_mutexes[i].prmask & mask) != 0) | |
9606 | { | |
9607 | /* If it destroys and creates the same mutex, do nothing. */ | |
9608 | if (qp_mutexes[i].prmask == mask | |
9609 | && qp_mutexes[i].path == md.path) | |
9610 | { | |
9611 | i++; | |
9612 | add = -1; | |
9613 | } | |
9614 | else | |
9615 | { | |
9616 | int keep = 0; | |
9617 | ||
9618 | if (md.debug_dv) | |
9619 | { | |
9620 | fprintf (stderr, " Clearing mutex relation"); | |
9621 | print_prmask (qp_mutexes[i].prmask); | |
9622 | fprintf (stderr, "\n"); | |
9623 | } | |
3739860c | 9624 | |
5e2f6673 L |
9625 | /* Deal with the old mutex with more than 3+ PRs only if |
9626 | the new mutex on the same execution path with it. | |
9627 | ||
9628 | FIXME: The 3+ mutex support is incomplete. | |
9629 | dot_pred_rel () may be a better place to fix it. */ | |
9630 | if (qp_mutexes[i].path == md.path) | |
9631 | { | |
9632 | /* If it is a proper subset of the mutex, create a | |
9633 | new mutex. */ | |
9634 | if (add == 0 | |
9635 | && (qp_mutexes[i].prmask & mask) == mask) | |
9636 | add = 1; | |
3739860c | 9637 | |
5e2f6673 L |
9638 | qp_mutexes[i].prmask &= ~mask; |
9639 | if (qp_mutexes[i].prmask & (qp_mutexes[i].prmask - 1)) | |
9640 | { | |
9641 | /* Modify the mutex if there are more than one | |
9642 | PR left. */ | |
9643 | keep = 1; | |
9644 | i++; | |
9645 | } | |
9646 | } | |
3739860c | 9647 | |
5e2f6673 L |
9648 | if (keep == 0) |
9649 | /* Remove the mutex. */ | |
9650 | qp_mutexes[i] = qp_mutexes[--qp_mutexeslen]; | |
9651 | } | |
9652 | } | |
9653 | else | |
9654 | ++i; | |
9655 | } | |
9656 | ||
9657 | if (add == 1) | |
9658 | add_qp_mutex (mask); | |
9659 | ||
9660 | return add; | |
9661 | } | |
9662 | ||
197865e8 | 9663 | /* Remove any mutexes which contain any of the PRs indicated in the mask. |
800eeca4 | 9664 | |
542d6675 KH |
9665 | Any changes to a PR clears the mutex relations which include that PR. */ |
9666 | ||
800eeca4 | 9667 | static void |
5a49b8ac | 9668 | clear_qp_mutex (valueT mask) |
800eeca4 JW |
9669 | { |
9670 | int i; | |
9671 | ||
9672 | i = 0; | |
9673 | while (i < qp_mutexeslen) | |
9674 | { | |
9675 | if ((qp_mutexes[i].prmask & mask) != 0) | |
542d6675 KH |
9676 | { |
9677 | if (md.debug_dv) | |
9678 | { | |
9679 | fprintf (stderr, " Clearing mutex relation"); | |
9680 | print_prmask (qp_mutexes[i].prmask); | |
9681 | fprintf (stderr, "\n"); | |
9682 | } | |
9683 | qp_mutexes[i] = qp_mutexes[--qp_mutexeslen]; | |
9684 | } | |
800eeca4 | 9685 | else |
542d6675 | 9686 | ++i; |
800eeca4 JW |
9687 | } |
9688 | } | |
9689 | ||
9690 | /* Clear implies relations which contain PRs in the given masks. | |
9691 | P1_MASK indicates the source of the implies relation, while P2_MASK | |
542d6675 KH |
9692 | indicates the implied PR. */ |
9693 | ||
800eeca4 | 9694 | static void |
5a49b8ac | 9695 | clear_qp_implies (valueT p1_mask, valueT p2_mask) |
800eeca4 JW |
9696 | { |
9697 | int i; | |
9698 | ||
9699 | i = 0; | |
9700 | while (i < qp_implieslen) | |
9701 | { | |
197865e8 | 9702 | if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0 |
542d6675 KH |
9703 | || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0) |
9704 | { | |
9705 | if (md.debug_dv) | |
9706 | fprintf (stderr, "Clearing implied relation PR%d->PR%d\n", | |
9707 | qp_implies[i].p1, qp_implies[i].p2); | |
9708 | qp_implies[i] = qp_implies[--qp_implieslen]; | |
9709 | } | |
197865e8 | 9710 | else |
542d6675 | 9711 | ++i; |
800eeca4 JW |
9712 | } |
9713 | } | |
9714 | ||
542d6675 KH |
9715 | /* Add the PRs specified to the list of implied relations. */ |
9716 | ||
800eeca4 | 9717 | static void |
5a49b8ac | 9718 | add_qp_imply (int p1, int p2) |
800eeca4 JW |
9719 | { |
9720 | valueT mask; | |
9721 | valueT bit; | |
9722 | int i; | |
9723 | ||
542d6675 | 9724 | /* p0 is not meaningful here. */ |
800eeca4 JW |
9725 | if (p1 == 0 || p2 == 0) |
9726 | abort (); | |
9727 | ||
9728 | if (p1 == p2) | |
9729 | return; | |
9730 | ||
542d6675 KH |
9731 | /* If it exists already, ignore it. */ |
9732 | for (i = 0; i < qp_implieslen; i++) | |
800eeca4 | 9733 | { |
197865e8 | 9734 | if (qp_implies[i].p1 == p1 |
542d6675 KH |
9735 | && qp_implies[i].p2 == p2 |
9736 | && qp_implies[i].path == md.path | |
9737 | && !qp_implies[i].p2_branched) | |
9738 | return; | |
800eeca4 JW |
9739 | } |
9740 | ||
9741 | if (qp_implieslen == qp_impliestotlen) | |
9742 | { | |
9743 | qp_impliestotlen += 20; | |
9744 | qp_implies = (struct qp_imply *) | |
542d6675 KH |
9745 | xrealloc ((void *) qp_implies, |
9746 | qp_impliestotlen * sizeof (struct qp_imply)); | |
800eeca4 JW |
9747 | } |
9748 | if (md.debug_dv) | |
9749 | fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2); | |
9750 | qp_implies[qp_implieslen].p1 = p1; | |
9751 | qp_implies[qp_implieslen].p2 = p2; | |
9752 | qp_implies[qp_implieslen].path = md.path; | |
9753 | qp_implies[qp_implieslen++].p2_branched = 0; | |
9754 | ||
9755 | /* Add in the implied transitive relations; for everything that p2 implies, | |
9756 | make p1 imply that, too; for everything that implies p1, make it imply p2 | |
197865e8 | 9757 | as well. */ |
542d6675 | 9758 | for (i = 0; i < qp_implieslen; i++) |
800eeca4 JW |
9759 | { |
9760 | if (qp_implies[i].p1 == p2) | |
542d6675 | 9761 | add_qp_imply (p1, qp_implies[i].p2); |
800eeca4 | 9762 | if (qp_implies[i].p2 == p1) |
542d6675 | 9763 | add_qp_imply (qp_implies[i].p1, p2); |
800eeca4 JW |
9764 | } |
9765 | /* Add in mutex relations implied by this implies relation; for each mutex | |
197865e8 KH |
9766 | relation containing p2, duplicate it and replace p2 with p1. */ |
9767 | bit = (valueT) 1 << p1; | |
9768 | mask = (valueT) 1 << p2; | |
542d6675 | 9769 | for (i = 0; i < qp_mutexeslen; i++) |
800eeca4 JW |
9770 | { |
9771 | if (qp_mutexes[i].prmask & mask) | |
542d6675 | 9772 | add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit); |
800eeca4 JW |
9773 | } |
9774 | } | |
9775 | ||
800eeca4 JW |
9776 | /* Add the PRs specified in the mask to the mutex list; this means that only |
9777 | one of the PRs can be true at any time. PR0 should never be included in | |
9778 | the mask. */ | |
542d6675 | 9779 | |
800eeca4 | 9780 | static void |
5a49b8ac | 9781 | add_qp_mutex (valueT mask) |
800eeca4 JW |
9782 | { |
9783 | if (mask & 0x1) | |
9784 | abort (); | |
9785 | ||
9786 | if (qp_mutexeslen == qp_mutexestotlen) | |
9787 | { | |
9788 | qp_mutexestotlen += 20; | |
9789 | qp_mutexes = (struct qpmutex *) | |
542d6675 KH |
9790 | xrealloc ((void *) qp_mutexes, |
9791 | qp_mutexestotlen * sizeof (struct qpmutex)); | |
800eeca4 JW |
9792 | } |
9793 | if (md.debug_dv) | |
9794 | { | |
9795 | fprintf (stderr, " Registering mutex on"); | |
9796 | print_prmask (mask); | |
9797 | fprintf (stderr, "\n"); | |
9798 | } | |
9799 | qp_mutexes[qp_mutexeslen].path = md.path; | |
9800 | qp_mutexes[qp_mutexeslen++].prmask = mask; | |
9801 | } | |
9802 | ||
cb5301b6 | 9803 | static int |
5a49b8ac | 9804 | has_suffix_p (const char *name, const char *suffix) |
cb5301b6 RH |
9805 | { |
9806 | size_t namelen = strlen (name); | |
9807 | size_t sufflen = strlen (suffix); | |
9808 | ||
9809 | if (namelen <= sufflen) | |
9810 | return 0; | |
9811 | return strcmp (name + namelen - sufflen, suffix) == 0; | |
9812 | } | |
9813 | ||
800eeca4 | 9814 | static void |
5a49b8ac | 9815 | clear_register_values (void) |
800eeca4 JW |
9816 | { |
9817 | int i; | |
9818 | if (md.debug_dv) | |
9819 | fprintf (stderr, " Clearing register values\n"); | |
542d6675 | 9820 | for (i = 1; i < NELEMS (gr_values); i++) |
800eeca4 JW |
9821 | gr_values[i].known = 0; |
9822 | } | |
9823 | ||
9824 | /* Keep track of register values/changes which affect DV tracking. | |
9825 | ||
9826 | optimization note: should add a flag to classes of insns where otherwise we | |
542d6675 | 9827 | have to examine a group of strings to identify them. */ |
800eeca4 | 9828 | |
800eeca4 | 9829 | static void |
5a49b8ac | 9830 | note_register_values (struct ia64_opcode *idesc) |
800eeca4 JW |
9831 | { |
9832 | valueT qp_changemask = 0; | |
9833 | int i; | |
9834 | ||
542d6675 KH |
9835 | /* Invalidate values for registers being written to. */ |
9836 | for (i = 0; i < idesc->num_outputs; i++) | |
800eeca4 | 9837 | { |
197865e8 | 9838 | if (idesc->operands[i] == IA64_OPND_R1 |
542d6675 KH |
9839 | || idesc->operands[i] == IA64_OPND_R2 |
9840 | || idesc->operands[i] == IA64_OPND_R3) | |
9841 | { | |
9842 | int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR; | |
9843 | if (regno > 0 && regno < NELEMS (gr_values)) | |
9844 | gr_values[regno].known = 0; | |
9845 | } | |
50b81f19 JW |
9846 | else if (idesc->operands[i] == IA64_OPND_R3_2) |
9847 | { | |
9848 | int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR; | |
9849 | if (regno > 0 && regno < 4) | |
9850 | gr_values[regno].known = 0; | |
9851 | } | |
197865e8 | 9852 | else if (idesc->operands[i] == IA64_OPND_P1 |
542d6675 KH |
9853 | || idesc->operands[i] == IA64_OPND_P2) |
9854 | { | |
9855 | int regno = CURR_SLOT.opnd[i].X_add_number - REG_P; | |
9856 | qp_changemask |= (valueT) 1 << regno; | |
9857 | } | |
800eeca4 | 9858 | else if (idesc->operands[i] == IA64_OPND_PR) |
542d6675 KH |
9859 | { |
9860 | if (idesc->operands[2] & (valueT) 0x10000) | |
9861 | qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2]; | |
9862 | else | |
9863 | qp_changemask = idesc->operands[2]; | |
9864 | break; | |
9865 | } | |
800eeca4 | 9866 | else if (idesc->operands[i] == IA64_OPND_PR_ROT) |
542d6675 KH |
9867 | { |
9868 | if (idesc->operands[1] & ((valueT) 1 << 43)) | |
6344efa4 | 9869 | qp_changemask = -((valueT) 1 << 44) | idesc->operands[1]; |
542d6675 KH |
9870 | else |
9871 | qp_changemask = idesc->operands[1]; | |
9872 | qp_changemask &= ~(valueT) 0xFFFF; | |
9873 | break; | |
9874 | } | |
9875 | } | |
9876 | ||
9877 | /* Always clear qp branch flags on any PR change. */ | |
9878 | /* FIXME there may be exceptions for certain compares. */ | |
800eeca4 JW |
9879 | clear_qp_branch_flag (qp_changemask); |
9880 | ||
542d6675 | 9881 | /* Invalidate rotating registers on insns which affect RRBs in CFM. */ |
800eeca4 JW |
9882 | if (idesc->flags & IA64_OPCODE_MOD_RRBS) |
9883 | { | |
197865e8 | 9884 | qp_changemask |= ~(valueT) 0xFFFF; |
800eeca4 | 9885 | if (strcmp (idesc->name, "clrrrb.pr") != 0) |
542d6675 KH |
9886 | { |
9887 | for (i = 32; i < 32 + md.rot.num_regs; i++) | |
9888 | gr_values[i].known = 0; | |
9889 | } | |
800eeca4 JW |
9890 | clear_qp_mutex (qp_changemask); |
9891 | clear_qp_implies (qp_changemask, qp_changemask); | |
9892 | } | |
542d6675 KH |
9893 | /* After a call, all register values are undefined, except those marked |
9894 | as "safe". */ | |
800eeca4 | 9895 | else if (strncmp (idesc->name, "br.call", 6) == 0 |
542d6675 | 9896 | || strncmp (idesc->name, "brl.call", 7) == 0) |
800eeca4 | 9897 | { |
56d27c17 | 9898 | /* FIXME keep GR values which are marked as "safe_across_calls" */ |
800eeca4 JW |
9899 | clear_register_values (); |
9900 | clear_qp_mutex (~qp_safe_across_calls); | |
9901 | clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls); | |
9902 | clear_qp_branch_flag (~qp_safe_across_calls); | |
9903 | } | |
e9718fe1 | 9904 | else if (is_interruption_or_rfi (idesc) |
542d6675 | 9905 | || is_taken_branch (idesc)) |
e9718fe1 TW |
9906 | { |
9907 | clear_register_values (); | |
197865e8 KH |
9908 | clear_qp_mutex (~(valueT) 0); |
9909 | clear_qp_implies (~(valueT) 0, ~(valueT) 0); | |
e9718fe1 | 9910 | } |
542d6675 | 9911 | /* Look for mutex and implies relations. */ |
197865e8 | 9912 | else if ((idesc->operands[0] == IA64_OPND_P1 |
542d6675 KH |
9913 | || idesc->operands[0] == IA64_OPND_P2) |
9914 | && (idesc->operands[1] == IA64_OPND_P1 | |
9915 | || idesc->operands[1] == IA64_OPND_P2)) | |
800eeca4 JW |
9916 | { |
9917 | int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P; | |
197865e8 | 9918 | int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P; |
5e2f6673 L |
9919 | valueT p1mask = (p1 != 0) ? (valueT) 1 << p1 : 0; |
9920 | valueT p2mask = (p2 != 0) ? (valueT) 1 << p2 : 0; | |
800eeca4 | 9921 | |
5e2f6673 L |
9922 | /* If both PRs are PR0, we can't really do anything. */ |
9923 | if (p1 == 0 && p2 == 0) | |
542d6675 KH |
9924 | { |
9925 | if (md.debug_dv) | |
9926 | fprintf (stderr, " Ignoring PRs due to inclusion of p0\n"); | |
9927 | } | |
800eeca4 | 9928 | /* In general, clear mutexes and implies which include P1 or P2, |
542d6675 | 9929 | with the following exceptions. */ |
cb5301b6 RH |
9930 | else if (has_suffix_p (idesc->name, ".or.andcm") |
9931 | || has_suffix_p (idesc->name, ".and.orcm")) | |
542d6675 | 9932 | { |
542d6675 KH |
9933 | clear_qp_implies (p2mask, p1mask); |
9934 | } | |
cb5301b6 RH |
9935 | else if (has_suffix_p (idesc->name, ".andcm") |
9936 | || has_suffix_p (idesc->name, ".and")) | |
542d6675 KH |
9937 | { |
9938 | clear_qp_implies (0, p1mask | p2mask); | |
9939 | } | |
cb5301b6 RH |
9940 | else if (has_suffix_p (idesc->name, ".orcm") |
9941 | || has_suffix_p (idesc->name, ".or")) | |
542d6675 KH |
9942 | { |
9943 | clear_qp_mutex (p1mask | p2mask); | |
9944 | clear_qp_implies (p1mask | p2mask, 0); | |
9945 | } | |
800eeca4 | 9946 | else |
542d6675 | 9947 | { |
5e2f6673 L |
9948 | int added = 0; |
9949 | ||
542d6675 | 9950 | clear_qp_implies (p1mask | p2mask, p1mask | p2mask); |
5e2f6673 L |
9951 | |
9952 | /* If one of the PRs is PR0, we call clear_qp_mutex. */ | |
9953 | if (p1 == 0 || p2 == 0) | |
9954 | clear_qp_mutex (p1mask | p2mask); | |
9955 | else | |
9956 | added = update_qp_mutex (p1mask | p2mask); | |
9957 | ||
9958 | if (CURR_SLOT.qp_regno == 0 | |
9959 | || has_suffix_p (idesc->name, ".unc")) | |
542d6675 | 9960 | { |
5e2f6673 L |
9961 | if (added == 0 && p1 && p2) |
9962 | add_qp_mutex (p1mask | p2mask); | |
542d6675 KH |
9963 | if (CURR_SLOT.qp_regno != 0) |
9964 | { | |
5e2f6673 L |
9965 | if (p1) |
9966 | add_qp_imply (p1, CURR_SLOT.qp_regno); | |
9967 | if (p2) | |
9968 | add_qp_imply (p2, CURR_SLOT.qp_regno); | |
542d6675 KH |
9969 | } |
9970 | } | |
542d6675 KH |
9971 | } |
9972 | } | |
9973 | /* Look for mov imm insns into GRs. */ | |
800eeca4 | 9974 | else if (idesc->operands[0] == IA64_OPND_R1 |
542d6675 KH |
9975 | && (idesc->operands[1] == IA64_OPND_IMM22 |
9976 | || idesc->operands[1] == IA64_OPND_IMMU64) | |
a66d2bb7 | 9977 | && CURR_SLOT.opnd[1].X_op == O_constant |
542d6675 KH |
9978 | && (strcmp (idesc->name, "mov") == 0 |
9979 | || strcmp (idesc->name, "movl") == 0)) | |
800eeca4 JW |
9980 | { |
9981 | int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR; | |
542d6675 KH |
9982 | if (regno > 0 && regno < NELEMS (gr_values)) |
9983 | { | |
9984 | gr_values[regno].known = 1; | |
9985 | gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number; | |
9986 | gr_values[regno].path = md.path; | |
9987 | if (md.debug_dv) | |
2434f565 JW |
9988 | { |
9989 | fprintf (stderr, " Know gr%d = ", regno); | |
9990 | fprintf_vma (stderr, gr_values[regno].value); | |
9991 | fputs ("\n", stderr); | |
9992 | } | |
542d6675 | 9993 | } |
800eeca4 | 9994 | } |
a66d2bb7 JB |
9995 | /* Look for dep.z imm insns. */ |
9996 | else if (idesc->operands[0] == IA64_OPND_R1 | |
9997 | && idesc->operands[1] == IA64_OPND_IMM8 | |
9998 | && strcmp (idesc->name, "dep.z") == 0) | |
9999 | { | |
10000 | int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR; | |
10001 | if (regno > 0 && regno < NELEMS (gr_values)) | |
10002 | { | |
10003 | valueT value = CURR_SLOT.opnd[1].X_add_number; | |
10004 | ||
10005 | if (CURR_SLOT.opnd[3].X_add_number < 64) | |
10006 | value &= ((valueT)1 << CURR_SLOT.opnd[3].X_add_number) - 1; | |
10007 | value <<= CURR_SLOT.opnd[2].X_add_number; | |
10008 | gr_values[regno].known = 1; | |
10009 | gr_values[regno].value = value; | |
10010 | gr_values[regno].path = md.path; | |
10011 | if (md.debug_dv) | |
10012 | { | |
10013 | fprintf (stderr, " Know gr%d = ", regno); | |
10014 | fprintf_vma (stderr, gr_values[regno].value); | |
10015 | fputs ("\n", stderr); | |
10016 | } | |
10017 | } | |
10018 | } | |
197865e8 | 10019 | else |
800eeca4 JW |
10020 | { |
10021 | clear_qp_mutex (qp_changemask); | |
10022 | clear_qp_implies (qp_changemask, qp_changemask); | |
10023 | } | |
10024 | } | |
10025 | ||
542d6675 KH |
10026 | /* Return whether the given predicate registers are currently mutex. */ |
10027 | ||
800eeca4 | 10028 | static int |
5a49b8ac | 10029 | qp_mutex (int p1, int p2, int path) |
800eeca4 JW |
10030 | { |
10031 | int i; | |
10032 | valueT mask; | |
10033 | ||
10034 | if (p1 != p2) | |
10035 | { | |
542d6675 KH |
10036 | mask = ((valueT) 1 << p1) | (valueT) 1 << p2; |
10037 | for (i = 0; i < qp_mutexeslen; i++) | |
10038 | { | |
10039 | if (qp_mutexes[i].path >= path | |
10040 | && (qp_mutexes[i].prmask & mask) == mask) | |
10041 | return 1; | |
10042 | } | |
800eeca4 JW |
10043 | } |
10044 | return 0; | |
10045 | } | |
10046 | ||
10047 | /* Return whether the given resource is in the given insn's list of chks | |
10048 | Return 1 if the conflict is absolutely determined, 2 if it's a potential | |
542d6675 KH |
10049 | conflict. */ |
10050 | ||
800eeca4 | 10051 | static int |
5a49b8ac AM |
10052 | resources_match (struct rsrc *rs, |
10053 | struct ia64_opcode *idesc, | |
10054 | int note, | |
10055 | int qp_regno, | |
10056 | int path) | |
800eeca4 JW |
10057 | { |
10058 | struct rsrc specs[MAX_SPECS]; | |
10059 | int count; | |
10060 | ||
10061 | /* If the marked resource's qp_regno and the given qp_regno are mutex, | |
10062 | we don't need to check. One exception is note 11, which indicates that | |
10063 | target predicates are written regardless of PR[qp]. */ | |
197865e8 | 10064 | if (qp_mutex (rs->qp_regno, qp_regno, path) |
800eeca4 JW |
10065 | && note != 11) |
10066 | return 0; | |
10067 | ||
10068 | count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path); | |
10069 | while (count-- > 0) | |
10070 | { | |
10071 | /* UNAT checking is a bit more specific than other resources */ | |
10072 | if (rs->dependency->specifier == IA64_RS_AR_UNAT | |
542d6675 KH |
10073 | && specs[count].mem_offset.hint |
10074 | && rs->mem_offset.hint) | |
10075 | { | |
10076 | if (rs->mem_offset.base == specs[count].mem_offset.base) | |
10077 | { | |
10078 | if (((rs->mem_offset.offset >> 3) & 0x3F) == | |
10079 | ((specs[count].mem_offset.offset >> 3) & 0x3F)) | |
10080 | return 1; | |
10081 | else | |
10082 | continue; | |
10083 | } | |
10084 | } | |
800eeca4 | 10085 | |
7484b8e6 | 10086 | /* Skip apparent PR write conflicts where both writes are an AND or both |
4a4f25cf | 10087 | writes are an OR. */ |
7484b8e6 | 10088 | if (rs->dependency->specifier == IA64_RS_PR |
afa680f8 | 10089 | || rs->dependency->specifier == IA64_RS_PRr |
7484b8e6 TW |
10090 | || rs->dependency->specifier == IA64_RS_PR63) |
10091 | { | |
10092 | if (specs[count].cmp_type != CMP_NONE | |
10093 | && specs[count].cmp_type == rs->cmp_type) | |
10094 | { | |
10095 | if (md.debug_dv) | |
10096 | fprintf (stderr, " %s on parallel compare allowed (PR%d)\n", | |
10097 | dv_mode[rs->dependency->mode], | |
afa680f8 | 10098 | rs->dependency->specifier != IA64_RS_PR63 ? |
7484b8e6 TW |
10099 | specs[count].index : 63); |
10100 | continue; | |
10101 | } | |
10102 | if (md.debug_dv) | |
4a4f25cf | 10103 | fprintf (stderr, |
7484b8e6 TW |
10104 | " %s on parallel compare conflict %s vs %s on PR%d\n", |
10105 | dv_mode[rs->dependency->mode], | |
4a4f25cf | 10106 | dv_cmp_type[rs->cmp_type], |
7484b8e6 | 10107 | dv_cmp_type[specs[count].cmp_type], |
afa680f8 | 10108 | rs->dependency->specifier != IA64_RS_PR63 ? |
7484b8e6 | 10109 | specs[count].index : 63); |
4a4f25cf | 10110 | |
7484b8e6 TW |
10111 | } |
10112 | ||
800eeca4 | 10113 | /* If either resource is not specific, conservatively assume a conflict |
197865e8 | 10114 | */ |
800eeca4 | 10115 | if (!specs[count].specific || !rs->specific) |
542d6675 | 10116 | return 2; |
800eeca4 | 10117 | else if (specs[count].index == rs->index) |
542d6675 | 10118 | return 1; |
800eeca4 | 10119 | } |
800eeca4 JW |
10120 | |
10121 | return 0; | |
10122 | } | |
10123 | ||
10124 | /* Indicate an instruction group break; if INSERT_STOP is non-zero, then | |
10125 | insert a stop to create the break. Update all resource dependencies | |
10126 | appropriately. If QP_REGNO is non-zero, only apply the break to resources | |
10127 | which use the same QP_REGNO and have the link_to_qp_branch flag set. | |
10128 | If SAVE_CURRENT is non-zero, don't affect resources marked by the current | |
542d6675 | 10129 | instruction. */ |
800eeca4 JW |
10130 | |
10131 | static void | |
5a49b8ac | 10132 | insn_group_break (int insert_stop, int qp_regno, int save_current) |
800eeca4 JW |
10133 | { |
10134 | int i; | |
10135 | ||
10136 | if (insert_stop && md.num_slots_in_use > 0) | |
10137 | PREV_SLOT.end_of_insn_group = 1; | |
10138 | ||
10139 | if (md.debug_dv) | |
10140 | { | |
197865e8 | 10141 | fprintf (stderr, " Insn group break%s", |
542d6675 | 10142 | (insert_stop ? " (w/stop)" : "")); |
800eeca4 | 10143 | if (qp_regno != 0) |
542d6675 | 10144 | fprintf (stderr, " effective for QP=%d", qp_regno); |
800eeca4 JW |
10145 | fprintf (stderr, "\n"); |
10146 | } | |
10147 | ||
10148 | i = 0; | |
10149 | while (i < regdepslen) | |
10150 | { | |
10151 | const struct ia64_dependency *dep = regdeps[i].dependency; | |
10152 | ||
10153 | if (qp_regno != 0 | |
542d6675 KH |
10154 | && regdeps[i].qp_regno != qp_regno) |
10155 | { | |
10156 | ++i; | |
10157 | continue; | |
10158 | } | |
800eeca4 JW |
10159 | |
10160 | if (save_current | |
542d6675 KH |
10161 | && CURR_SLOT.src_file == regdeps[i].file |
10162 | && CURR_SLOT.src_line == regdeps[i].line) | |
10163 | { | |
10164 | ++i; | |
10165 | continue; | |
10166 | } | |
800eeca4 JW |
10167 | |
10168 | /* clear dependencies which are automatically cleared by a stop, or | |
542d6675 | 10169 | those that have reached the appropriate state of insn serialization */ |
800eeca4 | 10170 | if (dep->semantics == IA64_DVS_IMPLIED |
542d6675 KH |
10171 | || dep->semantics == IA64_DVS_IMPLIEDF |
10172 | || regdeps[i].insn_srlz == STATE_SRLZ) | |
10173 | { | |
10174 | print_dependency ("Removing", i); | |
10175 | regdeps[i] = regdeps[--regdepslen]; | |
10176 | } | |
800eeca4 | 10177 | else |
542d6675 KH |
10178 | { |
10179 | if (dep->semantics == IA64_DVS_DATA | |
10180 | || dep->semantics == IA64_DVS_INSTR | |
800eeca4 | 10181 | || dep->semantics == IA64_DVS_SPECIFIC) |
542d6675 KH |
10182 | { |
10183 | if (regdeps[i].insn_srlz == STATE_NONE) | |
10184 | regdeps[i].insn_srlz = STATE_STOP; | |
10185 | if (regdeps[i].data_srlz == STATE_NONE) | |
10186 | regdeps[i].data_srlz = STATE_STOP; | |
10187 | } | |
10188 | ++i; | |
10189 | } | |
800eeca4 JW |
10190 | } |
10191 | } | |
10192 | ||
542d6675 KH |
10193 | /* Add the given resource usage spec to the list of active dependencies. */ |
10194 | ||
197865e8 | 10195 | static void |
5a49b8ac AM |
10196 | mark_resource (struct ia64_opcode *idesc ATTRIBUTE_UNUSED, |
10197 | const struct ia64_dependency *dep ATTRIBUTE_UNUSED, | |
10198 | struct rsrc *spec, | |
10199 | int depind, | |
10200 | int path) | |
800eeca4 JW |
10201 | { |
10202 | if (regdepslen == regdepstotlen) | |
10203 | { | |
10204 | regdepstotlen += 20; | |
10205 | regdeps = (struct rsrc *) | |
542d6675 | 10206 | xrealloc ((void *) regdeps, |
bc805888 | 10207 | regdepstotlen * sizeof (struct rsrc)); |
800eeca4 JW |
10208 | } |
10209 | ||
10210 | regdeps[regdepslen] = *spec; | |
10211 | regdeps[regdepslen].depind = depind; | |
10212 | regdeps[regdepslen].path = path; | |
10213 | regdeps[regdepslen].file = CURR_SLOT.src_file; | |
10214 | regdeps[regdepslen].line = CURR_SLOT.src_line; | |
10215 | ||
10216 | print_dependency ("Adding", regdepslen); | |
10217 | ||
10218 | ++regdepslen; | |
10219 | } | |
10220 | ||
10221 | static void | |
5a49b8ac | 10222 | print_dependency (const char *action, int depind) |
800eeca4 JW |
10223 | { |
10224 | if (md.debug_dv) | |
10225 | { | |
197865e8 | 10226 | fprintf (stderr, " %s %s '%s'", |
542d6675 KH |
10227 | action, dv_mode[(regdeps[depind].dependency)->mode], |
10228 | (regdeps[depind].dependency)->name); | |
a66d2bb7 | 10229 | if (regdeps[depind].specific && regdeps[depind].index >= 0) |
542d6675 | 10230 | fprintf (stderr, " (%d)", regdeps[depind].index); |
800eeca4 | 10231 | if (regdeps[depind].mem_offset.hint) |
2434f565 JW |
10232 | { |
10233 | fputs (" ", stderr); | |
10234 | fprintf_vma (stderr, regdeps[depind].mem_offset.base); | |
10235 | fputs ("+", stderr); | |
10236 | fprintf_vma (stderr, regdeps[depind].mem_offset.offset); | |
10237 | } | |
800eeca4 JW |
10238 | fprintf (stderr, "\n"); |
10239 | } | |
10240 | } | |
10241 | ||
10242 | static void | |
5a49b8ac | 10243 | instruction_serialization (void) |
800eeca4 JW |
10244 | { |
10245 | int i; | |
10246 | if (md.debug_dv) | |
10247 | fprintf (stderr, " Instruction serialization\n"); | |
542d6675 | 10248 | for (i = 0; i < regdepslen; i++) |
800eeca4 JW |
10249 | if (regdeps[i].insn_srlz == STATE_STOP) |
10250 | regdeps[i].insn_srlz = STATE_SRLZ; | |
10251 | } | |
10252 | ||
10253 | static void | |
5a49b8ac | 10254 | data_serialization (void) |
800eeca4 JW |
10255 | { |
10256 | int i = 0; | |
10257 | if (md.debug_dv) | |
10258 | fprintf (stderr, " Data serialization\n"); | |
10259 | while (i < regdepslen) | |
10260 | { | |
10261 | if (regdeps[i].data_srlz == STATE_STOP | |
542d6675 KH |
10262 | /* Note: as of 991210, all "other" dependencies are cleared by a |
10263 | data serialization. This might change with new tables */ | |
10264 | || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER) | |
10265 | { | |
10266 | print_dependency ("Removing", i); | |
10267 | regdeps[i] = regdeps[--regdepslen]; | |
10268 | } | |
800eeca4 | 10269 | else |
542d6675 | 10270 | ++i; |
800eeca4 JW |
10271 | } |
10272 | } | |
10273 | ||
542d6675 KH |
10274 | /* Insert stops and serializations as needed to avoid DVs. */ |
10275 | ||
800eeca4 | 10276 | static void |
5a49b8ac | 10277 | remove_marked_resource (struct rsrc *rs) |
800eeca4 JW |
10278 | { |
10279 | switch (rs->dependency->semantics) | |
10280 | { | |
10281 | case IA64_DVS_SPECIFIC: | |
10282 | if (md.debug_dv) | |
10283 | fprintf (stderr, "Implementation-specific, assume worst case...\n"); | |
197865e8 | 10284 | /* ...fall through... */ |
800eeca4 JW |
10285 | case IA64_DVS_INSTR: |
10286 | if (md.debug_dv) | |
542d6675 | 10287 | fprintf (stderr, "Inserting instr serialization\n"); |
800eeca4 | 10288 | if (rs->insn_srlz < STATE_STOP) |
542d6675 | 10289 | insn_group_break (1, 0, 0); |
800eeca4 | 10290 | if (rs->insn_srlz < STATE_SRLZ) |
542d6675 | 10291 | { |
888a75be | 10292 | struct slot oldslot = CURR_SLOT; |
542d6675 | 10293 | /* Manually jam a srlz.i insn into the stream */ |
888a75be | 10294 | memset (&CURR_SLOT, 0, sizeof (CURR_SLOT)); |
744b6414 | 10295 | CURR_SLOT.user_template = -1; |
542d6675 KH |
10296 | CURR_SLOT.idesc = ia64_find_opcode ("srlz.i"); |
10297 | instruction_serialization (); | |
10298 | md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS; | |
10299 | if (++md.num_slots_in_use >= NUM_SLOTS) | |
10300 | emit_one_bundle (); | |
888a75be | 10301 | CURR_SLOT = oldslot; |
542d6675 | 10302 | } |
800eeca4 JW |
10303 | insn_group_break (1, 0, 0); |
10304 | break; | |
10305 | case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all | |
542d6675 KH |
10306 | "other" types of DV are eliminated |
10307 | by a data serialization */ | |
800eeca4 JW |
10308 | case IA64_DVS_DATA: |
10309 | if (md.debug_dv) | |
542d6675 | 10310 | fprintf (stderr, "Inserting data serialization\n"); |
800eeca4 | 10311 | if (rs->data_srlz < STATE_STOP) |
542d6675 | 10312 | insn_group_break (1, 0, 0); |
800eeca4 | 10313 | { |
888a75be | 10314 | struct slot oldslot = CURR_SLOT; |
542d6675 | 10315 | /* Manually jam a srlz.d insn into the stream */ |
888a75be | 10316 | memset (&CURR_SLOT, 0, sizeof (CURR_SLOT)); |
744b6414 | 10317 | CURR_SLOT.user_template = -1; |
542d6675 KH |
10318 | CURR_SLOT.idesc = ia64_find_opcode ("srlz.d"); |
10319 | data_serialization (); | |
10320 | md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS; | |
10321 | if (++md.num_slots_in_use >= NUM_SLOTS) | |
10322 | emit_one_bundle (); | |
888a75be | 10323 | CURR_SLOT = oldslot; |
800eeca4 JW |
10324 | } |
10325 | break; | |
10326 | case IA64_DVS_IMPLIED: | |
10327 | case IA64_DVS_IMPLIEDF: | |
10328 | if (md.debug_dv) | |
542d6675 | 10329 | fprintf (stderr, "Inserting stop\n"); |
800eeca4 JW |
10330 | insn_group_break (1, 0, 0); |
10331 | break; | |
10332 | default: | |
10333 | break; | |
10334 | } | |
10335 | } | |
10336 | ||
10337 | /* Check the resources used by the given opcode against the current dependency | |
197865e8 | 10338 | list. |
800eeca4 JW |
10339 | |
10340 | The check is run once for each execution path encountered. In this case, | |
10341 | a unique execution path is the sequence of instructions following a code | |
10342 | entry point, e.g. the following has three execution paths, one starting | |
10343 | at L0, one at L1, and one at L2. | |
197865e8 | 10344 | |
800eeca4 JW |
10345 | L0: nop |
10346 | L1: add | |
10347 | L2: add | |
197865e8 | 10348 | br.ret |
800eeca4 | 10349 | */ |
542d6675 | 10350 | |
800eeca4 | 10351 | static void |
5a49b8ac | 10352 | check_dependencies (struct ia64_opcode *idesc) |
800eeca4 JW |
10353 | { |
10354 | const struct ia64_opcode_dependency *opdeps = idesc->dependencies; | |
10355 | int path; | |
10356 | int i; | |
10357 | ||
10358 | /* Note that the number of marked resources may change within the | |
197865e8 | 10359 | loop if in auto mode. */ |
800eeca4 JW |
10360 | i = 0; |
10361 | while (i < regdepslen) | |
10362 | { | |
10363 | struct rsrc *rs = ®deps[i]; | |
10364 | const struct ia64_dependency *dep = rs->dependency; | |
10365 | int chkind; | |
10366 | int note; | |
10367 | int start_over = 0; | |
10368 | ||
10369 | if (dep->semantics == IA64_DVS_NONE | |
542d6675 KH |
10370 | || (chkind = depends_on (rs->depind, idesc)) == -1) |
10371 | { | |
10372 | ++i; | |
10373 | continue; | |
10374 | } | |
10375 | ||
10376 | note = NOTE (opdeps->chks[chkind]); | |
10377 | ||
10378 | /* Check this resource against each execution path seen thus far. */ | |
10379 | for (path = 0; path <= md.path; path++) | |
10380 | { | |
10381 | int matchtype; | |
10382 | ||
10383 | /* If the dependency wasn't on the path being checked, ignore it. */ | |
10384 | if (rs->path < path) | |
10385 | continue; | |
10386 | ||
10387 | /* If the QP for this insn implies a QP which has branched, don't | |
10388 | bother checking. Ed. NOTE: I don't think this check is terribly | |
10389 | useful; what's the point of generating code which will only be | |
10390 | reached if its QP is zero? | |
10391 | This code was specifically inserted to handle the following code, | |
10392 | based on notes from Intel's DV checking code, where p1 implies p2. | |
10393 | ||
10394 | mov r4 = 2 | |
10395 | (p2) br.cond L | |
10396 | (p1) mov r4 = 7 | |
10397 | */ | |
10398 | if (CURR_SLOT.qp_regno != 0) | |
10399 | { | |
10400 | int skip = 0; | |
10401 | int implies; | |
10402 | for (implies = 0; implies < qp_implieslen; implies++) | |
10403 | { | |
10404 | if (qp_implies[implies].path >= path | |
10405 | && qp_implies[implies].p1 == CURR_SLOT.qp_regno | |
10406 | && qp_implies[implies].p2_branched) | |
10407 | { | |
10408 | skip = 1; | |
10409 | break; | |
10410 | } | |
10411 | } | |
10412 | if (skip) | |
10413 | continue; | |
10414 | } | |
10415 | ||
10416 | if ((matchtype = resources_match (rs, idesc, note, | |
10417 | CURR_SLOT.qp_regno, path)) != 0) | |
10418 | { | |
10419 | char msg[1024]; | |
10420 | char pathmsg[256] = ""; | |
10421 | char indexmsg[256] = ""; | |
10422 | int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0); | |
10423 | ||
10424 | if (path != 0) | |
f9f21a03 L |
10425 | snprintf (pathmsg, sizeof (pathmsg), |
10426 | " when entry is at label '%s'", | |
542d6675 | 10427 | md.entry_labels[path - 1]); |
a66d2bb7 | 10428 | if (matchtype == 1 && rs->index >= 0) |
f9f21a03 L |
10429 | snprintf (indexmsg, sizeof (indexmsg), |
10430 | ", specific resource number is %d", | |
542d6675 | 10431 | rs->index); |
f9f21a03 L |
10432 | snprintf (msg, sizeof (msg), |
10433 | "Use of '%s' %s %s dependency '%s' (%s)%s%s", | |
542d6675 KH |
10434 | idesc->name, |
10435 | (certain ? "violates" : "may violate"), | |
10436 | dv_mode[dep->mode], dep->name, | |
10437 | dv_sem[dep->semantics], | |
10438 | pathmsg, indexmsg); | |
10439 | ||
10440 | if (md.explicit_mode) | |
10441 | { | |
10442 | as_warn ("%s", msg); | |
10443 | if (path < md.path) | |
ad4b42b4 | 10444 | as_warn (_("Only the first path encountering the conflict is reported")); |
542d6675 | 10445 | as_warn_where (rs->file, rs->line, |
ad4b42b4 | 10446 | _("This is the location of the conflicting usage")); |
542d6675 KH |
10447 | /* Don't bother checking other paths, to avoid duplicating |
10448 | the same warning */ | |
10449 | break; | |
10450 | } | |
10451 | else | |
10452 | { | |
10453 | if (md.debug_dv) | |
10454 | fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line); | |
10455 | ||
10456 | remove_marked_resource (rs); | |
10457 | ||
10458 | /* since the set of dependencies has changed, start over */ | |
10459 | /* FIXME -- since we're removing dvs as we go, we | |
10460 | probably don't really need to start over... */ | |
10461 | start_over = 1; | |
10462 | break; | |
10463 | } | |
10464 | } | |
10465 | } | |
800eeca4 | 10466 | if (start_over) |
542d6675 | 10467 | i = 0; |
800eeca4 | 10468 | else |
542d6675 | 10469 | ++i; |
800eeca4 JW |
10470 | } |
10471 | } | |
10472 | ||
542d6675 KH |
10473 | /* Register new dependencies based on the given opcode. */ |
10474 | ||
800eeca4 | 10475 | static void |
5a49b8ac | 10476 | mark_resources (struct ia64_opcode *idesc) |
800eeca4 JW |
10477 | { |
10478 | int i; | |
10479 | const struct ia64_opcode_dependency *opdeps = idesc->dependencies; | |
10480 | int add_only_qp_reads = 0; | |
10481 | ||
10482 | /* A conditional branch only uses its resources if it is taken; if it is | |
10483 | taken, we stop following that path. The other branch types effectively | |
10484 | *always* write their resources. If it's not taken, register only QP | |
197865e8 | 10485 | reads. */ |
800eeca4 JW |
10486 | if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc)) |
10487 | { | |
10488 | add_only_qp_reads = 1; | |
10489 | } | |
10490 | ||
10491 | if (md.debug_dv) | |
10492 | fprintf (stderr, "Registering '%s' resource usage\n", idesc->name); | |
10493 | ||
542d6675 | 10494 | for (i = 0; i < opdeps->nregs; i++) |
800eeca4 JW |
10495 | { |
10496 | const struct ia64_dependency *dep; | |
10497 | struct rsrc specs[MAX_SPECS]; | |
10498 | int note; | |
10499 | int path; | |
10500 | int count; | |
197865e8 | 10501 | |
800eeca4 | 10502 | dep = ia64_find_dependency (opdeps->regs[i]); |
542d6675 | 10503 | note = NOTE (opdeps->regs[i]); |
800eeca4 JW |
10504 | |
10505 | if (add_only_qp_reads | |
542d6675 KH |
10506 | && !(dep->mode == IA64_DV_WAR |
10507 | && (dep->specifier == IA64_RS_PR | |
139368c9 | 10508 | || dep->specifier == IA64_RS_PRr |
542d6675 KH |
10509 | || dep->specifier == IA64_RS_PR63))) |
10510 | continue; | |
800eeca4 JW |
10511 | |
10512 | count = specify_resource (dep, idesc, DV_REG, specs, note, md.path); | |
10513 | ||
800eeca4 | 10514 | while (count-- > 0) |
542d6675 KH |
10515 | { |
10516 | mark_resource (idesc, dep, &specs[count], | |
10517 | DEP (opdeps->regs[i]), md.path); | |
10518 | } | |
800eeca4 JW |
10519 | |
10520 | /* The execution path may affect register values, which may in turn | |
542d6675 | 10521 | affect which indirect-access resources are accessed. */ |
800eeca4 | 10522 | switch (dep->specifier) |
542d6675 KH |
10523 | { |
10524 | default: | |
10525 | break; | |
10526 | case IA64_RS_CPUID: | |
10527 | case IA64_RS_DBR: | |
10528 | case IA64_RS_IBR: | |
800eeca4 | 10529 | case IA64_RS_MSR: |
542d6675 KH |
10530 | case IA64_RS_PKR: |
10531 | case IA64_RS_PMC: | |
10532 | case IA64_RS_PMD: | |
10533 | case IA64_RS_RR: | |
10534 | for (path = 0; path < md.path; path++) | |
10535 | { | |
10536 | count = specify_resource (dep, idesc, DV_REG, specs, note, path); | |
10537 | while (count-- > 0) | |
10538 | mark_resource (idesc, dep, &specs[count], | |
10539 | DEP (opdeps->regs[i]), path); | |
10540 | } | |
10541 | break; | |
10542 | } | |
10543 | } | |
10544 | } | |
10545 | ||
10546 | /* Remove dependencies when they no longer apply. */ | |
10547 | ||
800eeca4 | 10548 | static void |
5a49b8ac | 10549 | update_dependencies (struct ia64_opcode *idesc) |
800eeca4 JW |
10550 | { |
10551 | int i; | |
10552 | ||
10553 | if (strcmp (idesc->name, "srlz.i") == 0) | |
10554 | { | |
10555 | instruction_serialization (); | |
10556 | } | |
10557 | else if (strcmp (idesc->name, "srlz.d") == 0) | |
10558 | { | |
10559 | data_serialization (); | |
10560 | } | |
10561 | else if (is_interruption_or_rfi (idesc) | |
542d6675 | 10562 | || is_taken_branch (idesc)) |
800eeca4 | 10563 | { |
542d6675 KH |
10564 | /* Although technically the taken branch doesn't clear dependencies |
10565 | which require a srlz.[id], we don't follow the branch; the next | |
10566 | instruction is assumed to start with a clean slate. */ | |
800eeca4 | 10567 | regdepslen = 0; |
800eeca4 JW |
10568 | md.path = 0; |
10569 | } | |
10570 | else if (is_conditional_branch (idesc) | |
542d6675 | 10571 | && CURR_SLOT.qp_regno != 0) |
800eeca4 JW |
10572 | { |
10573 | int is_call = strstr (idesc->name, ".call") != NULL; | |
10574 | ||
542d6675 KH |
10575 | for (i = 0; i < qp_implieslen; i++) |
10576 | { | |
10577 | /* If the conditional branch's predicate is implied by the predicate | |
10578 | in an existing dependency, remove that dependency. */ | |
10579 | if (qp_implies[i].p2 == CURR_SLOT.qp_regno) | |
10580 | { | |
10581 | int depind = 0; | |
10582 | /* Note that this implied predicate takes a branch so that if | |
10583 | a later insn generates a DV but its predicate implies this | |
10584 | one, we can avoid the false DV warning. */ | |
10585 | qp_implies[i].p2_branched = 1; | |
10586 | while (depind < regdepslen) | |
10587 | { | |
10588 | if (regdeps[depind].qp_regno == qp_implies[i].p1) | |
10589 | { | |
10590 | print_dependency ("Removing", depind); | |
10591 | regdeps[depind] = regdeps[--regdepslen]; | |
10592 | } | |
10593 | else | |
10594 | ++depind; | |
10595 | } | |
10596 | } | |
10597 | } | |
800eeca4 | 10598 | /* Any marked resources which have this same predicate should be |
542d6675 KH |
10599 | cleared, provided that the QP hasn't been modified between the |
10600 | marking instruction and the branch. */ | |
800eeca4 | 10601 | if (is_call) |
542d6675 KH |
10602 | { |
10603 | insn_group_break (0, CURR_SLOT.qp_regno, 1); | |
10604 | } | |
800eeca4 | 10605 | else |
542d6675 KH |
10606 | { |
10607 | i = 0; | |
10608 | while (i < regdepslen) | |
10609 | { | |
10610 | if (regdeps[i].qp_regno == CURR_SLOT.qp_regno | |
10611 | && regdeps[i].link_to_qp_branch | |
10612 | && (regdeps[i].file != CURR_SLOT.src_file | |
10613 | || regdeps[i].line != CURR_SLOT.src_line)) | |
10614 | { | |
10615 | /* Treat like a taken branch */ | |
10616 | print_dependency ("Removing", i); | |
10617 | regdeps[i] = regdeps[--regdepslen]; | |
10618 | } | |
10619 | else | |
10620 | ++i; | |
10621 | } | |
10622 | } | |
800eeca4 JW |
10623 | } |
10624 | } | |
10625 | ||
10626 | /* Examine the current instruction for dependency violations. */ | |
542d6675 | 10627 | |
800eeca4 | 10628 | static int |
5a49b8ac | 10629 | check_dv (struct ia64_opcode *idesc) |
800eeca4 JW |
10630 | { |
10631 | if (md.debug_dv) | |
10632 | { | |
197865e8 | 10633 | fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n", |
542d6675 KH |
10634 | idesc->name, CURR_SLOT.src_line, |
10635 | idesc->dependencies->nchks, | |
10636 | idesc->dependencies->nregs); | |
800eeca4 JW |
10637 | } |
10638 | ||
197865e8 | 10639 | /* Look through the list of currently marked resources; if the current |
800eeca4 | 10640 | instruction has the dependency in its chks list which uses that resource, |
542d6675 | 10641 | check against the specific resources used. */ |
800eeca4 JW |
10642 | check_dependencies (idesc); |
10643 | ||
542d6675 KH |
10644 | /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads), |
10645 | then add them to the list of marked resources. */ | |
800eeca4 JW |
10646 | mark_resources (idesc); |
10647 | ||
10648 | /* There are several types of dependency semantics, and each has its own | |
197865e8 KH |
10649 | requirements for being cleared |
10650 | ||
800eeca4 JW |
10651 | Instruction serialization (insns separated by interruption, rfi, or |
10652 | writer + srlz.i + reader, all in separate groups) clears DVS_INSTR. | |
10653 | ||
10654 | Data serialization (instruction serialization, or writer + srlz.d + | |
10655 | reader, where writer and srlz.d are in separate groups) clears | |
10656 | DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to | |
10657 | always be the case). | |
10658 | ||
10659 | Instruction group break (groups separated by stop, taken branch, | |
10660 | interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF. | |
10661 | */ | |
10662 | update_dependencies (idesc); | |
10663 | ||
10664 | /* Sometimes, knowing a register value allows us to avoid giving a false DV | |
197865e8 | 10665 | warning. Keep track of as many as possible that are useful. */ |
800eeca4 JW |
10666 | note_register_values (idesc); |
10667 | ||
197865e8 | 10668 | /* We don't need or want this anymore. */ |
800eeca4 JW |
10669 | md.mem_offset.hint = 0; |
10670 | ||
10671 | return 0; | |
10672 | } | |
10673 | ||
10674 | /* Translate one line of assembly. Pseudo ops and labels do not show | |
10675 | here. */ | |
10676 | void | |
5a49b8ac | 10677 | md_assemble (char *str) |
800eeca4 JW |
10678 | { |
10679 | char *saved_input_line_pointer, *mnemonic; | |
10680 | const struct pseudo_opcode *pdesc; | |
10681 | struct ia64_opcode *idesc; | |
10682 | unsigned char qp_regno; | |
10683 | unsigned int flags; | |
10684 | int ch; | |
10685 | ||
10686 | saved_input_line_pointer = input_line_pointer; | |
10687 | input_line_pointer = str; | |
10688 | ||
542d6675 | 10689 | /* extract the opcode (mnemonic): */ |
800eeca4 | 10690 | |
d02603dc | 10691 | ch = get_symbol_name (&mnemonic); |
800eeca4 JW |
10692 | pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic); |
10693 | if (pdesc) | |
10694 | { | |
d02603dc | 10695 | (void) restore_line_pointer (ch); |
800eeca4 JW |
10696 | (*pdesc->handler) (pdesc->arg); |
10697 | goto done; | |
10698 | } | |
10699 | ||
542d6675 | 10700 | /* Find the instruction descriptor matching the arguments. */ |
800eeca4 JW |
10701 | |
10702 | idesc = ia64_find_opcode (mnemonic); | |
d02603dc | 10703 | (void) restore_line_pointer (ch); |
800eeca4 JW |
10704 | if (!idesc) |
10705 | { | |
ad4b42b4 | 10706 | as_bad (_("Unknown opcode `%s'"), mnemonic); |
800eeca4 JW |
10707 | goto done; |
10708 | } | |
10709 | ||
10710 | idesc = parse_operands (idesc); | |
10711 | if (!idesc) | |
10712 | goto done; | |
10713 | ||
542d6675 | 10714 | /* Handle the dynamic ops we can handle now: */ |
800eeca4 JW |
10715 | if (idesc->type == IA64_TYPE_DYN) |
10716 | { | |
10717 | if (strcmp (idesc->name, "add") == 0) | |
10718 | { | |
10719 | if (CURR_SLOT.opnd[2].X_op == O_register | |
10720 | && CURR_SLOT.opnd[2].X_add_number < 4) | |
10721 | mnemonic = "addl"; | |
10722 | else | |
10723 | mnemonic = "adds"; | |
3d56ab85 | 10724 | ia64_free_opcode (idesc); |
800eeca4 | 10725 | idesc = ia64_find_opcode (mnemonic); |
800eeca4 JW |
10726 | } |
10727 | else if (strcmp (idesc->name, "mov") == 0) | |
10728 | { | |
10729 | enum ia64_opnd opnd1, opnd2; | |
10730 | int rop; | |
10731 | ||
10732 | opnd1 = idesc->operands[0]; | |
10733 | opnd2 = idesc->operands[1]; | |
10734 | if (opnd1 == IA64_OPND_AR3) | |
10735 | rop = 0; | |
10736 | else if (opnd2 == IA64_OPND_AR3) | |
10737 | rop = 1; | |
10738 | else | |
10739 | abort (); | |
652ca075 L |
10740 | if (CURR_SLOT.opnd[rop].X_op == O_register) |
10741 | { | |
10742 | if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number)) | |
10743 | mnemonic = "mov.i"; | |
97762d08 | 10744 | else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number)) |
652ca075 | 10745 | mnemonic = "mov.m"; |
97762d08 JB |
10746 | else |
10747 | rop = -1; | |
652ca075 | 10748 | } |
800eeca4 | 10749 | else |
652ca075 | 10750 | abort (); |
97762d08 JB |
10751 | if (rop >= 0) |
10752 | { | |
10753 | ia64_free_opcode (idesc); | |
10754 | idesc = ia64_find_opcode (mnemonic); | |
10755 | while (idesc != NULL | |
10756 | && (idesc->operands[0] != opnd1 | |
10757 | || idesc->operands[1] != opnd2)) | |
10758 | idesc = get_next_opcode (idesc); | |
10759 | } | |
800eeca4 JW |
10760 | } |
10761 | } | |
652ca075 L |
10762 | else if (strcmp (idesc->name, "mov.i") == 0 |
10763 | || strcmp (idesc->name, "mov.m") == 0) | |
10764 | { | |
10765 | enum ia64_opnd opnd1, opnd2; | |
10766 | int rop; | |
3739860c | 10767 | |
652ca075 L |
10768 | opnd1 = idesc->operands[0]; |
10769 | opnd2 = idesc->operands[1]; | |
10770 | if (opnd1 == IA64_OPND_AR3) | |
10771 | rop = 0; | |
10772 | else if (opnd2 == IA64_OPND_AR3) | |
10773 | rop = 1; | |
10774 | else | |
10775 | abort (); | |
10776 | if (CURR_SLOT.opnd[rop].X_op == O_register) | |
10777 | { | |
10778 | char unit = 'a'; | |
10779 | if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number)) | |
10780 | unit = 'i'; | |
10781 | else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number)) | |
10782 | unit = 'm'; | |
10783 | if (unit != 'a' && unit != idesc->name [4]) | |
ad4b42b4 | 10784 | as_bad (_("AR %d can only be accessed by %c-unit"), |
652ca075 L |
10785 | (int) (CURR_SLOT.opnd[rop].X_add_number - REG_AR), |
10786 | TOUPPER (unit)); | |
10787 | } | |
10788 | } | |
91d777ee L |
10789 | else if (strcmp (idesc->name, "hint.b") == 0) |
10790 | { | |
10791 | switch (md.hint_b) | |
10792 | { | |
10793 | case hint_b_ok: | |
10794 | break; | |
10795 | case hint_b_warning: | |
ad4b42b4 | 10796 | as_warn (_("hint.b may be treated as nop")); |
91d777ee L |
10797 | break; |
10798 | case hint_b_error: | |
ad4b42b4 | 10799 | as_bad (_("hint.b shouldn't be used")); |
91d777ee L |
10800 | break; |
10801 | } | |
10802 | } | |
800eeca4 JW |
10803 | |
10804 | qp_regno = 0; | |
10805 | if (md.qp.X_op == O_register) | |
f1bcba5b JW |
10806 | { |
10807 | qp_regno = md.qp.X_add_number - REG_P; | |
10808 | md.qp.X_op = O_absent; | |
10809 | } | |
800eeca4 JW |
10810 | |
10811 | flags = idesc->flags; | |
10812 | ||
10813 | if ((flags & IA64_OPCODE_FIRST) != 0) | |
9545c4ce L |
10814 | { |
10815 | /* The alignment frag has to end with a stop bit only if the | |
10816 | next instruction after the alignment directive has to be | |
10817 | the first instruction in an instruction group. */ | |
10818 | if (align_frag) | |
10819 | { | |
10820 | while (align_frag->fr_type != rs_align_code) | |
10821 | { | |
10822 | align_frag = align_frag->fr_next; | |
bae25f19 L |
10823 | if (!align_frag) |
10824 | break; | |
9545c4ce | 10825 | } |
bae25f19 L |
10826 | /* align_frag can be NULL if there are directives in |
10827 | between. */ | |
10828 | if (align_frag && align_frag->fr_next == frag_now) | |
9545c4ce L |
10829 | align_frag->tc_frag_data = 1; |
10830 | } | |
10831 | ||
10832 | insn_group_break (1, 0, 0); | |
10833 | } | |
10834 | align_frag = NULL; | |
800eeca4 JW |
10835 | |
10836 | if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0) | |
10837 | { | |
ad4b42b4 | 10838 | as_bad (_("`%s' cannot be predicated"), idesc->name); |
800eeca4 JW |
10839 | goto done; |
10840 | } | |
10841 | ||
542d6675 | 10842 | /* Build the instruction. */ |
800eeca4 JW |
10843 | CURR_SLOT.qp_regno = qp_regno; |
10844 | CURR_SLOT.idesc = idesc; | |
3b4dbbbf | 10845 | CURR_SLOT.src_file = as_where (&CURR_SLOT.src_line); |
4dc7ead9 | 10846 | dwarf2_where (&CURR_SLOT.debug_line); |
661ba50f | 10847 | dwarf2_consume_line_info (); |
800eeca4 | 10848 | |
ba825241 | 10849 | /* Add unwind entries, if there are any. */ |
e0c9811a | 10850 | if (unwind.current_entry) |
800eeca4 | 10851 | { |
e0c9811a JW |
10852 | CURR_SLOT.unwind_record = unwind.current_entry; |
10853 | unwind.current_entry = NULL; | |
800eeca4 | 10854 | } |
ba825241 JB |
10855 | if (unwind.pending_saves) |
10856 | { | |
10857 | if (unwind.pending_saves->next) | |
10858 | { | |
10859 | /* Attach the next pending save to the next slot so that its | |
10860 | slot number will get set correctly. */ | |
10861 | add_unwind_entry (unwind.pending_saves->next, NOT_A_CHAR); | |
10862 | unwind.pending_saves = &unwind.pending_saves->next->r.record.p; | |
10863 | } | |
10864 | else | |
10865 | unwind.pending_saves = NULL; | |
10866 | } | |
5656b6b8 | 10867 | if (unwind.proc_pending.sym && S_IS_DEFINED (unwind.proc_pending.sym)) |
75e09913 | 10868 | unwind.insn = 1; |
800eeca4 | 10869 | |
542d6675 | 10870 | /* Check for dependency violations. */ |
800eeca4 | 10871 | if (md.detect_dv) |
542d6675 | 10872 | check_dv (idesc); |
800eeca4 JW |
10873 | |
10874 | md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS; | |
10875 | if (++md.num_slots_in_use >= NUM_SLOTS) | |
10876 | emit_one_bundle (); | |
10877 | ||
10878 | if ((flags & IA64_OPCODE_LAST) != 0) | |
10879 | insn_group_break (1, 0, 0); | |
10880 | ||
10881 | md.last_text_seg = now_seg; | |
10882 | ||
10883 | done: | |
10884 | input_line_pointer = saved_input_line_pointer; | |
10885 | } | |
10886 | ||
10887 | /* Called when symbol NAME cannot be found in the symbol table. | |
10888 | Should be used for dynamic valued symbols only. */ | |
542d6675 KH |
10889 | |
10890 | symbolS * | |
5a49b8ac | 10891 | md_undefined_symbol (char *name ATTRIBUTE_UNUSED) |
800eeca4 JW |
10892 | { |
10893 | return 0; | |
10894 | } | |
10895 | ||
10896 | /* Called for any expression that can not be recognized. When the | |
10897 | function is called, `input_line_pointer' will point to the start of | |
10898 | the expression. */ | |
542d6675 | 10899 | |
800eeca4 | 10900 | void |
5a49b8ac | 10901 | md_operand (expressionS *e) |
800eeca4 | 10902 | { |
800eeca4 JW |
10903 | switch (*input_line_pointer) |
10904 | { | |
800eeca4 JW |
10905 | case '[': |
10906 | ++input_line_pointer; | |
60d11e55 | 10907 | expression_and_evaluate (e); |
800eeca4 JW |
10908 | if (*input_line_pointer != ']') |
10909 | { | |
ad4b42b4 | 10910 | as_bad (_("Closing bracket missing")); |
800eeca4 JW |
10911 | goto err; |
10912 | } | |
10913 | else | |
10914 | { | |
6a2375c6 JB |
10915 | if (e->X_op != O_register |
10916 | || e->X_add_number < REG_GR | |
10917 | || e->X_add_number > REG_GR + 127) | |
10918 | { | |
ad4b42b4 | 10919 | as_bad (_("Index must be a general register")); |
6a2375c6 JB |
10920 | e->X_add_number = REG_GR; |
10921 | } | |
800eeca4 JW |
10922 | |
10923 | ++input_line_pointer; | |
10924 | e->X_op = O_index; | |
10925 | } | |
10926 | break; | |
10927 | ||
10928 | default: | |
10929 | break; | |
10930 | } | |
10931 | return; | |
10932 | ||
10933 | err: | |
10934 | ignore_rest_of_line (); | |
10935 | } | |
10936 | ||
10937 | /* Return 1 if it's OK to adjust a reloc by replacing the symbol with | |
10938 | a section symbol plus some offset. For relocs involving @fptr(), | |
10939 | directives we don't want such adjustments since we need to have the | |
10940 | original symbol's name in the reloc. */ | |
10941 | int | |
5a49b8ac | 10942 | ia64_fix_adjustable (fixS *fix) |
800eeca4 JW |
10943 | { |
10944 | /* Prevent all adjustments to global symbols */ | |
e97b3f28 | 10945 | if (S_IS_EXTERNAL (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy)) |
800eeca4 JW |
10946 | return 0; |
10947 | ||
10948 | switch (fix->fx_r_type) | |
10949 | { | |
10950 | case BFD_RELOC_IA64_FPTR64I: | |
10951 | case BFD_RELOC_IA64_FPTR32MSB: | |
10952 | case BFD_RELOC_IA64_FPTR32LSB: | |
10953 | case BFD_RELOC_IA64_FPTR64MSB: | |
10954 | case BFD_RELOC_IA64_FPTR64LSB: | |
10955 | case BFD_RELOC_IA64_LTOFF_FPTR22: | |
10956 | case BFD_RELOC_IA64_LTOFF_FPTR64I: | |
10957 | return 0; | |
10958 | default: | |
10959 | break; | |
10960 | } | |
10961 | ||
10962 | return 1; | |
10963 | } | |
10964 | ||
10965 | int | |
5a49b8ac | 10966 | ia64_force_relocation (fixS *fix) |
800eeca4 JW |
10967 | { |
10968 | switch (fix->fx_r_type) | |
10969 | { | |
10970 | case BFD_RELOC_IA64_FPTR64I: | |
10971 | case BFD_RELOC_IA64_FPTR32MSB: | |
10972 | case BFD_RELOC_IA64_FPTR32LSB: | |
10973 | case BFD_RELOC_IA64_FPTR64MSB: | |
10974 | case BFD_RELOC_IA64_FPTR64LSB: | |
10975 | ||
10976 | case BFD_RELOC_IA64_LTOFF22: | |
10977 | case BFD_RELOC_IA64_LTOFF64I: | |
10978 | case BFD_RELOC_IA64_LTOFF_FPTR22: | |
10979 | case BFD_RELOC_IA64_LTOFF_FPTR64I: | |
10980 | case BFD_RELOC_IA64_PLTOFF22: | |
10981 | case BFD_RELOC_IA64_PLTOFF64I: | |
10982 | case BFD_RELOC_IA64_PLTOFF64MSB: | |
10983 | case BFD_RELOC_IA64_PLTOFF64LSB: | |
fa2c7eff RH |
10984 | |
10985 | case BFD_RELOC_IA64_LTOFF22X: | |
10986 | case BFD_RELOC_IA64_LDXMOV: | |
800eeca4 JW |
10987 | return 1; |
10988 | ||
10989 | default: | |
a161fe53 | 10990 | break; |
800eeca4 | 10991 | } |
a161fe53 | 10992 | |
ae6063d4 | 10993 | return generic_force_reloc (fix); |
800eeca4 JW |
10994 | } |
10995 | ||
10996 | /* Decide from what point a pc-relative relocation is relative to, | |
10997 | relative to the pc-relative fixup. Er, relatively speaking. */ | |
10998 | long | |
5a49b8ac | 10999 | ia64_pcrel_from_section (fixS *fix, segT sec) |
800eeca4 JW |
11000 | { |
11001 | unsigned long off = fix->fx_frag->fr_address + fix->fx_where; | |
197865e8 | 11002 | |
800eeca4 JW |
11003 | if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE) |
11004 | off &= ~0xfUL; | |
11005 | ||
11006 | return off; | |
11007 | } | |
11008 | ||
6174d9c8 RH |
11009 | |
11010 | /* Used to emit section-relative relocs for the dwarf2 debug data. */ | |
11011 | void | |
11012 | ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size) | |
11013 | { | |
91d6fa6a | 11014 | expressionS exp; |
6174d9c8 | 11015 | |
91d6fa6a NC |
11016 | exp.X_op = O_pseudo_fixup; |
11017 | exp.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym; | |
11018 | exp.X_add_number = 0; | |
11019 | exp.X_add_symbol = symbol; | |
11020 | emit_expr (&exp, size); | |
6174d9c8 RH |
11021 | } |
11022 | ||
800eeca4 JW |
11023 | /* This is called whenever some data item (not an instruction) needs a |
11024 | fixup. We pick the right reloc code depending on the byteorder | |
11025 | currently in effect. */ | |
11026 | void | |
62ebcb5c AM |
11027 | ia64_cons_fix_new (fragS *f, int where, int nbytes, expressionS *exp, |
11028 | bfd_reloc_code_real_type code) | |
800eeca4 | 11029 | { |
800eeca4 JW |
11030 | fixS *fix; |
11031 | ||
11032 | switch (nbytes) | |
11033 | { | |
11034 | /* There are no reloc for 8 and 16 bit quantities, but we allow | |
11035 | them here since they will work fine as long as the expression | |
11036 | is fully defined at the end of the pass over the source file. */ | |
11037 | case 1: code = BFD_RELOC_8; break; | |
11038 | case 2: code = BFD_RELOC_16; break; | |
11039 | case 4: | |
11040 | if (target_big_endian) | |
11041 | code = BFD_RELOC_IA64_DIR32MSB; | |
11042 | else | |
11043 | code = BFD_RELOC_IA64_DIR32LSB; | |
11044 | break; | |
11045 | ||
11046 | case 8: | |
40449e9f | 11047 | /* In 32-bit mode, data8 could mean function descriptors too. */ |
5f44c186 | 11048 | if (exp->X_op == O_pseudo_fixup |
40449e9f KH |
11049 | && exp->X_op_symbol |
11050 | && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC | |
11051 | && !(md.flags & EF_IA_64_ABI64)) | |
11052 | { | |
11053 | if (target_big_endian) | |
11054 | code = BFD_RELOC_IA64_IPLTMSB; | |
11055 | else | |
11056 | code = BFD_RELOC_IA64_IPLTLSB; | |
11057 | exp->X_op = O_symbol; | |
11058 | break; | |
11059 | } | |
11060 | else | |
11061 | { | |
11062 | if (target_big_endian) | |
11063 | code = BFD_RELOC_IA64_DIR64MSB; | |
11064 | else | |
11065 | code = BFD_RELOC_IA64_DIR64LSB; | |
11066 | break; | |
11067 | } | |
800eeca4 | 11068 | |
3969b680 RH |
11069 | case 16: |
11070 | if (exp->X_op == O_pseudo_fixup | |
11071 | && exp->X_op_symbol | |
11072 | && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC) | |
11073 | { | |
11074 | if (target_big_endian) | |
11075 | code = BFD_RELOC_IA64_IPLTMSB; | |
11076 | else | |
11077 | code = BFD_RELOC_IA64_IPLTLSB; | |
3969b680 RH |
11078 | exp->X_op = O_symbol; |
11079 | break; | |
11080 | } | |
11081 | /* FALLTHRU */ | |
11082 | ||
800eeca4 | 11083 | default: |
ad4b42b4 | 11084 | as_bad (_("Unsupported fixup size %d"), nbytes); |
800eeca4 JW |
11085 | ignore_rest_of_line (); |
11086 | return; | |
11087 | } | |
6174d9c8 | 11088 | |
800eeca4 JW |
11089 | if (exp->X_op == O_pseudo_fixup) |
11090 | { | |
800eeca4 JW |
11091 | exp->X_op = O_symbol; |
11092 | code = ia64_gen_real_reloc_type (exp->X_op_symbol, code); | |
6174d9c8 | 11093 | /* ??? If code unchanged, unsupported. */ |
800eeca4 | 11094 | } |
3969b680 | 11095 | |
800eeca4 JW |
11096 | fix = fix_new_exp (f, where, nbytes, exp, 0, code); |
11097 | /* We need to store the byte order in effect in case we're going | |
11098 | to fix an 8 or 16 bit relocation (for which there no real | |
55cf6793 | 11099 | relocs available). See md_apply_fix(). */ |
800eeca4 JW |
11100 | fix->tc_fix_data.bigendian = target_big_endian; |
11101 | } | |
11102 | ||
11103 | /* Return the actual relocation we wish to associate with the pseudo | |
11104 | reloc described by SYM and R_TYPE. SYM should be one of the | |
197865e8 | 11105 | symbols in the pseudo_func array, or NULL. */ |
800eeca4 JW |
11106 | |
11107 | static bfd_reloc_code_real_type | |
5a49b8ac | 11108 | ia64_gen_real_reloc_type (struct symbol *sym, bfd_reloc_code_real_type r_type) |
800eeca4 | 11109 | { |
d3ce72d0 | 11110 | bfd_reloc_code_real_type newr = 0; |
0ca3e455 | 11111 | const char *type = NULL, *suffix = ""; |
800eeca4 JW |
11112 | |
11113 | if (sym == NULL) | |
11114 | { | |
11115 | return r_type; | |
11116 | } | |
11117 | ||
11118 | switch (S_GET_VALUE (sym)) | |
11119 | { | |
11120 | case FUNC_FPTR_RELATIVE: | |
11121 | switch (r_type) | |
11122 | { | |
d3ce72d0 NC |
11123 | case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_FPTR64I; break; |
11124 | case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_FPTR32MSB; break; | |
11125 | case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_FPTR32LSB; break; | |
11126 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_FPTR64MSB; break; | |
11127 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_FPTR64LSB; break; | |
0ca3e455 | 11128 | default: type = "FPTR"; break; |
800eeca4 JW |
11129 | } |
11130 | break; | |
11131 | ||
11132 | case FUNC_GP_RELATIVE: | |
11133 | switch (r_type) | |
11134 | { | |
d3ce72d0 NC |
11135 | case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_GPREL22; break; |
11136 | case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_GPREL64I; break; | |
11137 | case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_GPREL32MSB; break; | |
11138 | case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_GPREL32LSB; break; | |
11139 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_GPREL64MSB; break; | |
11140 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_GPREL64LSB; break; | |
0ca3e455 | 11141 | default: type = "GPREL"; break; |
800eeca4 JW |
11142 | } |
11143 | break; | |
11144 | ||
11145 | case FUNC_LT_RELATIVE: | |
11146 | switch (r_type) | |
11147 | { | |
d3ce72d0 NC |
11148 | case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_LTOFF22; break; |
11149 | case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_LTOFF64I; break; | |
0ca3e455 | 11150 | default: type = "LTOFF"; break; |
800eeca4 JW |
11151 | } |
11152 | break; | |
11153 | ||
fa2c7eff RH |
11154 | case FUNC_LT_RELATIVE_X: |
11155 | switch (r_type) | |
11156 | { | |
d3ce72d0 | 11157 | case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_LTOFF22X; break; |
0ca3e455 | 11158 | default: type = "LTOFF"; suffix = "X"; break; |
fa2c7eff RH |
11159 | } |
11160 | break; | |
11161 | ||
c67e42c9 RH |
11162 | case FUNC_PC_RELATIVE: |
11163 | switch (r_type) | |
11164 | { | |
d3ce72d0 NC |
11165 | case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_PCREL22; break; |
11166 | case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_PCREL64I; break; | |
11167 | case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_PCREL32MSB; break; | |
11168 | case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_PCREL32LSB; break; | |
11169 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_PCREL64MSB; break; | |
11170 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_PCREL64LSB; break; | |
0ca3e455 | 11171 | default: type = "PCREL"; break; |
c67e42c9 RH |
11172 | } |
11173 | break; | |
11174 | ||
800eeca4 JW |
11175 | case FUNC_PLT_RELATIVE: |
11176 | switch (r_type) | |
11177 | { | |
d3ce72d0 NC |
11178 | case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_PLTOFF22; break; |
11179 | case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_PLTOFF64I; break; | |
11180 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_PLTOFF64MSB;break; | |
11181 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_PLTOFF64LSB;break; | |
0ca3e455 | 11182 | default: type = "PLTOFF"; break; |
800eeca4 JW |
11183 | } |
11184 | break; | |
11185 | ||
11186 | case FUNC_SEC_RELATIVE: | |
11187 | switch (r_type) | |
11188 | { | |
d3ce72d0 NC |
11189 | case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_SECREL32MSB;break; |
11190 | case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_SECREL32LSB;break; | |
11191 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_SECREL64MSB;break; | |
11192 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_SECREL64LSB;break; | |
0ca3e455 | 11193 | default: type = "SECREL"; break; |
800eeca4 JW |
11194 | } |
11195 | break; | |
11196 | ||
11197 | case FUNC_SEG_RELATIVE: | |
11198 | switch (r_type) | |
11199 | { | |
d3ce72d0 NC |
11200 | case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_SEGREL32MSB;break; |
11201 | case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_SEGREL32LSB;break; | |
11202 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_SEGREL64MSB;break; | |
11203 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_SEGREL64LSB;break; | |
0ca3e455 | 11204 | default: type = "SEGREL"; break; |
800eeca4 JW |
11205 | } |
11206 | break; | |
11207 | ||
11208 | case FUNC_LTV_RELATIVE: | |
11209 | switch (r_type) | |
11210 | { | |
d3ce72d0 NC |
11211 | case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_LTV32MSB; break; |
11212 | case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_LTV32LSB; break; | |
11213 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_LTV64MSB; break; | |
11214 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_LTV64LSB; break; | |
0ca3e455 | 11215 | default: type = "LTV"; break; |
800eeca4 JW |
11216 | } |
11217 | break; | |
11218 | ||
11219 | case FUNC_LT_FPTR_RELATIVE: | |
11220 | switch (r_type) | |
11221 | { | |
11222 | case BFD_RELOC_IA64_IMM22: | |
d3ce72d0 | 11223 | newr = BFD_RELOC_IA64_LTOFF_FPTR22; break; |
800eeca4 | 11224 | case BFD_RELOC_IA64_IMM64: |
d3ce72d0 | 11225 | newr = BFD_RELOC_IA64_LTOFF_FPTR64I; break; |
0ca3e455 | 11226 | case BFD_RELOC_IA64_DIR32MSB: |
d3ce72d0 | 11227 | newr = BFD_RELOC_IA64_LTOFF_FPTR32MSB; break; |
0ca3e455 | 11228 | case BFD_RELOC_IA64_DIR32LSB: |
d3ce72d0 | 11229 | newr = BFD_RELOC_IA64_LTOFF_FPTR32LSB; break; |
0ca3e455 | 11230 | case BFD_RELOC_IA64_DIR64MSB: |
d3ce72d0 | 11231 | newr = BFD_RELOC_IA64_LTOFF_FPTR64MSB; break; |
0ca3e455 | 11232 | case BFD_RELOC_IA64_DIR64LSB: |
d3ce72d0 | 11233 | newr = BFD_RELOC_IA64_LTOFF_FPTR64LSB; break; |
800eeca4 | 11234 | default: |
0ca3e455 | 11235 | type = "LTOFF_FPTR"; break; |
800eeca4 JW |
11236 | } |
11237 | break; | |
3969b680 | 11238 | |
13ae64f3 JJ |
11239 | case FUNC_TP_RELATIVE: |
11240 | switch (r_type) | |
11241 | { | |
d3ce72d0 NC |
11242 | case BFD_RELOC_IA64_IMM14: newr = BFD_RELOC_IA64_TPREL14; break; |
11243 | case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_TPREL22; break; | |
11244 | case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_TPREL64I; break; | |
11245 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_TPREL64MSB; break; | |
11246 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_TPREL64LSB; break; | |
0ca3e455 | 11247 | default: type = "TPREL"; break; |
13ae64f3 JJ |
11248 | } |
11249 | break; | |
11250 | ||
11251 | case FUNC_LT_TP_RELATIVE: | |
11252 | switch (r_type) | |
11253 | { | |
11254 | case BFD_RELOC_IA64_IMM22: | |
d3ce72d0 | 11255 | newr = BFD_RELOC_IA64_LTOFF_TPREL22; break; |
13ae64f3 | 11256 | default: |
0ca3e455 JB |
11257 | type = "LTOFF_TPREL"; break; |
11258 | } | |
11259 | break; | |
11260 | ||
11261 | case FUNC_DTP_MODULE: | |
11262 | switch (r_type) | |
11263 | { | |
11264 | case BFD_RELOC_IA64_DIR64MSB: | |
d3ce72d0 | 11265 | newr = BFD_RELOC_IA64_DTPMOD64MSB; break; |
0ca3e455 | 11266 | case BFD_RELOC_IA64_DIR64LSB: |
d3ce72d0 | 11267 | newr = BFD_RELOC_IA64_DTPMOD64LSB; break; |
0ca3e455 JB |
11268 | default: |
11269 | type = "DTPMOD"; break; | |
13ae64f3 JJ |
11270 | } |
11271 | break; | |
11272 | ||
11273 | case FUNC_LT_DTP_MODULE: | |
11274 | switch (r_type) | |
11275 | { | |
11276 | case BFD_RELOC_IA64_IMM22: | |
d3ce72d0 | 11277 | newr = BFD_RELOC_IA64_LTOFF_DTPMOD22; break; |
13ae64f3 | 11278 | default: |
0ca3e455 | 11279 | type = "LTOFF_DTPMOD"; break; |
13ae64f3 JJ |
11280 | } |
11281 | break; | |
11282 | ||
11283 | case FUNC_DTP_RELATIVE: | |
11284 | switch (r_type) | |
11285 | { | |
0ca3e455 | 11286 | case BFD_RELOC_IA64_DIR32MSB: |
d3ce72d0 | 11287 | newr = BFD_RELOC_IA64_DTPREL32MSB; break; |
0ca3e455 | 11288 | case BFD_RELOC_IA64_DIR32LSB: |
d3ce72d0 | 11289 | newr = BFD_RELOC_IA64_DTPREL32LSB; break; |
6174d9c8 | 11290 | case BFD_RELOC_IA64_DIR64MSB: |
d3ce72d0 | 11291 | newr = BFD_RELOC_IA64_DTPREL64MSB; break; |
6174d9c8 | 11292 | case BFD_RELOC_IA64_DIR64LSB: |
d3ce72d0 | 11293 | newr = BFD_RELOC_IA64_DTPREL64LSB; break; |
13ae64f3 | 11294 | case BFD_RELOC_IA64_IMM14: |
d3ce72d0 | 11295 | newr = BFD_RELOC_IA64_DTPREL14; break; |
13ae64f3 | 11296 | case BFD_RELOC_IA64_IMM22: |
d3ce72d0 | 11297 | newr = BFD_RELOC_IA64_DTPREL22; break; |
13ae64f3 | 11298 | case BFD_RELOC_IA64_IMM64: |
d3ce72d0 | 11299 | newr = BFD_RELOC_IA64_DTPREL64I; break; |
13ae64f3 | 11300 | default: |
0ca3e455 | 11301 | type = "DTPREL"; break; |
13ae64f3 JJ |
11302 | } |
11303 | break; | |
11304 | ||
11305 | case FUNC_LT_DTP_RELATIVE: | |
11306 | switch (r_type) | |
11307 | { | |
11308 | case BFD_RELOC_IA64_IMM22: | |
d3ce72d0 | 11309 | newr = BFD_RELOC_IA64_LTOFF_DTPREL22; break; |
13ae64f3 | 11310 | default: |
0ca3e455 | 11311 | type = "LTOFF_DTPREL"; break; |
13ae64f3 JJ |
11312 | } |
11313 | break; | |
11314 | ||
40449e9f | 11315 | case FUNC_IPLT_RELOC: |
0ca3e455 JB |
11316 | switch (r_type) |
11317 | { | |
11318 | case BFD_RELOC_IA64_IPLTMSB: return r_type; | |
11319 | case BFD_RELOC_IA64_IPLTLSB: return r_type; | |
11320 | default: type = "IPLT"; break; | |
11321 | } | |
40449e9f | 11322 | break; |
1cd8ff38 | 11323 | |
9d0e8497 TG |
11324 | #ifdef TE_VMS |
11325 | case FUNC_SLOTCOUNT_RELOC: | |
11326 | return DUMMY_RELOC_IA64_SLOTCOUNT; | |
11327 | #endif | |
11328 | ||
800eeca4 JW |
11329 | default: |
11330 | abort (); | |
11331 | } | |
6174d9c8 | 11332 | |
d3ce72d0 NC |
11333 | if (newr) |
11334 | return newr; | |
800eeca4 | 11335 | else |
0ca3e455 JB |
11336 | { |
11337 | int width; | |
11338 | ||
11339 | if (!type) | |
11340 | abort (); | |
11341 | switch (r_type) | |
11342 | { | |
11343 | case BFD_RELOC_IA64_DIR32MSB: width = 32; suffix = "MSB"; break; | |
11344 | case BFD_RELOC_IA64_DIR32LSB: width = 32; suffix = "LSB"; break; | |
11345 | case BFD_RELOC_IA64_DIR64MSB: width = 64; suffix = "MSB"; break; | |
11346 | case BFD_RELOC_IA64_DIR64LSB: width = 64; suffix = "LSB"; break; | |
30ad6cb9 | 11347 | case BFD_RELOC_UNUSED: width = 13; break; |
0ca3e455 JB |
11348 | case BFD_RELOC_IA64_IMM14: width = 14; break; |
11349 | case BFD_RELOC_IA64_IMM22: width = 22; break; | |
11350 | case BFD_RELOC_IA64_IMM64: width = 64; suffix = "I"; break; | |
11351 | default: abort (); | |
11352 | } | |
11353 | ||
11354 | /* This should be an error, but since previously there wasn't any | |
ad4b42b4 NC |
11355 | diagnostic here, don't make it fail because of this for now. */ |
11356 | as_warn (_("Cannot express %s%d%s relocation"), type, width, suffix); | |
0ca3e455 JB |
11357 | return r_type; |
11358 | } | |
800eeca4 JW |
11359 | } |
11360 | ||
11361 | /* Here is where generate the appropriate reloc for pseudo relocation | |
11362 | functions. */ | |
11363 | void | |
5a49b8ac | 11364 | ia64_validate_fix (fixS *fix) |
800eeca4 JW |
11365 | { |
11366 | switch (fix->fx_r_type) | |
11367 | { | |
11368 | case BFD_RELOC_IA64_FPTR64I: | |
11369 | case BFD_RELOC_IA64_FPTR32MSB: | |
11370 | case BFD_RELOC_IA64_FPTR64LSB: | |
11371 | case BFD_RELOC_IA64_LTOFF_FPTR22: | |
11372 | case BFD_RELOC_IA64_LTOFF_FPTR64I: | |
11373 | if (fix->fx_offset != 0) | |
11374 | as_bad_where (fix->fx_file, fix->fx_line, | |
ad4b42b4 | 11375 | _("No addend allowed in @fptr() relocation")); |
800eeca4 JW |
11376 | break; |
11377 | default: | |
11378 | break; | |
11379 | } | |
800eeca4 JW |
11380 | } |
11381 | ||
11382 | static void | |
5a49b8ac | 11383 | fix_insn (fixS *fix, const struct ia64_operand *odesc, valueT value) |
800eeca4 JW |
11384 | { |
11385 | bfd_vma insn[3], t0, t1, control_bits; | |
11386 | const char *err; | |
11387 | char *fixpos; | |
11388 | long slot; | |
11389 | ||
11390 | slot = fix->fx_where & 0x3; | |
11391 | fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot); | |
11392 | ||
c67e42c9 | 11393 | /* Bundles are always in little-endian byte order */ |
800eeca4 JW |
11394 | t0 = bfd_getl64 (fixpos); |
11395 | t1 = bfd_getl64 (fixpos + 8); | |
11396 | control_bits = t0 & 0x1f; | |
11397 | insn[0] = (t0 >> 5) & 0x1ffffffffffLL; | |
11398 | insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18); | |
11399 | insn[2] = (t1 >> 23) & 0x1ffffffffffLL; | |
11400 | ||
c67e42c9 RH |
11401 | err = NULL; |
11402 | if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64) | |
800eeca4 | 11403 | { |
c67e42c9 RH |
11404 | insn[1] = (value >> 22) & 0x1ffffffffffLL; |
11405 | insn[2] |= (((value & 0x7f) << 13) | |
11406 | | (((value >> 7) & 0x1ff) << 27) | |
11407 | | (((value >> 16) & 0x1f) << 22) | |
11408 | | (((value >> 21) & 0x1) << 21) | |
11409 | | (((value >> 63) & 0x1) << 36)); | |
800eeca4 | 11410 | } |
c67e42c9 RH |
11411 | else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62) |
11412 | { | |
11413 | if (value & ~0x3fffffffffffffffULL) | |
20203fb9 | 11414 | err = _("integer operand out of range"); |
c67e42c9 RH |
11415 | insn[1] = (value >> 21) & 0x1ffffffffffLL; |
11416 | insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36)); | |
11417 | } | |
11418 | else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64) | |
11419 | { | |
11420 | value >>= 4; | |
11421 | insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2; | |
11422 | insn[2] |= ((((value >> 59) & 0x1) << 36) | |
11423 | | (((value >> 0) & 0xfffff) << 13)); | |
11424 | } | |
11425 | else | |
11426 | err = (*odesc->insert) (odesc, value, insn + slot); | |
11427 | ||
11428 | if (err) | |
83cf10fd | 11429 | as_bad_where (fix->fx_file, fix->fx_line, "%s", err); |
800eeca4 JW |
11430 | |
11431 | t0 = control_bits | (insn[0] << 5) | (insn[1] << 46); | |
11432 | t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23); | |
44f5c83a JW |
11433 | number_to_chars_littleendian (fixpos + 0, t0, 8); |
11434 | number_to_chars_littleendian (fixpos + 8, t1, 8); | |
800eeca4 JW |
11435 | } |
11436 | ||
11437 | /* Attempt to simplify or even eliminate a fixup. The return value is | |
11438 | ignored; perhaps it was once meaningful, but now it is historical. | |
11439 | To indicate that a fixup has been eliminated, set FIXP->FX_DONE. | |
11440 | ||
11441 | If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry | |
197865e8 | 11442 | (if possible). */ |
94f592af NC |
11443 | |
11444 | void | |
5a49b8ac | 11445 | md_apply_fix (fixS *fix, valueT *valP, segT seg ATTRIBUTE_UNUSED) |
800eeca4 JW |
11446 | { |
11447 | char *fixpos; | |
40449e9f | 11448 | valueT value = *valP; |
800eeca4 JW |
11449 | |
11450 | fixpos = fix->fx_frag->fr_literal + fix->fx_where; | |
11451 | ||
11452 | if (fix->fx_pcrel) | |
11453 | { | |
7b347e43 JB |
11454 | switch (fix->fx_r_type) |
11455 | { | |
11456 | case BFD_RELOC_IA64_PCREL21B: break; | |
11457 | case BFD_RELOC_IA64_PCREL21BI: break; | |
11458 | case BFD_RELOC_IA64_PCREL21F: break; | |
11459 | case BFD_RELOC_IA64_PCREL21M: break; | |
11460 | case BFD_RELOC_IA64_PCREL60B: break; | |
11461 | case BFD_RELOC_IA64_PCREL22: break; | |
11462 | case BFD_RELOC_IA64_PCREL64I: break; | |
11463 | case BFD_RELOC_IA64_PCREL32MSB: break; | |
11464 | case BFD_RELOC_IA64_PCREL32LSB: break; | |
11465 | case BFD_RELOC_IA64_PCREL64MSB: break; | |
11466 | case BFD_RELOC_IA64_PCREL64LSB: break; | |
11467 | default: | |
11468 | fix->fx_r_type = ia64_gen_real_reloc_type (pseudo_func[FUNC_PC_RELATIVE].u.sym, | |
11469 | fix->fx_r_type); | |
11470 | break; | |
11471 | } | |
800eeca4 JW |
11472 | } |
11473 | if (fix->fx_addsy) | |
11474 | { | |
592588f3 | 11475 | switch ((unsigned) fix->fx_r_type) |
800eeca4 | 11476 | { |
00f7efb6 | 11477 | case BFD_RELOC_UNUSED: |
fa1cb89c JW |
11478 | /* This must be a TAG13 or TAG13b operand. There are no external |
11479 | relocs defined for them, so we must give an error. */ | |
800eeca4 | 11480 | as_bad_where (fix->fx_file, fix->fx_line, |
ad4b42b4 | 11481 | _("%s must have a constant value"), |
800eeca4 | 11482 | elf64_ia64_operands[fix->tc_fix_data.opnd].desc); |
fa1cb89c | 11483 | fix->fx_done = 1; |
94f592af | 11484 | return; |
00f7efb6 JJ |
11485 | |
11486 | case BFD_RELOC_IA64_TPREL14: | |
11487 | case BFD_RELOC_IA64_TPREL22: | |
11488 | case BFD_RELOC_IA64_TPREL64I: | |
11489 | case BFD_RELOC_IA64_LTOFF_TPREL22: | |
11490 | case BFD_RELOC_IA64_LTOFF_DTPMOD22: | |
11491 | case BFD_RELOC_IA64_DTPREL14: | |
11492 | case BFD_RELOC_IA64_DTPREL22: | |
11493 | case BFD_RELOC_IA64_DTPREL64I: | |
11494 | case BFD_RELOC_IA64_LTOFF_DTPREL22: | |
11495 | S_SET_THREAD_LOCAL (fix->fx_addsy); | |
11496 | break; | |
7925dd68 | 11497 | |
9d0e8497 TG |
11498 | #ifdef TE_VMS |
11499 | case DUMMY_RELOC_IA64_SLOTCOUNT: | |
11500 | as_bad_where (fix->fx_file, fix->fx_line, | |
11501 | _("cannot resolve @slotcount parameter")); | |
11502 | fix->fx_done = 1; | |
11503 | return; | |
11504 | #endif | |
11505 | ||
7925dd68 JJ |
11506 | default: |
11507 | break; | |
800eeca4 | 11508 | } |
800eeca4 JW |
11509 | } |
11510 | else if (fix->tc_fix_data.opnd == IA64_OPND_NIL) | |
11511 | { | |
9d0e8497 TG |
11512 | #ifdef TE_VMS |
11513 | if (fix->fx_r_type == DUMMY_RELOC_IA64_SLOTCOUNT) | |
11514 | { | |
11515 | /* For @slotcount, convert an addresses difference to a slots | |
11516 | difference. */ | |
11517 | valueT v; | |
11518 | ||
11519 | v = (value >> 4) * 3; | |
11520 | switch (value & 0x0f) | |
11521 | { | |
11522 | case 0: | |
11523 | case 1: | |
11524 | case 2: | |
11525 | v += value & 0x0f; | |
11526 | break; | |
11527 | case 0x0f: | |
11528 | v += 2; | |
11529 | break; | |
11530 | case 0x0e: | |
11531 | v += 1; | |
11532 | break; | |
11533 | default: | |
11534 | as_bad (_("invalid @slotcount value")); | |
11535 | } | |
11536 | value = v; | |
11537 | } | |
11538 | #endif | |
11539 | ||
800eeca4 JW |
11540 | if (fix->tc_fix_data.bigendian) |
11541 | number_to_chars_bigendian (fixpos, value, fix->fx_size); | |
11542 | else | |
11543 | number_to_chars_littleendian (fixpos, value, fix->fx_size); | |
11544 | fix->fx_done = 1; | |
800eeca4 JW |
11545 | } |
11546 | else | |
11547 | { | |
11548 | fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value); | |
11549 | fix->fx_done = 1; | |
800eeca4 | 11550 | } |
800eeca4 JW |
11551 | } |
11552 | ||
11553 | /* Generate the BFD reloc to be stuck in the object file from the | |
11554 | fixup used internally in the assembler. */ | |
542d6675 KH |
11555 | |
11556 | arelent * | |
5a49b8ac | 11557 | tc_gen_reloc (asection *sec ATTRIBUTE_UNUSED, fixS *fixp) |
800eeca4 JW |
11558 | { |
11559 | arelent *reloc; | |
11560 | ||
11561 | reloc = xmalloc (sizeof (*reloc)); | |
11562 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); | |
11563 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
11564 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
11565 | reloc->addend = fixp->fx_offset; | |
11566 | reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); | |
11567 | ||
11568 | if (!reloc->howto) | |
11569 | { | |
11570 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
ad4b42b4 | 11571 | _("Cannot represent %s relocation in object file"), |
800eeca4 | 11572 | bfd_get_reloc_code_name (fixp->fx_r_type)); |
cf738528 AS |
11573 | free (reloc); |
11574 | return NULL; | |
800eeca4 JW |
11575 | } |
11576 | return reloc; | |
11577 | } | |
11578 | ||
11579 | /* Turn a string in input_line_pointer into a floating point constant | |
bc0d738a NC |
11580 | of type TYPE, and store the appropriate bytes in *LIT. The number |
11581 | of LITTLENUMS emitted is stored in *SIZE. An error message is | |
800eeca4 JW |
11582 | returned, or NULL on OK. */ |
11583 | ||
11584 | #define MAX_LITTLENUMS 5 | |
11585 | ||
542d6675 | 11586 | char * |
499ac353 | 11587 | md_atof (int type, char *lit, int *size) |
800eeca4 JW |
11588 | { |
11589 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
800eeca4 JW |
11590 | char *t; |
11591 | int prec; | |
11592 | ||
11593 | switch (type) | |
11594 | { | |
11595 | /* IEEE floats */ | |
11596 | case 'f': | |
11597 | case 'F': | |
11598 | case 's': | |
11599 | case 'S': | |
11600 | prec = 2; | |
11601 | break; | |
11602 | ||
11603 | case 'd': | |
11604 | case 'D': | |
11605 | case 'r': | |
11606 | case 'R': | |
11607 | prec = 4; | |
11608 | break; | |
11609 | ||
11610 | case 'x': | |
11611 | case 'X': | |
11612 | case 'p': | |
11613 | case 'P': | |
11614 | prec = 5; | |
11615 | break; | |
11616 | ||
11617 | default: | |
11618 | *size = 0; | |
499ac353 | 11619 | return _("Unrecognized or unsupported floating point constant"); |
800eeca4 JW |
11620 | } |
11621 | t = atof_ieee (input_line_pointer, type, words); | |
11622 | if (t) | |
11623 | input_line_pointer = t; | |
800eeca4 | 11624 | |
10a98291 L |
11625 | (*ia64_float_to_chars) (lit, words, prec); |
11626 | ||
165a7f90 L |
11627 | if (type == 'X') |
11628 | { | |
11629 | /* It is 10 byte floating point with 6 byte padding. */ | |
10a98291 | 11630 | memset (&lit [10], 0, 6); |
165a7f90 L |
11631 | *size = 8 * sizeof (LITTLENUM_TYPE); |
11632 | } | |
10a98291 L |
11633 | else |
11634 | *size = prec * sizeof (LITTLENUM_TYPE); | |
11635 | ||
499ac353 | 11636 | return NULL; |
800eeca4 JW |
11637 | } |
11638 | ||
800eeca4 JW |
11639 | /* Handle ia64 specific semantics of the align directive. */ |
11640 | ||
0a9ef439 | 11641 | void |
5a49b8ac AM |
11642 | ia64_md_do_align (int n ATTRIBUTE_UNUSED, |
11643 | const char *fill ATTRIBUTE_UNUSED, | |
11644 | int len ATTRIBUTE_UNUSED, | |
11645 | int max ATTRIBUTE_UNUSED) | |
800eeca4 | 11646 | { |
0a9ef439 | 11647 | if (subseg_text_p (now_seg)) |
800eeca4 | 11648 | ia64_flush_insns (); |
0a9ef439 | 11649 | } |
800eeca4 | 11650 | |
0a9ef439 RH |
11651 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
11652 | of an rs_align_code fragment. */ | |
800eeca4 | 11653 | |
0a9ef439 | 11654 | void |
5a49b8ac | 11655 | ia64_handle_align (fragS *fragp) |
0a9ef439 | 11656 | { |
0a9ef439 RH |
11657 | int bytes; |
11658 | char *p; | |
91d6fa6a | 11659 | const unsigned char *nop_type; |
0a9ef439 RH |
11660 | |
11661 | if (fragp->fr_type != rs_align_code) | |
11662 | return; | |
11663 | ||
9545c4ce | 11664 | /* Check if this frag has to end with a stop bit. */ |
91d6fa6a | 11665 | nop_type = fragp->tc_frag_data ? le_nop_stop : le_nop; |
9545c4ce | 11666 | |
0a9ef439 RH |
11667 | bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix; |
11668 | p = fragp->fr_literal + fragp->fr_fix; | |
11669 | ||
3739860c | 11670 | /* If no paddings are needed, we check if we need a stop bit. */ |
d9201763 L |
11671 | if (!bytes && fragp->tc_frag_data) |
11672 | { | |
11673 | if (fragp->fr_fix < 16) | |
bae25f19 L |
11674 | #if 1 |
11675 | /* FIXME: It won't work with | |
11676 | .align 16 | |
11677 | alloc r32=ar.pfs,1,2,4,0 | |
11678 | */ | |
11679 | ; | |
11680 | #else | |
d9201763 L |
11681 | as_bad_where (fragp->fr_file, fragp->fr_line, |
11682 | _("Can't add stop bit to mark end of instruction group")); | |
bae25f19 | 11683 | #endif |
d9201763 L |
11684 | else |
11685 | /* Bundles are always in little-endian byte order. Make sure | |
11686 | the previous bundle has the stop bit. */ | |
11687 | *(p - 16) |= 1; | |
11688 | } | |
11689 | ||
0a9ef439 RH |
11690 | /* Make sure we are on a 16-byte boundary, in case someone has been |
11691 | putting data into a text section. */ | |
11692 | if (bytes & 15) | |
11693 | { | |
11694 | int fix = bytes & 15; | |
11695 | memset (p, 0, fix); | |
11696 | p += fix; | |
11697 | bytes -= fix; | |
11698 | fragp->fr_fix += fix; | |
800eeca4 JW |
11699 | } |
11700 | ||
012a452b | 11701 | /* Instruction bundles are always little-endian. */ |
91d6fa6a | 11702 | memcpy (p, nop_type, 16); |
0a9ef439 | 11703 | fragp->fr_var = 16; |
800eeca4 | 11704 | } |
10a98291 L |
11705 | |
11706 | static void | |
11707 | ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words, | |
11708 | int prec) | |
11709 | { | |
11710 | while (prec--) | |
11711 | { | |
11712 | number_to_chars_bigendian (lit, (long) (*words++), | |
11713 | sizeof (LITTLENUM_TYPE)); | |
11714 | lit += sizeof (LITTLENUM_TYPE); | |
11715 | } | |
11716 | } | |
11717 | ||
11718 | static void | |
11719 | ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words, | |
11720 | int prec) | |
11721 | { | |
11722 | while (prec--) | |
11723 | { | |
11724 | number_to_chars_littleendian (lit, (long) (words[prec]), | |
11725 | sizeof (LITTLENUM_TYPE)); | |
11726 | lit += sizeof (LITTLENUM_TYPE); | |
11727 | } | |
11728 | } | |
11729 | ||
11730 | void | |
5a49b8ac | 11731 | ia64_elf_section_change_hook (void) |
10a98291 | 11732 | { |
38ce5b11 L |
11733 | if (elf_section_type (now_seg) == SHT_IA_64_UNWIND |
11734 | && elf_linked_to_section (now_seg) == NULL) | |
11735 | elf_linked_to_section (now_seg) = text_section; | |
10a98291 L |
11736 | dot_byteorder (-1); |
11737 | } | |
a645d1eb L |
11738 | |
11739 | /* Check if a label should be made global. */ | |
11740 | void | |
11741 | ia64_check_label (symbolS *label) | |
11742 | { | |
11743 | if (*input_line_pointer == ':') | |
11744 | { | |
11745 | S_SET_EXTERNAL (label); | |
11746 | input_line_pointer++; | |
11747 | } | |
11748 | } | |
35f5df7f L |
11749 | |
11750 | /* Used to remember where .alias and .secalias directives are seen. We | |
11751 | will rename symbol and section names when we are about to output | |
11752 | the relocatable file. */ | |
11753 | struct alias | |
11754 | { | |
3b4dbbbf | 11755 | const char *file; /* The file where the directive is seen. */ |
35f5df7f | 11756 | unsigned int line; /* The line number the directive is at. */ |
708587a4 | 11757 | const char *name; /* The original name of the symbol. */ |
35f5df7f L |
11758 | }; |
11759 | ||
11760 | /* Called for .alias and .secalias directives. If SECTION is 1, it is | |
11761 | .secalias. Otherwise, it is .alias. */ | |
11762 | static void | |
11763 | dot_alias (int section) | |
11764 | { | |
11765 | char *name, *alias; | |
11766 | char delim; | |
11767 | char *end_name; | |
11768 | int len; | |
11769 | const char *error_string; | |
11770 | struct alias *h; | |
11771 | const char *a; | |
11772 | struct hash_control *ahash, *nhash; | |
11773 | const char *kind; | |
11774 | ||
d02603dc | 11775 | delim = get_symbol_name (&name); |
35f5df7f L |
11776 | end_name = input_line_pointer; |
11777 | *end_name = delim; | |
11778 | ||
11779 | if (name == end_name) | |
11780 | { | |
11781 | as_bad (_("expected symbol name")); | |
e4e8248d | 11782 | ignore_rest_of_line (); |
35f5df7f L |
11783 | return; |
11784 | } | |
11785 | ||
d02603dc | 11786 | SKIP_WHITESPACE_AFTER_NAME (); |
35f5df7f L |
11787 | |
11788 | if (*input_line_pointer != ',') | |
11789 | { | |
11790 | *end_name = 0; | |
11791 | as_bad (_("expected comma after \"%s\""), name); | |
11792 | *end_name = delim; | |
11793 | ignore_rest_of_line (); | |
11794 | return; | |
11795 | } | |
11796 | ||
11797 | input_line_pointer++; | |
11798 | *end_name = 0; | |
20b36a95 | 11799 | ia64_canonicalize_symbol_name (name); |
35f5df7f L |
11800 | |
11801 | /* We call demand_copy_C_string to check if alias string is valid. | |
11802 | There should be a closing `"' and no `\0' in the string. */ | |
11803 | alias = demand_copy_C_string (&len); | |
11804 | if (alias == NULL) | |
11805 | { | |
11806 | ignore_rest_of_line (); | |
11807 | return; | |
11808 | } | |
11809 | ||
11810 | /* Make a copy of name string. */ | |
11811 | len = strlen (name) + 1; | |
11812 | obstack_grow (¬es, name, len); | |
11813 | name = obstack_finish (¬es); | |
11814 | ||
11815 | if (section) | |
11816 | { | |
11817 | kind = "section"; | |
11818 | ahash = secalias_hash; | |
11819 | nhash = secalias_name_hash; | |
11820 | } | |
11821 | else | |
11822 | { | |
11823 | kind = "symbol"; | |
11824 | ahash = alias_hash; | |
11825 | nhash = alias_name_hash; | |
11826 | } | |
11827 | ||
11828 | /* Check if alias has been used before. */ | |
11829 | h = (struct alias *) hash_find (ahash, alias); | |
11830 | if (h) | |
11831 | { | |
11832 | if (strcmp (h->name, name)) | |
11833 | as_bad (_("`%s' is already the alias of %s `%s'"), | |
11834 | alias, kind, h->name); | |
11835 | goto out; | |
11836 | } | |
11837 | ||
11838 | /* Check if name already has an alias. */ | |
11839 | a = (const char *) hash_find (nhash, name); | |
11840 | if (a) | |
11841 | { | |
11842 | if (strcmp (a, alias)) | |
11843 | as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a); | |
11844 | goto out; | |
11845 | } | |
11846 | ||
11847 | h = (struct alias *) xmalloc (sizeof (struct alias)); | |
3b4dbbbf | 11848 | h->file = as_where (&h->line); |
35f5df7f | 11849 | h->name = name; |
3739860c | 11850 | |
5a49b8ac | 11851 | error_string = hash_jam (ahash, alias, (void *) h); |
35f5df7f L |
11852 | if (error_string) |
11853 | { | |
11854 | as_fatal (_("inserting \"%s\" into %s alias hash table failed: %s"), | |
11855 | alias, kind, error_string); | |
11856 | goto out; | |
11857 | } | |
11858 | ||
5a49b8ac | 11859 | error_string = hash_jam (nhash, name, (void *) alias); |
35f5df7f L |
11860 | if (error_string) |
11861 | { | |
11862 | as_fatal (_("inserting \"%s\" into %s name hash table failed: %s"), | |
11863 | alias, kind, error_string); | |
11864 | out: | |
11865 | obstack_free (¬es, name); | |
11866 | obstack_free (¬es, alias); | |
11867 | } | |
11868 | ||
11869 | demand_empty_rest_of_line (); | |
11870 | } | |
11871 | ||
11872 | /* It renames the original symbol name to its alias. */ | |
11873 | static void | |
5a49b8ac | 11874 | do_alias (const char *alias, void *value) |
35f5df7f L |
11875 | { |
11876 | struct alias *h = (struct alias *) value; | |
11877 | symbolS *sym = symbol_find (h->name); | |
11878 | ||
11879 | if (sym == NULL) | |
01e1a5bc NC |
11880 | { |
11881 | #ifdef TE_VMS | |
11882 | /* Uses .alias extensively to alias CRTL functions to same with | |
11883 | decc$ prefix. Sometimes function gets optimized away and a | |
11884 | warning results, which should be suppressed. */ | |
11885 | if (strncmp (alias, "decc$", 5) != 0) | |
11886 | #endif | |
11887 | as_warn_where (h->file, h->line, | |
11888 | _("symbol `%s' aliased to `%s' is not used"), | |
11889 | h->name, alias); | |
11890 | } | |
35f5df7f L |
11891 | else |
11892 | S_SET_NAME (sym, (char *) alias); | |
11893 | } | |
11894 | ||
11895 | /* Called from write_object_file. */ | |
11896 | void | |
11897 | ia64_adjust_symtab (void) | |
11898 | { | |
11899 | hash_traverse (alias_hash, do_alias); | |
11900 | } | |
11901 | ||
11902 | /* It renames the original section name to its alias. */ | |
11903 | static void | |
5a49b8ac | 11904 | do_secalias (const char *alias, void *value) |
35f5df7f L |
11905 | { |
11906 | struct alias *h = (struct alias *) value; | |
11907 | segT sec = bfd_get_section_by_name (stdoutput, h->name); | |
11908 | ||
11909 | if (sec == NULL) | |
11910 | as_warn_where (h->file, h->line, | |
11911 | _("section `%s' aliased to `%s' is not used"), | |
11912 | h->name, alias); | |
11913 | else | |
11914 | sec->name = alias; | |
11915 | } | |
11916 | ||
11917 | /* Called from write_object_file. */ | |
11918 | void | |
11919 | ia64_frob_file (void) | |
11920 | { | |
11921 | hash_traverse (secalias_hash, do_secalias); | |
11922 | } | |
01e1a5bc NC |
11923 | |
11924 | #ifdef TE_VMS | |
11925 | #define NT_VMS_MHD 1 | |
11926 | #define NT_VMS_LNM 2 | |
11927 | ||
11928 | /* Integrity VMS 8.x identifies it's ELF modules with a standard ELF | |
11929 | .note section. */ | |
11930 | ||
11931 | /* Manufacture a VMS-like time string. */ | |
11932 | static void | |
11933 | get_vms_time (char *Now) | |
11934 | { | |
11935 | char *pnt; | |
11936 | time_t timeb; | |
11937 | ||
11938 | time (&timeb); | |
11939 | pnt = ctime (&timeb); | |
11940 | pnt[3] = 0; | |
11941 | pnt[7] = 0; | |
11942 | pnt[10] = 0; | |
11943 | pnt[16] = 0; | |
11944 | pnt[24] = 0; | |
11945 | sprintf (Now, "%2s-%3s-%s %s", pnt + 8, pnt + 4, pnt + 20, pnt + 11); | |
11946 | } | |
11947 | ||
11948 | void | |
11949 | ia64_vms_note (void) | |
11950 | { | |
11951 | char *p; | |
11952 | asection *seg = now_seg; | |
11953 | subsegT subseg = now_subseg; | |
01e1a5bc | 11954 | asection *secp = NULL; |
a0840211 | 11955 | char *bname; |
01e1a5bc NC |
11956 | char buf [256]; |
11957 | symbolS *sym; | |
11958 | ||
11959 | /* Create the .note section. */ | |
11960 | ||
11961 | secp = subseg_new (".note", 0); | |
11962 | bfd_set_section_flags (stdoutput, | |
11963 | secp, | |
11964 | SEC_HAS_CONTENTS | SEC_READONLY); | |
11965 | ||
37a1f277 | 11966 | /* Module header note (MHD). */ |
a0840211 | 11967 | bname = xstrdup (lbasename (out_file_name)); |
01e1a5bc NC |
11968 | if ((p = strrchr (bname, '.'))) |
11969 | *p = '\0'; | |
3739860c | 11970 | |
37a1f277 TG |
11971 | /* VMS note header is 24 bytes long. */ |
11972 | p = frag_more (8 + 8 + 8); | |
11973 | number_to_chars_littleendian (p + 0, 8, 8); | |
11974 | number_to_chars_littleendian (p + 8, 40 + strlen (bname), 8); | |
11975 | number_to_chars_littleendian (p + 16, NT_VMS_MHD, 8); | |
01e1a5bc NC |
11976 | |
11977 | p = frag_more (8); | |
11978 | strcpy (p, "IPF/VMS"); | |
11979 | ||
37a1f277 TG |
11980 | p = frag_more (17 + 17 + strlen (bname) + 1 + 5); |
11981 | get_vms_time (p); | |
11982 | strcpy (p + 17, "24-FEB-2005 15:00"); | |
11983 | p += 17 + 17; | |
01e1a5bc | 11984 | strcpy (p, bname); |
37a1f277 | 11985 | p += strlen (bname) + 1; |
a0840211 | 11986 | free (bname); |
01e1a5bc NC |
11987 | strcpy (p, "V1.0"); |
11988 | ||
11989 | frag_align (3, 0, 0); | |
11990 | ||
11991 | /* Language processor name note. */ | |
11992 | sprintf (buf, "GNU assembler version %s (%s) using BFD version %s", | |
11993 | VERSION, TARGET_ALIAS, BFD_VERSION_STRING); | |
11994 | ||
37a1f277 TG |
11995 | p = frag_more (8 + 8 + 8); |
11996 | number_to_chars_littleendian (p + 0, 8, 8); | |
11997 | number_to_chars_littleendian (p + 8, strlen (buf) + 1, 8); | |
11998 | number_to_chars_littleendian (p + 16, NT_VMS_LNM, 8); | |
01e1a5bc NC |
11999 | |
12000 | p = frag_more (8); | |
12001 | strcpy (p, "IPF/VMS"); | |
12002 | ||
12003 | p = frag_more (strlen (buf) + 1); | |
12004 | strcpy (p, buf); | |
12005 | ||
12006 | frag_align (3, 0, 0); | |
12007 | ||
12008 | secp = subseg_new (".vms_display_name_info", 0); | |
12009 | bfd_set_section_flags (stdoutput, | |
12010 | secp, | |
12011 | SEC_HAS_CONTENTS | SEC_READONLY); | |
12012 | ||
12013 | /* This symbol should be passed on the command line and be variable | |
12014 | according to language. */ | |
12015 | sym = symbol_new ("__gnat_vms_display_name@gnat_demangler_rtl", | |
12016 | absolute_section, 0, &zero_address_frag); | |
12017 | symbol_table_insert (sym); | |
12018 | symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING | BSF_DYNAMIC; | |
12019 | ||
12020 | p = frag_more (4); | |
12021 | /* Format 3 of VMS demangler Spec. */ | |
12022 | number_to_chars_littleendian (p, 3, 4); | |
12023 | ||
12024 | p = frag_more (4); | |
12025 | /* Place holder for symbol table index of above symbol. */ | |
12026 | number_to_chars_littleendian (p, -1, 4); | |
12027 | ||
12028 | frag_align (3, 0, 0); | |
12029 | ||
12030 | /* We probably can't restore the current segment, for there likely | |
12031 | isn't one yet... */ | |
12032 | if (seg && subseg) | |
12033 | subseg_set (seg, subseg); | |
12034 | } | |
12035 | ||
12036 | #endif /* TE_VMS */ |