Commit | Line | Data |
---|---|---|
800eeca4 | 1 | /* tc-ia64.c -- Assembler for the HP/Intel IA-64 architecture. |
b90efa5b | 2 | Copyright (C) 1998-2015 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]; | |
305 | char *src_file; | |
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 */ | |
675 | 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 | ||
2d6ed997 L |
3524 | static char *special_linkonce_name[] = |
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; | |
3569 | size_t prefix_len, suffix_len, sec_name_len; | |
3570 | ||
3571 | sec_text_name = segment_name (text_seg); | |
3572 | text_name = sec_text_name; | |
3573 | if (strncmp (text_name, "_info", 5) == 0) | |
3574 | { | |
ad4b42b4 | 3575 | as_bad (_("Illegal section name `%s' (causes unwind section name clash)"), |
2d6ed997 L |
3576 | text_name); |
3577 | ignore_rest_of_line (); | |
3578 | return; | |
3579 | } | |
3580 | if (strcmp (text_name, ".text") == 0) | |
3581 | text_name = ""; | |
3582 | ||
3583 | /* Build the unwind section name by appending the (possibly stripped) | |
3584 | text section name to the unwind prefix. */ | |
3585 | suffix = text_name; | |
3586 | if (strncmp (text_name, ".gnu.linkonce.t.", | |
3587 | sizeof (".gnu.linkonce.t.") - 1) == 0) | |
3588 | { | |
3589 | prefix = special_linkonce_name [sec_index - SPECIAL_SECTION_UNWIND]; | |
3590 | suffix += sizeof (".gnu.linkonce.t.") - 1; | |
3591 | } | |
3592 | ||
3593 | prefix_len = strlen (prefix); | |
3594 | suffix_len = strlen (suffix); | |
3595 | sec_name_len = prefix_len + suffix_len; | |
3596 | sec_name = alloca (sec_name_len + 1); | |
3597 | memcpy (sec_name, prefix, prefix_len); | |
3598 | memcpy (sec_name + prefix_len, suffix, suffix_len); | |
3599 | sec_name [sec_name_len] = '\0'; | |
3600 | ||
3601 | /* Handle COMDAT group. */ | |
6e3f953d L |
3602 | if ((text_seg->flags & SEC_LINK_ONCE) != 0 |
3603 | && (elf_section_flags (text_seg) & SHF_GROUP) != 0) | |
2d6ed997 L |
3604 | { |
3605 | char *section; | |
3606 | size_t len, group_name_len; | |
3607 | const char *group_name = elf_group_name (text_seg); | |
3608 | ||
3609 | if (group_name == NULL) | |
3610 | { | |
ad4b42b4 | 3611 | as_bad (_("Group section `%s' has no group signature"), |
2d6ed997 L |
3612 | sec_text_name); |
3613 | ignore_rest_of_line (); | |
3614 | return; | |
3615 | } | |
3616 | /* We have to construct a fake section directive. */ | |
3617 | group_name_len = strlen (group_name); | |
3618 | len = (sec_name_len | |
3619 | + 16 /* ,"aG",@progbits, */ | |
3620 | + group_name_len /* ,group_name */ | |
3621 | + 7); /* ,comdat */ | |
3622 | ||
3623 | section = alloca (len + 1); | |
3624 | memcpy (section, sec_name, sec_name_len); | |
3625 | memcpy (section + sec_name_len, ",\"aG\",@progbits,", 16); | |
3626 | memcpy (section + sec_name_len + 16, group_name, group_name_len); | |
3627 | memcpy (section + len - 7, ",comdat", 7); | |
3628 | section [len] = '\0'; | |
3629 | set_section (section); | |
3630 | } | |
3631 | else | |
3632 | { | |
3633 | set_section (sec_name); | |
3634 | bfd_set_section_flags (stdoutput, now_seg, | |
3635 | SEC_LOAD | SEC_ALLOC | SEC_READONLY); | |
3636 | } | |
38ce5b11 L |
3637 | |
3638 | elf_linked_to_section (now_seg) = text_seg; | |
2d6ed997 L |
3639 | } |
3640 | ||
73f20958 | 3641 | static void |
2d6ed997 | 3642 | generate_unwind_image (const segT text_seg) |
800eeca4 | 3643 | { |
73f20958 L |
3644 | int size, pad; |
3645 | unw_rec_list *list; | |
800eeca4 | 3646 | |
c97b7ef6 JW |
3647 | /* Mark the end of the unwind info, so that we can compute the size of the |
3648 | last unwind region. */ | |
e4e8248d | 3649 | add_unwind_entry (output_endp (), NOT_A_CHAR); |
c97b7ef6 | 3650 | |
10850f29 JW |
3651 | /* Force out pending instructions, to make sure all unwind records have |
3652 | a valid slot_number field. */ | |
3653 | ia64_flush_insns (); | |
3654 | ||
800eeca4 | 3655 | /* Generate the unwind record. */ |
73f20958 | 3656 | list = optimize_unw_records (unwind.list); |
b5e0fabd | 3657 | fixup_unw_records (list, 1); |
73f20958 L |
3658 | size = calc_record_size (list); |
3659 | ||
3660 | if (size > 0 || unwind.force_unwind_entry) | |
3661 | { | |
3662 | unwind.force_unwind_entry = 0; | |
3663 | /* pad to pointer-size boundary. */ | |
3664 | pad = size % md.pointer_size; | |
3665 | if (pad != 0) | |
3666 | size += md.pointer_size - pad; | |
f7e323d5 JB |
3667 | /* Add 8 for the header. */ |
3668 | size += 8; | |
3669 | /* Add a pointer for the personality offset. */ | |
3670 | if (unwind.personality_routine) | |
3671 | size += md.pointer_size; | |
73f20958 | 3672 | } |
6290819d | 3673 | |
800eeca4 JW |
3674 | /* If there are unwind records, switch sections, and output the info. */ |
3675 | if (size != 0) | |
3676 | { | |
800eeca4 | 3677 | expressionS exp; |
1cd8ff38 | 3678 | bfd_reloc_code_real_type reloc; |
91a2ae2a | 3679 | |
da9f89d4 | 3680 | start_unwind_section (text_seg, SPECIAL_SECTION_UNWIND_INFO); |
800eeca4 | 3681 | |
557debba JW |
3682 | /* Make sure the section has 4 byte alignment for ILP32 and |
3683 | 8 byte alignment for LP64. */ | |
3684 | frag_align (md.pointer_size_shift, 0, 0); | |
3685 | record_alignment (now_seg, md.pointer_size_shift); | |
5e7474a7 | 3686 | |
800eeca4 | 3687 | /* Set expression which points to start of unwind descriptor area. */ |
e0c9811a | 3688 | unwind.info = expr_build_dot (); |
3739860c | 3689 | |
73f20958 | 3690 | frag_var (rs_machine_dependent, size, size, 0, 0, |
652ca075 L |
3691 | (offsetT) (long) unwind.personality_routine, |
3692 | (char *) list); | |
91a2ae2a | 3693 | |
800eeca4 | 3694 | /* Add the personality address to the image. */ |
e0c9811a | 3695 | if (unwind.personality_routine != 0) |
542d6675 | 3696 | { |
40449e9f | 3697 | exp.X_op = O_symbol; |
e0c9811a | 3698 | exp.X_add_symbol = unwind.personality_routine; |
800eeca4 | 3699 | exp.X_add_number = 0; |
1cd8ff38 NC |
3700 | |
3701 | if (md.flags & EF_IA_64_BE) | |
3702 | { | |
3703 | if (md.flags & EF_IA_64_ABI64) | |
3704 | reloc = BFD_RELOC_IA64_LTOFF_FPTR64MSB; | |
3705 | else | |
3706 | reloc = BFD_RELOC_IA64_LTOFF_FPTR32MSB; | |
3707 | } | |
40449e9f | 3708 | else |
1cd8ff38 NC |
3709 | { |
3710 | if (md.flags & EF_IA_64_ABI64) | |
3711 | reloc = BFD_RELOC_IA64_LTOFF_FPTR64LSB; | |
3712 | else | |
3713 | reloc = BFD_RELOC_IA64_LTOFF_FPTR32LSB; | |
3714 | } | |
3715 | ||
3716 | fix_new_exp (frag_now, frag_now_fix () - md.pointer_size, | |
40449e9f | 3717 | md.pointer_size, &exp, 0, reloc); |
e0c9811a | 3718 | unwind.personality_routine = 0; |
542d6675 | 3719 | } |
800eeca4 JW |
3720 | } |
3721 | ||
6290819d | 3722 | free_saved_prologue_counts (); |
e0c9811a | 3723 | unwind.list = unwind.tail = unwind.current_entry = NULL; |
800eeca4 JW |
3724 | } |
3725 | ||
197865e8 | 3726 | static void |
5a49b8ac | 3727 | dot_handlerdata (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3728 | { |
75e09913 JB |
3729 | if (!in_procedure ("handlerdata")) |
3730 | return; | |
91a2ae2a RH |
3731 | unwind.force_unwind_entry = 1; |
3732 | ||
3733 | /* Remember which segment we're in so we can switch back after .endp */ | |
3734 | unwind.saved_text_seg = now_seg; | |
3735 | unwind.saved_text_subseg = now_subseg; | |
3736 | ||
3737 | /* Generate unwind info into unwind-info section and then leave that | |
3738 | section as the currently active one so dataXX directives go into | |
3739 | the language specific data area of the unwind info block. */ | |
2d6ed997 | 3740 | generate_unwind_image (now_seg); |
e0c9811a | 3741 | demand_empty_rest_of_line (); |
800eeca4 JW |
3742 | } |
3743 | ||
197865e8 | 3744 | static void |
5a49b8ac | 3745 | dot_unwentry (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3746 | { |
75e09913 JB |
3747 | if (!in_procedure ("unwentry")) |
3748 | return; | |
91a2ae2a | 3749 | unwind.force_unwind_entry = 1; |
e0c9811a | 3750 | demand_empty_rest_of_line (); |
800eeca4 JW |
3751 | } |
3752 | ||
197865e8 | 3753 | static void |
5a49b8ac | 3754 | dot_altrp (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3755 | { |
e0c9811a JW |
3756 | expressionS e; |
3757 | unsigned reg; | |
3758 | ||
75e09913 JB |
3759 | if (!in_prologue ("altrp")) |
3760 | return; | |
3761 | ||
cd42ff9c | 3762 | parse_operand_and_eval (&e, 0); |
e0c9811a | 3763 | reg = e.X_add_number - REG_BR; |
e4e8248d JB |
3764 | if (e.X_op != O_register || reg > 7) |
3765 | { | |
ad4b42b4 | 3766 | as_bad (_("First operand to .altrp not a valid branch register")); |
e4e8248d JB |
3767 | reg = 0; |
3768 | } | |
3769 | add_unwind_entry (output_rp_br (reg), 0); | |
800eeca4 JW |
3770 | } |
3771 | ||
197865e8 | 3772 | static void |
5a49b8ac | 3773 | dot_savemem (int psprel) |
800eeca4 JW |
3774 | { |
3775 | expressionS e1, e2; | |
3776 | int sep; | |
3777 | int reg1, val; | |
e4e8248d | 3778 | const char * const po = psprel ? "savepsp" : "savesp"; |
800eeca4 | 3779 | |
e4e8248d | 3780 | if (!in_prologue (po)) |
75e09913 JB |
3781 | return; |
3782 | ||
cd42ff9c | 3783 | sep = parse_operand_and_eval (&e1, ','); |
e4e8248d | 3784 | if (sep == ',') |
cd42ff9c | 3785 | sep = parse_operand_and_eval (&e2, ','); |
e4e8248d JB |
3786 | else |
3787 | e2.X_op = O_absent; | |
800eeca4 | 3788 | |
e0c9811a | 3789 | reg1 = e1.X_add_number; |
800eeca4 | 3790 | val = e2.X_add_number; |
197865e8 | 3791 | |
800eeca4 | 3792 | /* Make sure its a valid ar.xxx reg, OR its br0, aka 'rp'. */ |
e4e8248d | 3793 | if (e1.X_op != O_register) |
800eeca4 | 3794 | { |
ad4b42b4 | 3795 | as_bad (_("First operand to .%s not a register"), po); |
e4e8248d JB |
3796 | reg1 = REG_PR; /* Anything valid is good here. */ |
3797 | } | |
3798 | if (e2.X_op != O_constant) | |
3799 | { | |
ad4b42b4 | 3800 | as_bad (_("Second operand to .%s not a constant"), po); |
e4e8248d JB |
3801 | val = 0; |
3802 | } | |
3803 | ||
3804 | switch (reg1) | |
3805 | { | |
3806 | case REG_AR + AR_BSP: | |
3807 | add_unwind_entry (output_bsp_when (), sep); | |
3808 | add_unwind_entry ((psprel | |
3809 | ? output_bsp_psprel | |
3810 | : output_bsp_sprel) (val), NOT_A_CHAR); | |
3811 | break; | |
3812 | case REG_AR + AR_BSPSTORE: | |
3813 | add_unwind_entry (output_bspstore_when (), sep); | |
3814 | add_unwind_entry ((psprel | |
3815 | ? output_bspstore_psprel | |
3816 | : output_bspstore_sprel) (val), NOT_A_CHAR); | |
3817 | break; | |
3818 | case REG_AR + AR_RNAT: | |
3819 | add_unwind_entry (output_rnat_when (), sep); | |
3820 | add_unwind_entry ((psprel | |
3821 | ? output_rnat_psprel | |
3822 | : output_rnat_sprel) (val), NOT_A_CHAR); | |
3823 | break; | |
3824 | case REG_AR + AR_UNAT: | |
3825 | add_unwind_entry (output_unat_when (), sep); | |
3826 | add_unwind_entry ((psprel | |
3827 | ? output_unat_psprel | |
3828 | : output_unat_sprel) (val), NOT_A_CHAR); | |
3829 | break; | |
3830 | case REG_AR + AR_FPSR: | |
3831 | add_unwind_entry (output_fpsr_when (), sep); | |
3832 | add_unwind_entry ((psprel | |
3833 | ? output_fpsr_psprel | |
3834 | : output_fpsr_sprel) (val), NOT_A_CHAR); | |
3835 | break; | |
3836 | case REG_AR + AR_PFS: | |
3837 | add_unwind_entry (output_pfs_when (), sep); | |
3838 | add_unwind_entry ((psprel | |
3839 | ? output_pfs_psprel | |
3840 | : output_pfs_sprel) (val), NOT_A_CHAR); | |
3841 | break; | |
3842 | case REG_AR + AR_LC: | |
3843 | add_unwind_entry (output_lc_when (), sep); | |
3844 | add_unwind_entry ((psprel | |
3845 | ? output_lc_psprel | |
3846 | : output_lc_sprel) (val), NOT_A_CHAR); | |
3847 | break; | |
3848 | case REG_BR: | |
3849 | add_unwind_entry (output_rp_when (), sep); | |
3850 | add_unwind_entry ((psprel | |
3851 | ? output_rp_psprel | |
3852 | : output_rp_sprel) (val), NOT_A_CHAR); | |
3853 | break; | |
3854 | case REG_PR: | |
3855 | add_unwind_entry (output_preds_when (), sep); | |
3856 | add_unwind_entry ((psprel | |
3857 | ? output_preds_psprel | |
3858 | : output_preds_sprel) (val), NOT_A_CHAR); | |
3859 | break; | |
3860 | case REG_PRIUNAT: | |
3861 | add_unwind_entry (output_priunat_when_mem (), sep); | |
3862 | add_unwind_entry ((psprel | |
3863 | ? output_priunat_psprel | |
3864 | : output_priunat_sprel) (val), NOT_A_CHAR); | |
3865 | break; | |
3866 | default: | |
ad4b42b4 | 3867 | as_bad (_("First operand to .%s not a valid register"), po); |
e4e8248d JB |
3868 | add_unwind_entry (NULL, sep); |
3869 | break; | |
800eeca4 | 3870 | } |
800eeca4 JW |
3871 | } |
3872 | ||
197865e8 | 3873 | static void |
5a49b8ac | 3874 | dot_saveg (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3875 | { |
e4e8248d JB |
3876 | expressionS e; |
3877 | unsigned grmask; | |
800eeca4 | 3878 | int sep; |
75e09913 JB |
3879 | |
3880 | if (!in_prologue ("save.g")) | |
3881 | return; | |
3882 | ||
cd42ff9c | 3883 | sep = parse_operand_and_eval (&e, ','); |
197865e8 | 3884 | |
e4e8248d JB |
3885 | grmask = e.X_add_number; |
3886 | if (e.X_op != O_constant | |
3887 | || e.X_add_number <= 0 | |
3888 | || e.X_add_number > 0xf) | |
800eeca4 | 3889 | { |
ad4b42b4 | 3890 | as_bad (_("First operand to .save.g must be a positive 4-bit constant")); |
e4e8248d JB |
3891 | grmask = 0; |
3892 | } | |
3893 | ||
3894 | if (sep == ',') | |
3895 | { | |
3896 | unsigned reg; | |
3897 | int n = popcount (grmask); | |
3898 | ||
cd42ff9c | 3899 | parse_operand_and_eval (&e, 0); |
e4e8248d JB |
3900 | reg = e.X_add_number - REG_GR; |
3901 | if (e.X_op != O_register || reg > 127) | |
542d6675 | 3902 | { |
ad4b42b4 | 3903 | as_bad (_("Second operand to .save.g must be a general register")); |
e4e8248d JB |
3904 | reg = 0; |
3905 | } | |
3906 | else if (reg > 128U - n) | |
3907 | { | |
ad4b42b4 | 3908 | as_bad (_("Second operand to .save.g must be the first of %d general registers"), n); |
e4e8248d | 3909 | reg = 0; |
800eeca4 | 3910 | } |
e4e8248d | 3911 | add_unwind_entry (output_gr_gr (grmask, reg), 0); |
800eeca4 | 3912 | } |
e4e8248d JB |
3913 | else |
3914 | add_unwind_entry (output_gr_mem (grmask), 0); | |
800eeca4 JW |
3915 | } |
3916 | ||
197865e8 | 3917 | static void |
5a49b8ac | 3918 | dot_savef (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3919 | { |
e4e8248d | 3920 | expressionS e; |
75e09913 JB |
3921 | |
3922 | if (!in_prologue ("save.f")) | |
3923 | return; | |
3924 | ||
cd42ff9c | 3925 | parse_operand_and_eval (&e, 0); |
197865e8 | 3926 | |
e4e8248d JB |
3927 | if (e.X_op != O_constant |
3928 | || e.X_add_number <= 0 | |
3929 | || e.X_add_number > 0xfffff) | |
3930 | { | |
ad4b42b4 | 3931 | as_bad (_("Operand to .save.f must be a positive 20-bit constant")); |
e4e8248d JB |
3932 | e.X_add_number = 0; |
3933 | } | |
3934 | add_unwind_entry (output_fr_mem (e.X_add_number), 0); | |
800eeca4 JW |
3935 | } |
3936 | ||
197865e8 | 3937 | static void |
5a49b8ac | 3938 | dot_saveb (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 3939 | { |
e4e8248d JB |
3940 | expressionS e; |
3941 | unsigned brmask; | |
3942 | int sep; | |
e0c9811a | 3943 | |
75e09913 JB |
3944 | if (!in_prologue ("save.b")) |
3945 | return; | |
3946 | ||
cd42ff9c | 3947 | sep = parse_operand_and_eval (&e, ','); |
e4e8248d JB |
3948 | |
3949 | brmask = e.X_add_number; | |
3950 | if (e.X_op != O_constant | |
3951 | || e.X_add_number <= 0 | |
3952 | || e.X_add_number > 0x1f) | |
800eeca4 | 3953 | { |
ad4b42b4 | 3954 | as_bad (_("First operand to .save.b must be a positive 5-bit constant")); |
e4e8248d | 3955 | brmask = 0; |
800eeca4 | 3956 | } |
e0c9811a JW |
3957 | |
3958 | if (sep == ',') | |
3959 | { | |
e4e8248d JB |
3960 | unsigned reg; |
3961 | int n = popcount (brmask); | |
3962 | ||
cd42ff9c | 3963 | parse_operand_and_eval (&e, 0); |
e4e8248d JB |
3964 | reg = e.X_add_number - REG_GR; |
3965 | if (e.X_op != O_register || reg > 127) | |
e0c9811a | 3966 | { |
ad4b42b4 | 3967 | as_bad (_("Second operand to .save.b must be a general register")); |
e4e8248d | 3968 | reg = 0; |
e0c9811a | 3969 | } |
e4e8248d JB |
3970 | else if (reg > 128U - n) |
3971 | { | |
ad4b42b4 | 3972 | as_bad (_("Second operand to .save.b must be the first of %d general registers"), n); |
e4e8248d JB |
3973 | reg = 0; |
3974 | } | |
3975 | add_unwind_entry (output_br_gr (brmask, reg), 0); | |
e0c9811a JW |
3976 | } |
3977 | else | |
e4e8248d | 3978 | add_unwind_entry (output_br_mem (brmask), 0); |
800eeca4 JW |
3979 | } |
3980 | ||
197865e8 | 3981 | static void |
5a49b8ac | 3982 | dot_savegf (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
3983 | { |
3984 | expressionS e1, e2; | |
75e09913 JB |
3985 | |
3986 | if (!in_prologue ("save.gf")) | |
3987 | return; | |
3988 | ||
cd42ff9c AM |
3989 | if (parse_operand_and_eval (&e1, ',') == ',') |
3990 | parse_operand_and_eval (&e2, 0); | |
800eeca4 | 3991 | else |
e4e8248d JB |
3992 | e2.X_op = O_absent; |
3993 | ||
3994 | if (e1.X_op != O_constant | |
3995 | || e1.X_add_number < 0 | |
3996 | || e1.X_add_number > 0xf) | |
3997 | { | |
ad4b42b4 | 3998 | as_bad (_("First operand to .save.gf must be a non-negative 4-bit constant")); |
e4e8248d JB |
3999 | e1.X_op = O_absent; |
4000 | e1.X_add_number = 0; | |
4001 | } | |
4002 | if (e2.X_op != O_constant | |
4003 | || e2.X_add_number < 0 | |
4004 | || e2.X_add_number > 0xfffff) | |
800eeca4 | 4005 | { |
ad4b42b4 | 4006 | as_bad (_("Second operand to .save.gf must be a non-negative 20-bit constant")); |
e4e8248d JB |
4007 | e2.X_op = O_absent; |
4008 | e2.X_add_number = 0; | |
800eeca4 | 4009 | } |
e4e8248d JB |
4010 | if (e1.X_op == O_constant |
4011 | && e2.X_op == O_constant | |
4012 | && e1.X_add_number == 0 | |
4013 | && e2.X_add_number == 0) | |
ad4b42b4 | 4014 | as_bad (_("Operands to .save.gf may not be both zero")); |
e4e8248d JB |
4015 | |
4016 | add_unwind_entry (output_frgr_mem (e1.X_add_number, e2.X_add_number), 0); | |
800eeca4 JW |
4017 | } |
4018 | ||
197865e8 | 4019 | static void |
5a49b8ac | 4020 | dot_spill (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4021 | { |
4022 | expressionS e; | |
e0c9811a | 4023 | |
75e09913 JB |
4024 | if (!in_prologue ("spill")) |
4025 | return; | |
4026 | ||
cd42ff9c | 4027 | parse_operand_and_eval (&e, 0); |
197865e8 | 4028 | |
800eeca4 | 4029 | if (e.X_op != O_constant) |
800eeca4 | 4030 | { |
ad4b42b4 | 4031 | as_bad (_("Operand to .spill must be a constant")); |
e4e8248d | 4032 | e.X_add_number = 0; |
e0c9811a | 4033 | } |
e4e8248d | 4034 | add_unwind_entry (output_spill_base (e.X_add_number), 0); |
e0c9811a JW |
4035 | } |
4036 | ||
4037 | static void | |
5a49b8ac | 4038 | dot_spillreg (int pred) |
e0c9811a | 4039 | { |
2132e3a3 | 4040 | int sep; |
e4e8248d JB |
4041 | unsigned int qp, ab, xy, reg, treg; |
4042 | expressionS e; | |
4043 | const char * const po = pred ? "spillreg.p" : "spillreg"; | |
e0c9811a | 4044 | |
e4e8248d | 4045 | if (!in_procedure (po)) |
75e09913 JB |
4046 | return; |
4047 | ||
e4e8248d JB |
4048 | if (pred) |
4049 | sep = parse_predicate_and_operand (&e, &qp, po); | |
e0c9811a | 4050 | else |
e0c9811a | 4051 | { |
cd42ff9c | 4052 | sep = parse_operand_and_eval (&e, ','); |
e4e8248d | 4053 | qp = 0; |
e0c9811a | 4054 | } |
e4e8248d | 4055 | convert_expr_to_ab_reg (&e, &ab, ®, po, 1 + pred); |
e0c9811a | 4056 | |
e4e8248d | 4057 | if (sep == ',') |
cd42ff9c | 4058 | sep = parse_operand_and_eval (&e, ','); |
e4e8248d JB |
4059 | else |
4060 | e.X_op = O_absent; | |
4061 | convert_expr_to_xy_reg (&e, &xy, &treg, po, 2 + pred); | |
e0c9811a | 4062 | |
e4e8248d | 4063 | add_unwind_entry (output_spill_reg (ab, reg, treg, xy, qp), sep); |
e0c9811a JW |
4064 | } |
4065 | ||
4066 | static void | |
5a49b8ac | 4067 | dot_spillmem (int psprel) |
e0c9811a | 4068 | { |
e4e8248d JB |
4069 | expressionS e; |
4070 | int pred = (psprel < 0), sep; | |
4071 | unsigned int qp, ab, reg; | |
4072 | const char * po; | |
e0c9811a | 4073 | |
e4e8248d | 4074 | if (pred) |
e0c9811a | 4075 | { |
e4e8248d JB |
4076 | psprel = ~psprel; |
4077 | po = psprel ? "spillpsp.p" : "spillsp.p"; | |
e0c9811a | 4078 | } |
e4e8248d JB |
4079 | else |
4080 | po = psprel ? "spillpsp" : "spillsp"; | |
e0c9811a | 4081 | |
e4e8248d JB |
4082 | if (!in_procedure (po)) |
4083 | return; | |
e0c9811a | 4084 | |
e4e8248d JB |
4085 | if (pred) |
4086 | sep = parse_predicate_and_operand (&e, &qp, po); | |
4087 | else | |
e0c9811a | 4088 | { |
cd42ff9c | 4089 | sep = parse_operand_and_eval (&e, ','); |
e4e8248d | 4090 | qp = 0; |
e0c9811a | 4091 | } |
e4e8248d | 4092 | convert_expr_to_ab_reg (&e, &ab, ®, po, 1 + pred); |
e0c9811a | 4093 | |
e4e8248d | 4094 | if (sep == ',') |
cd42ff9c | 4095 | sep = parse_operand_and_eval (&e, ','); |
e4e8248d JB |
4096 | else |
4097 | e.X_op = O_absent; | |
4098 | if (e.X_op != O_constant) | |
e0c9811a | 4099 | { |
ad4b42b4 | 4100 | as_bad (_("Operand %d to .%s must be a constant"), 2 + pred, po); |
e4e8248d | 4101 | e.X_add_number = 0; |
e0c9811a JW |
4102 | } |
4103 | ||
4104 | if (psprel) | |
e4e8248d | 4105 | add_unwind_entry (output_spill_psprel (ab, reg, e.X_add_number, qp), sep); |
e0c9811a | 4106 | else |
e4e8248d | 4107 | add_unwind_entry (output_spill_sprel (ab, reg, e.X_add_number, qp), sep); |
e0c9811a JW |
4108 | } |
4109 | ||
6290819d | 4110 | static unsigned int |
5a49b8ac | 4111 | get_saved_prologue_count (unsigned long lbl) |
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 | return lpc->prologue_count; | |
4120 | ||
ad4b42b4 | 4121 | as_bad (_("Missing .label_state %ld"), lbl); |
6290819d NC |
4122 | return 1; |
4123 | } | |
4124 | ||
4125 | static void | |
5a49b8ac | 4126 | save_prologue_count (unsigned long lbl, unsigned int count) |
6290819d NC |
4127 | { |
4128 | label_prologue_count *lpc = unwind.saved_prologue_counts; | |
4129 | ||
4130 | while (lpc != NULL && lpc->label_number != lbl) | |
4131 | lpc = lpc->next; | |
4132 | ||
4133 | if (lpc != NULL) | |
4134 | lpc->prologue_count = count; | |
4135 | else | |
4136 | { | |
40449e9f | 4137 | label_prologue_count *new_lpc = xmalloc (sizeof (* new_lpc)); |
6290819d NC |
4138 | |
4139 | new_lpc->next = unwind.saved_prologue_counts; | |
4140 | new_lpc->label_number = lbl; | |
4141 | new_lpc->prologue_count = count; | |
4142 | unwind.saved_prologue_counts = new_lpc; | |
4143 | } | |
4144 | } | |
4145 | ||
4146 | static void | |
4147 | free_saved_prologue_counts () | |
4148 | { | |
40449e9f KH |
4149 | label_prologue_count *lpc = unwind.saved_prologue_counts; |
4150 | label_prologue_count *next; | |
6290819d NC |
4151 | |
4152 | while (lpc != NULL) | |
4153 | { | |
4154 | next = lpc->next; | |
4155 | free (lpc); | |
4156 | lpc = next; | |
4157 | } | |
4158 | ||
4159 | unwind.saved_prologue_counts = NULL; | |
4160 | } | |
4161 | ||
e0c9811a | 4162 | static void |
5a49b8ac | 4163 | dot_label_state (int dummy ATTRIBUTE_UNUSED) |
e0c9811a JW |
4164 | { |
4165 | expressionS e; | |
4166 | ||
75e09913 JB |
4167 | if (!in_body ("label_state")) |
4168 | return; | |
4169 | ||
cd42ff9c | 4170 | parse_operand_and_eval (&e, 0); |
e4e8248d JB |
4171 | if (e.X_op == O_constant) |
4172 | save_prologue_count (e.X_add_number, unwind.prologue_count); | |
4173 | else | |
e0c9811a | 4174 | { |
ad4b42b4 | 4175 | as_bad (_("Operand to .label_state must be a constant")); |
e4e8248d | 4176 | e.X_add_number = 0; |
e0c9811a | 4177 | } |
e4e8248d | 4178 | add_unwind_entry (output_label_state (e.X_add_number), 0); |
e0c9811a JW |
4179 | } |
4180 | ||
4181 | static void | |
5a49b8ac | 4182 | dot_copy_state (int dummy ATTRIBUTE_UNUSED) |
e0c9811a JW |
4183 | { |
4184 | expressionS e; | |
4185 | ||
75e09913 JB |
4186 | if (!in_body ("copy_state")) |
4187 | return; | |
4188 | ||
cd42ff9c | 4189 | parse_operand_and_eval (&e, 0); |
e4e8248d JB |
4190 | if (e.X_op == O_constant) |
4191 | unwind.prologue_count = get_saved_prologue_count (e.X_add_number); | |
4192 | else | |
e0c9811a | 4193 | { |
ad4b42b4 | 4194 | as_bad (_("Operand to .copy_state must be a constant")); |
e4e8248d | 4195 | e.X_add_number = 0; |
e0c9811a | 4196 | } |
e4e8248d | 4197 | add_unwind_entry (output_copy_state (e.X_add_number), 0); |
800eeca4 JW |
4198 | } |
4199 | ||
197865e8 | 4200 | static void |
5a49b8ac | 4201 | dot_unwabi (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 4202 | { |
e0c9811a JW |
4203 | expressionS e1, e2; |
4204 | unsigned char sep; | |
4205 | ||
e4e8248d | 4206 | if (!in_prologue ("unwabi")) |
75e09913 JB |
4207 | return; |
4208 | ||
cd42ff9c | 4209 | sep = parse_operand_and_eval (&e1, ','); |
e4e8248d | 4210 | if (sep == ',') |
cd42ff9c | 4211 | parse_operand_and_eval (&e2, 0); |
e4e8248d JB |
4212 | else |
4213 | e2.X_op = O_absent; | |
e0c9811a JW |
4214 | |
4215 | if (e1.X_op != O_constant) | |
4216 | { | |
ad4b42b4 | 4217 | as_bad (_("First operand to .unwabi must be a constant")); |
e4e8248d | 4218 | e1.X_add_number = 0; |
e0c9811a JW |
4219 | } |
4220 | ||
4221 | if (e2.X_op != O_constant) | |
4222 | { | |
ad4b42b4 | 4223 | as_bad (_("Second operand to .unwabi must be a constant")); |
e4e8248d | 4224 | e2.X_add_number = 0; |
e0c9811a JW |
4225 | } |
4226 | ||
e4e8248d | 4227 | add_unwind_entry (output_unwabi (e1.X_add_number, e2.X_add_number), 0); |
800eeca4 JW |
4228 | } |
4229 | ||
197865e8 | 4230 | static void |
5a49b8ac | 4231 | dot_personality (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4232 | { |
4233 | char *name, *p, c; | |
d02603dc | 4234 | |
75e09913 JB |
4235 | if (!in_procedure ("personality")) |
4236 | return; | |
800eeca4 | 4237 | SKIP_WHITESPACE (); |
d02603dc | 4238 | c = get_symbol_name (&name); |
800eeca4 | 4239 | p = input_line_pointer; |
e0c9811a | 4240 | unwind.personality_routine = symbol_find_or_make (name); |
91a2ae2a | 4241 | unwind.force_unwind_entry = 1; |
800eeca4 | 4242 | *p = c; |
d02603dc | 4243 | SKIP_WHITESPACE_AFTER_NAME (); |
800eeca4 JW |
4244 | demand_empty_rest_of_line (); |
4245 | } | |
4246 | ||
4247 | static void | |
5a49b8ac | 4248 | dot_proc (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4249 | { |
4250 | char *name, *p, c; | |
4251 | symbolS *sym; | |
5656b6b8 JB |
4252 | proc_pending *pending, *last_pending; |
4253 | ||
4254 | if (unwind.proc_pending.sym) | |
4255 | { | |
4256 | (md.unwind_check == unwind_check_warning | |
4257 | ? as_warn | |
ad4b42b4 | 4258 | : as_bad) (_("Missing .endp after previous .proc")); |
5656b6b8 JB |
4259 | while (unwind.proc_pending.next) |
4260 | { | |
4261 | pending = unwind.proc_pending.next; | |
4262 | unwind.proc_pending.next = pending->next; | |
4263 | free (pending); | |
4264 | } | |
4265 | } | |
4266 | last_pending = NULL; | |
800eeca4 | 4267 | |
e0c9811a | 4268 | /* Parse names of main and alternate entry points and mark them as |
542d6675 | 4269 | function symbols: */ |
800eeca4 JW |
4270 | while (1) |
4271 | { | |
4272 | SKIP_WHITESPACE (); | |
d02603dc | 4273 | c = get_symbol_name (&name); |
800eeca4 | 4274 | p = input_line_pointer; |
75e09913 | 4275 | if (!*name) |
ad4b42b4 | 4276 | as_bad (_("Empty argument of .proc")); |
75e09913 | 4277 | else |
542d6675 | 4278 | { |
75e09913 JB |
4279 | sym = symbol_find_or_make (name); |
4280 | if (S_IS_DEFINED (sym)) | |
ad4b42b4 | 4281 | as_bad (_("`%s' was already defined"), name); |
5656b6b8 JB |
4282 | else if (!last_pending) |
4283 | { | |
4284 | unwind.proc_pending.sym = sym; | |
4285 | last_pending = &unwind.proc_pending; | |
4286 | } | |
4287 | else | |
75e09913 | 4288 | { |
5656b6b8 JB |
4289 | pending = xmalloc (sizeof (*pending)); |
4290 | pending->sym = sym; | |
4291 | last_pending = last_pending->next = pending; | |
75e09913 JB |
4292 | } |
4293 | symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION; | |
800eeca4 | 4294 | } |
800eeca4 | 4295 | *p = c; |
d02603dc | 4296 | SKIP_WHITESPACE_AFTER_NAME (); |
800eeca4 JW |
4297 | if (*input_line_pointer != ',') |
4298 | break; | |
4299 | ++input_line_pointer; | |
4300 | } | |
5656b6b8 JB |
4301 | if (!last_pending) |
4302 | { | |
4303 | unwind.proc_pending.sym = expr_build_dot (); | |
4304 | last_pending = &unwind.proc_pending; | |
4305 | } | |
4306 | last_pending->next = NULL; | |
800eeca4 JW |
4307 | demand_empty_rest_of_line (); |
4308 | ia64_do_align (16); | |
4309 | ||
75e09913 | 4310 | unwind.prologue = 0; |
33d01f33 | 4311 | unwind.prologue_count = 0; |
75e09913 JB |
4312 | unwind.body = 0; |
4313 | unwind.insn = 0; | |
e0c9811a JW |
4314 | unwind.list = unwind.tail = unwind.current_entry = NULL; |
4315 | unwind.personality_routine = 0; | |
800eeca4 JW |
4316 | } |
4317 | ||
4318 | static void | |
5a49b8ac | 4319 | dot_body (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 4320 | { |
75e09913 JB |
4321 | if (!in_procedure ("body")) |
4322 | return; | |
4323 | if (!unwind.prologue && !unwind.body && unwind.insn) | |
ad4b42b4 | 4324 | as_warn (_("Initial .body should precede any instructions")); |
ba825241 | 4325 | check_pending_save (); |
75e09913 | 4326 | |
e0c9811a | 4327 | unwind.prologue = 0; |
30d25259 | 4328 | unwind.prologue_mask = 0; |
75e09913 | 4329 | unwind.body = 1; |
30d25259 | 4330 | |
e4e8248d | 4331 | add_unwind_entry (output_body (), 0); |
800eeca4 JW |
4332 | } |
4333 | ||
4334 | static void | |
5a49b8ac | 4335 | dot_prologue (int dummy ATTRIBUTE_UNUSED) |
800eeca4 | 4336 | { |
e4e8248d | 4337 | unsigned mask = 0, grsave = 0; |
e0c9811a | 4338 | |
75e09913 JB |
4339 | if (!in_procedure ("prologue")) |
4340 | return; | |
4341 | if (unwind.prologue) | |
4342 | { | |
ad4b42b4 | 4343 | as_bad (_(".prologue within prologue")); |
75e09913 JB |
4344 | ignore_rest_of_line (); |
4345 | return; | |
4346 | } | |
4347 | if (!unwind.body && unwind.insn) | |
ad4b42b4 | 4348 | as_warn (_("Initial .prologue should precede any instructions")); |
75e09913 | 4349 | |
e0c9811a | 4350 | if (!is_it_end_of_statement ()) |
800eeca4 | 4351 | { |
e4e8248d | 4352 | expressionS e; |
cd42ff9c | 4353 | int n, sep = parse_operand_and_eval (&e, ','); |
30d25259 | 4354 | |
e4e8248d JB |
4355 | if (e.X_op != O_constant |
4356 | || e.X_add_number < 0 | |
4357 | || e.X_add_number > 0xf) | |
ad4b42b4 | 4358 | as_bad (_("First operand to .prologue must be a positive 4-bit constant")); |
e4e8248d | 4359 | else if (e.X_add_number == 0) |
ad4b42b4 | 4360 | as_warn (_("Pointless use of zero first operand to .prologue")); |
e4e8248d JB |
4361 | else |
4362 | mask = e.X_add_number; | |
4363 | n = popcount (mask); | |
30d25259 | 4364 | |
e4e8248d | 4365 | if (sep == ',') |
cd42ff9c | 4366 | parse_operand_and_eval (&e, 0); |
800eeca4 | 4367 | else |
e4e8248d JB |
4368 | e.X_op = O_absent; |
4369 | if (e.X_op == O_constant | |
4370 | && e.X_add_number >= 0 | |
4371 | && e.X_add_number < 128) | |
4372 | { | |
4373 | if (md.unwind_check == unwind_check_error) | |
ad4b42b4 | 4374 | as_warn (_("Using a constant as second operand to .prologue is deprecated")); |
e4e8248d JB |
4375 | grsave = e.X_add_number; |
4376 | } | |
4377 | else if (e.X_op != O_register | |
4378 | || (grsave = e.X_add_number - REG_GR) > 127) | |
4379 | { | |
ad4b42b4 | 4380 | as_bad (_("Second operand to .prologue must be a general register")); |
e4e8248d JB |
4381 | grsave = 0; |
4382 | } | |
4383 | else if (grsave > 128U - n) | |
4384 | { | |
ad4b42b4 | 4385 | as_bad (_("Second operand to .prologue must be the first of %d general registers"), n); |
e4e8248d JB |
4386 | grsave = 0; |
4387 | } | |
4388 | ||
800eeca4 | 4389 | } |
e4e8248d JB |
4390 | |
4391 | if (mask) | |
4392 | add_unwind_entry (output_prologue_gr (mask, grsave), 0); | |
800eeca4 | 4393 | else |
e4e8248d | 4394 | add_unwind_entry (output_prologue (), 0); |
30d25259 RH |
4395 | |
4396 | unwind.prologue = 1; | |
4397 | unwind.prologue_mask = mask; | |
e4e8248d | 4398 | unwind.prologue_gr = grsave; |
75e09913 | 4399 | unwind.body = 0; |
33d01f33 | 4400 | ++unwind.prologue_count; |
800eeca4 JW |
4401 | } |
4402 | ||
4403 | static void | |
5a49b8ac | 4404 | dot_endp (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4405 | { |
4406 | expressionS e; | |
44f5c83a | 4407 | int bytes_per_address; |
800eeca4 JW |
4408 | long where; |
4409 | segT saved_seg; | |
4410 | subsegT saved_subseg; | |
5656b6b8 | 4411 | proc_pending *pending; |
970d6792 | 4412 | int unwind_check = md.unwind_check; |
800eeca4 | 4413 | |
970d6792 | 4414 | md.unwind_check = unwind_check_error; |
75e09913 JB |
4415 | if (!in_procedure ("endp")) |
4416 | return; | |
970d6792 | 4417 | md.unwind_check = unwind_check; |
75e09913 | 4418 | |
91a2ae2a RH |
4419 | if (unwind.saved_text_seg) |
4420 | { | |
4421 | saved_seg = unwind.saved_text_seg; | |
4422 | saved_subseg = unwind.saved_text_subseg; | |
4423 | unwind.saved_text_seg = NULL; | |
4424 | } | |
4425 | else | |
4426 | { | |
4427 | saved_seg = now_seg; | |
4428 | saved_subseg = now_subseg; | |
4429 | } | |
4430 | ||
800eeca4 | 4431 | insn_group_break (1, 0, 0); |
800eeca4 | 4432 | |
91a2ae2a RH |
4433 | /* If there wasn't a .handlerdata, we haven't generated an image yet. */ |
4434 | if (!unwind.info) | |
2d6ed997 | 4435 | generate_unwind_image (saved_seg); |
800eeca4 | 4436 | |
91a2ae2a RH |
4437 | if (unwind.info || unwind.force_unwind_entry) |
4438 | { | |
75e09913 JB |
4439 | symbolS *proc_end; |
4440 | ||
91a2ae2a | 4441 | subseg_set (md.last_text_seg, 0); |
75e09913 | 4442 | proc_end = expr_build_dot (); |
5e7474a7 | 4443 | |
da9f89d4 | 4444 | start_unwind_section (saved_seg, SPECIAL_SECTION_UNWIND); |
5e7474a7 | 4445 | |
557debba JW |
4446 | /* Make sure that section has 4 byte alignment for ILP32 and |
4447 | 8 byte alignment for LP64. */ | |
4448 | record_alignment (now_seg, md.pointer_size_shift); | |
800eeca4 | 4449 | |
557debba JW |
4450 | /* Need space for 3 pointers for procedure start, procedure end, |
4451 | and unwind info. */ | |
6baf2b51 | 4452 | memset (frag_more (3 * md.pointer_size), 0, 3 * md.pointer_size); |
557debba | 4453 | where = frag_now_fix () - (3 * md.pointer_size); |
91a2ae2a | 4454 | bytes_per_address = bfd_arch_bits_per_address (stdoutput) / 8; |
800eeca4 | 4455 | |
40449e9f | 4456 | /* Issue the values of a) Proc Begin, b) Proc End, c) Unwind Record. */ |
91a2ae2a RH |
4457 | e.X_op = O_pseudo_fixup; |
4458 | e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym; | |
4459 | e.X_add_number = 0; | |
5656b6b8 JB |
4460 | if (!S_IS_LOCAL (unwind.proc_pending.sym) |
4461 | && S_IS_DEFINED (unwind.proc_pending.sym)) | |
4462 | e.X_add_symbol = symbol_temp_new (S_GET_SEGMENT (unwind.proc_pending.sym), | |
4463 | S_GET_VALUE (unwind.proc_pending.sym), | |
4464 | symbol_get_frag (unwind.proc_pending.sym)); | |
4600db48 | 4465 | else |
5656b6b8 | 4466 | e.X_add_symbol = unwind.proc_pending.sym; |
62ebcb5c AM |
4467 | ia64_cons_fix_new (frag_now, where, bytes_per_address, &e, |
4468 | BFD_RELOC_NONE); | |
800eeca4 | 4469 | |
800eeca4 JW |
4470 | e.X_op = O_pseudo_fixup; |
4471 | e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym; | |
4472 | e.X_add_number = 0; | |
75e09913 | 4473 | e.X_add_symbol = proc_end; |
91a2ae2a | 4474 | ia64_cons_fix_new (frag_now, where + bytes_per_address, |
62ebcb5c | 4475 | bytes_per_address, &e, BFD_RELOC_NONE); |
91a2ae2a RH |
4476 | |
4477 | if (unwind.info) | |
4478 | { | |
4479 | e.X_op = O_pseudo_fixup; | |
4480 | e.X_op_symbol = pseudo_func[FUNC_SEG_RELATIVE].u.sym; | |
4481 | e.X_add_number = 0; | |
4482 | e.X_add_symbol = unwind.info; | |
4483 | ia64_cons_fix_new (frag_now, where + (bytes_per_address * 2), | |
62ebcb5c | 4484 | bytes_per_address, &e, BFD_RELOC_NONE); |
91a2ae2a | 4485 | } |
91a2ae2a | 4486 | } |
800eeca4 | 4487 | subseg_set (saved_seg, saved_subseg); |
c538998c | 4488 | |
5656b6b8 JB |
4489 | /* Set symbol sizes. */ |
4490 | pending = &unwind.proc_pending; | |
4491 | if (S_GET_NAME (pending->sym)) | |
c538998c | 4492 | { |
5656b6b8 | 4493 | do |
75e09913 | 4494 | { |
5656b6b8 JB |
4495 | symbolS *sym = pending->sym; |
4496 | ||
4497 | if (!S_IS_DEFINED (sym)) | |
ad4b42b4 | 4498 | as_bad (_("`%s' was not defined within procedure"), S_GET_NAME (sym)); |
5656b6b8 JB |
4499 | else if (S_GET_SIZE (sym) == 0 |
4500 | && symbol_get_obj (sym)->size == NULL) | |
75e09913 | 4501 | { |
75e09913 JB |
4502 | fragS *frag = symbol_get_frag (sym); |
4503 | ||
5656b6b8 | 4504 | if (frag) |
c538998c | 4505 | { |
75e09913 JB |
4506 | if (frag == frag_now && SEG_NORMAL (now_seg)) |
4507 | S_SET_SIZE (sym, frag_now_fix () - S_GET_VALUE (sym)); | |
4508 | else | |
4509 | { | |
4510 | symbol_get_obj (sym)->size = | |
4511 | (expressionS *) xmalloc (sizeof (expressionS)); | |
4512 | symbol_get_obj (sym)->size->X_op = O_subtract; | |
4513 | symbol_get_obj (sym)->size->X_add_symbol | |
4514 | = symbol_new (FAKE_LABEL_NAME, now_seg, | |
4515 | frag_now_fix (), frag_now); | |
4516 | symbol_get_obj (sym)->size->X_op_symbol = sym; | |
4517 | symbol_get_obj (sym)->size->X_add_number = 0; | |
4518 | } | |
c538998c JJ |
4519 | } |
4520 | } | |
5656b6b8 JB |
4521 | } while ((pending = pending->next) != NULL); |
4522 | } | |
4523 | ||
4524 | /* Parse names of main and alternate entry points. */ | |
4525 | while (1) | |
4526 | { | |
4527 | char *name, *p, c; | |
4528 | ||
4529 | SKIP_WHITESPACE (); | |
d02603dc | 4530 | c = get_symbol_name (&name); |
5656b6b8 JB |
4531 | p = input_line_pointer; |
4532 | if (!*name) | |
4533 | (md.unwind_check == unwind_check_warning | |
4534 | ? as_warn | |
ad4b42b4 | 4535 | : as_bad) (_("Empty argument of .endp")); |
5656b6b8 JB |
4536 | else |
4537 | { | |
4538 | symbolS *sym = symbol_find (name); | |
4539 | ||
4540 | for (pending = &unwind.proc_pending; pending; pending = pending->next) | |
4541 | { | |
4542 | if (sym == pending->sym) | |
4543 | { | |
4544 | pending->sym = NULL; | |
4545 | break; | |
4546 | } | |
4547 | } | |
4548 | if (!sym || !pending) | |
ad4b42b4 | 4549 | as_warn (_("`%s' was not specified with previous .proc"), name); |
c538998c JJ |
4550 | } |
4551 | *p = c; | |
d02603dc | 4552 | SKIP_WHITESPACE_AFTER_NAME (); |
c538998c JJ |
4553 | if (*input_line_pointer != ',') |
4554 | break; | |
4555 | ++input_line_pointer; | |
4556 | } | |
4557 | demand_empty_rest_of_line (); | |
5656b6b8 JB |
4558 | |
4559 | /* Deliberately only checking for the main entry point here; the | |
4560 | language spec even says all arguments to .endp are ignored. */ | |
4561 | if (unwind.proc_pending.sym | |
4562 | && S_GET_NAME (unwind.proc_pending.sym) | |
4563 | && strcmp (S_GET_NAME (unwind.proc_pending.sym), FAKE_LABEL_NAME)) | |
ad4b42b4 | 4564 | as_warn (_("`%s' should be an operand to this .endp"), |
5656b6b8 JB |
4565 | S_GET_NAME (unwind.proc_pending.sym)); |
4566 | while (unwind.proc_pending.next) | |
4567 | { | |
4568 | pending = unwind.proc_pending.next; | |
4569 | unwind.proc_pending.next = pending->next; | |
4570 | free (pending); | |
4571 | } | |
4572 | unwind.proc_pending.sym = unwind.info = NULL; | |
800eeca4 JW |
4573 | } |
4574 | ||
4575 | static void | |
d3ce72d0 | 4576 | dot_template (int template_val) |
800eeca4 | 4577 | { |
d3ce72d0 | 4578 | CURR_SLOT.user_template = template_val; |
800eeca4 JW |
4579 | } |
4580 | ||
4581 | static void | |
5a49b8ac | 4582 | dot_regstk (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4583 | { |
4584 | int ins, locs, outs, rots; | |
4585 | ||
4586 | if (is_it_end_of_statement ()) | |
4587 | ins = locs = outs = rots = 0; | |
4588 | else | |
4589 | { | |
4590 | ins = get_absolute_expression (); | |
4591 | if (*input_line_pointer++ != ',') | |
4592 | goto err; | |
4593 | locs = get_absolute_expression (); | |
4594 | if (*input_line_pointer++ != ',') | |
4595 | goto err; | |
4596 | outs = get_absolute_expression (); | |
4597 | if (*input_line_pointer++ != ',') | |
4598 | goto err; | |
4599 | rots = get_absolute_expression (); | |
4600 | } | |
4601 | set_regstack (ins, locs, outs, rots); | |
4602 | return; | |
4603 | ||
4604 | err: | |
ad4b42b4 | 4605 | as_bad (_("Comma expected")); |
800eeca4 JW |
4606 | ignore_rest_of_line (); |
4607 | } | |
4608 | ||
4609 | static void | |
5a49b8ac | 4610 | dot_rot (int type) |
800eeca4 | 4611 | { |
6a2375c6 JB |
4612 | offsetT num_regs; |
4613 | valueT num_alloced = 0; | |
800eeca4 JW |
4614 | struct dynreg **drpp, *dr; |
4615 | int ch, base_reg = 0; | |
4616 | char *name, *start; | |
4617 | size_t len; | |
4618 | ||
4619 | switch (type) | |
4620 | { | |
4621 | case DYNREG_GR: base_reg = REG_GR + 32; break; | |
4622 | case DYNREG_FR: base_reg = REG_FR + 32; break; | |
4623 | case DYNREG_PR: base_reg = REG_P + 16; break; | |
4624 | default: break; | |
4625 | } | |
4626 | ||
542d6675 | 4627 | /* First, remove existing names from hash table. */ |
800eeca4 JW |
4628 | for (dr = md.dynreg[type]; dr && dr->num_regs; dr = dr->next) |
4629 | { | |
db0bc284 | 4630 | hash_delete (md.dynreg_hash, dr->name, FALSE); |
20b36a95 | 4631 | /* FIXME: Free dr->name. */ |
800eeca4 JW |
4632 | dr->num_regs = 0; |
4633 | } | |
4634 | ||
4635 | drpp = &md.dynreg[type]; | |
4636 | while (1) | |
4637 | { | |
d02603dc | 4638 | ch = get_symbol_name (&start); |
20b36a95 | 4639 | len = strlen (ia64_canonicalize_symbol_name (start)); |
800eeca4 | 4640 | *input_line_pointer = ch; |
800eeca4 | 4641 | |
d02603dc | 4642 | SKIP_WHITESPACE_AFTER_NAME (); |
800eeca4 JW |
4643 | if (*input_line_pointer != '[') |
4644 | { | |
ad4b42b4 | 4645 | as_bad (_("Expected '['")); |
800eeca4 JW |
4646 | goto err; |
4647 | } | |
4648 | ++input_line_pointer; /* skip '[' */ | |
4649 | ||
4650 | num_regs = get_absolute_expression (); | |
4651 | ||
4652 | if (*input_line_pointer++ != ']') | |
4653 | { | |
ad4b42b4 | 4654 | as_bad (_("Expected ']'")); |
800eeca4 JW |
4655 | goto err; |
4656 | } | |
6a2375c6 JB |
4657 | if (num_regs <= 0) |
4658 | { | |
ad4b42b4 | 4659 | as_bad (_("Number of elements must be positive")); |
6a2375c6 JB |
4660 | goto err; |
4661 | } | |
800eeca4 JW |
4662 | SKIP_WHITESPACE (); |
4663 | ||
4664 | num_alloced += num_regs; | |
4665 | switch (type) | |
4666 | { | |
4667 | case DYNREG_GR: | |
4668 | if (num_alloced > md.rot.num_regs) | |
4669 | { | |
ad4b42b4 | 4670 | as_bad (_("Used more than the declared %d rotating registers"), |
800eeca4 JW |
4671 | md.rot.num_regs); |
4672 | goto err; | |
4673 | } | |
4674 | break; | |
4675 | case DYNREG_FR: | |
4676 | if (num_alloced > 96) | |
4677 | { | |
ad4b42b4 | 4678 | as_bad (_("Used more than the available 96 rotating registers")); |
800eeca4 JW |
4679 | goto err; |
4680 | } | |
4681 | break; | |
4682 | case DYNREG_PR: | |
4683 | if (num_alloced > 48) | |
4684 | { | |
ad4b42b4 | 4685 | as_bad (_("Used more than the available 48 rotating registers")); |
800eeca4 JW |
4686 | goto err; |
4687 | } | |
4688 | break; | |
4689 | ||
4690 | default: | |
4691 | break; | |
4692 | } | |
4693 | ||
800eeca4 JW |
4694 | if (!*drpp) |
4695 | { | |
4696 | *drpp = obstack_alloc (¬es, sizeof (*dr)); | |
4697 | memset (*drpp, 0, sizeof (*dr)); | |
4698 | } | |
4699 | ||
20b36a95 JB |
4700 | name = obstack_alloc (¬es, len + 1); |
4701 | memcpy (name, start, len); | |
4702 | name[len] = '\0'; | |
4703 | ||
800eeca4 JW |
4704 | dr = *drpp; |
4705 | dr->name = name; | |
4706 | dr->num_regs = num_regs; | |
4707 | dr->base = base_reg; | |
4708 | drpp = &dr->next; | |
4709 | base_reg += num_regs; | |
4710 | ||
4711 | if (hash_insert (md.dynreg_hash, name, dr)) | |
4712 | { | |
ad4b42b4 | 4713 | as_bad (_("Attempt to redefine register set `%s'"), name); |
20b36a95 | 4714 | obstack_free (¬es, name); |
800eeca4 JW |
4715 | goto err; |
4716 | } | |
4717 | ||
4718 | if (*input_line_pointer != ',') | |
4719 | break; | |
4720 | ++input_line_pointer; /* skip comma */ | |
4721 | SKIP_WHITESPACE (); | |
4722 | } | |
4723 | demand_empty_rest_of_line (); | |
4724 | return; | |
4725 | ||
4726 | err: | |
4727 | ignore_rest_of_line (); | |
4728 | } | |
4729 | ||
4730 | static void | |
5a49b8ac | 4731 | dot_byteorder (int byteorder) |
800eeca4 | 4732 | { |
10a98291 L |
4733 | segment_info_type *seginfo = seg_info (now_seg); |
4734 | ||
4735 | if (byteorder == -1) | |
4736 | { | |
4737 | if (seginfo->tc_segment_info_data.endian == 0) | |
549f748d | 4738 | seginfo->tc_segment_info_data.endian = default_big_endian ? 1 : 2; |
10a98291 L |
4739 | byteorder = seginfo->tc_segment_info_data.endian == 1; |
4740 | } | |
4741 | else | |
4742 | seginfo->tc_segment_info_data.endian = byteorder ? 1 : 2; | |
4743 | ||
4744 | if (target_big_endian != byteorder) | |
4745 | { | |
4746 | target_big_endian = byteorder; | |
4747 | if (target_big_endian) | |
4748 | { | |
4749 | ia64_number_to_chars = number_to_chars_bigendian; | |
4750 | ia64_float_to_chars = ia64_float_to_chars_bigendian; | |
4751 | } | |
4752 | else | |
4753 | { | |
4754 | ia64_number_to_chars = number_to_chars_littleendian; | |
4755 | ia64_float_to_chars = ia64_float_to_chars_littleendian; | |
4756 | } | |
4757 | } | |
800eeca4 JW |
4758 | } |
4759 | ||
4760 | static void | |
5a49b8ac | 4761 | dot_psr (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4762 | { |
4763 | char *option; | |
4764 | int ch; | |
4765 | ||
4766 | while (1) | |
4767 | { | |
d02603dc | 4768 | ch = get_symbol_name (&option); |
800eeca4 JW |
4769 | if (strcmp (option, "lsb") == 0) |
4770 | md.flags &= ~EF_IA_64_BE; | |
4771 | else if (strcmp (option, "msb") == 0) | |
4772 | md.flags |= EF_IA_64_BE; | |
4773 | else if (strcmp (option, "abi32") == 0) | |
4774 | md.flags &= ~EF_IA_64_ABI64; | |
4775 | else if (strcmp (option, "abi64") == 0) | |
4776 | md.flags |= EF_IA_64_ABI64; | |
4777 | else | |
ad4b42b4 | 4778 | as_bad (_("Unknown psr option `%s'"), option); |
800eeca4 JW |
4779 | *input_line_pointer = ch; |
4780 | ||
d02603dc | 4781 | SKIP_WHITESPACE_AFTER_NAME (); |
800eeca4 JW |
4782 | if (*input_line_pointer != ',') |
4783 | break; | |
4784 | ||
4785 | ++input_line_pointer; | |
4786 | SKIP_WHITESPACE (); | |
4787 | } | |
4788 | demand_empty_rest_of_line (); | |
4789 | } | |
4790 | ||
800eeca4 | 4791 | static void |
5a49b8ac | 4792 | dot_ln (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4793 | { |
4794 | new_logical_line (0, get_absolute_expression ()); | |
4795 | demand_empty_rest_of_line (); | |
4796 | } | |
4797 | ||
ef6a2b41 | 4798 | static void |
91d6fa6a | 4799 | cross_section (int ref, void (*builder) (int), int ua) |
800eeca4 | 4800 | { |
ef6a2b41 JB |
4801 | char *start, *end; |
4802 | int saved_auto_align; | |
4803 | unsigned int section_count; | |
d02603dc NC |
4804 | char *name; |
4805 | char c; | |
800eeca4 JW |
4806 | |
4807 | SKIP_WHITESPACE (); | |
ef6a2b41 | 4808 | start = input_line_pointer; |
d02603dc NC |
4809 | c = get_symbol_name (&name); |
4810 | if (input_line_pointer == start) | |
800eeca4 | 4811 | { |
d02603dc NC |
4812 | as_bad (_("Missing section name")); |
4813 | ignore_rest_of_line (); | |
4814 | return; | |
800eeca4 | 4815 | } |
d02603dc NC |
4816 | * input_line_pointer = c; |
4817 | SKIP_WHITESPACE_AFTER_NAME (); | |
ef6a2b41 | 4818 | end = input_line_pointer; |
800eeca4 JW |
4819 | if (*input_line_pointer != ',') |
4820 | { | |
ad4b42b4 | 4821 | as_bad (_("Comma expected after section name")); |
800eeca4 | 4822 | ignore_rest_of_line (); |
ef6a2b41 | 4823 | return; |
800eeca4 | 4824 | } |
ef6a2b41 JB |
4825 | *end = '\0'; |
4826 | end = input_line_pointer + 1; /* skip comma */ | |
4827 | input_line_pointer = start; | |
4828 | md.keep_pending_output = 1; | |
91d6fa6a | 4829 | section_count = bfd_count_sections (stdoutput); |
ef6a2b41 | 4830 | obj_elf_section (0); |
91d6fa6a | 4831 | if (section_count != bfd_count_sections (stdoutput)) |
ad4b42b4 | 4832 | as_warn (_("Creating sections with .xdataN/.xrealN/.xstringZ is deprecated.")); |
ef6a2b41 JB |
4833 | input_line_pointer = end; |
4834 | saved_auto_align = md.auto_align; | |
4835 | if (ua) | |
4836 | md.auto_align = 0; | |
91d6fa6a | 4837 | (*builder) (ref); |
ef6a2b41 JB |
4838 | if (ua) |
4839 | md.auto_align = saved_auto_align; | |
4840 | obj_elf_previous (0); | |
4841 | md.keep_pending_output = 0; | |
800eeca4 JW |
4842 | } |
4843 | ||
4844 | static void | |
5a49b8ac | 4845 | dot_xdata (int size) |
800eeca4 | 4846 | { |
ef6a2b41 | 4847 | cross_section (size, cons, 0); |
800eeca4 JW |
4848 | } |
4849 | ||
4850 | /* Why doesn't float_cons() call md_cons_align() the way cons() does? */ | |
542d6675 | 4851 | |
800eeca4 | 4852 | static void |
5a49b8ac | 4853 | stmt_float_cons (int kind) |
800eeca4 | 4854 | { |
165a7f90 | 4855 | size_t alignment; |
800eeca4 JW |
4856 | |
4857 | switch (kind) | |
4858 | { | |
165a7f90 L |
4859 | case 'd': |
4860 | alignment = 8; | |
4861 | break; | |
4862 | ||
4863 | case 'x': | |
4864 | case 'X': | |
4865 | alignment = 16; | |
4866 | break; | |
800eeca4 JW |
4867 | |
4868 | case 'f': | |
4869 | default: | |
165a7f90 | 4870 | alignment = 4; |
800eeca4 JW |
4871 | break; |
4872 | } | |
165a7f90 | 4873 | ia64_do_align (alignment); |
800eeca4 JW |
4874 | float_cons (kind); |
4875 | } | |
4876 | ||
4877 | static void | |
5a49b8ac | 4878 | stmt_cons_ua (int size) |
800eeca4 JW |
4879 | { |
4880 | int saved_auto_align = md.auto_align; | |
4881 | ||
4882 | md.auto_align = 0; | |
4883 | cons (size); | |
4884 | md.auto_align = saved_auto_align; | |
4885 | } | |
4886 | ||
4887 | static void | |
5a49b8ac | 4888 | dot_xfloat_cons (int kind) |
800eeca4 | 4889 | { |
ef6a2b41 | 4890 | cross_section (kind, stmt_float_cons, 0); |
800eeca4 JW |
4891 | } |
4892 | ||
4893 | static void | |
38a57ae7 | 4894 | dot_xstringer (int zero) |
800eeca4 | 4895 | { |
ef6a2b41 | 4896 | cross_section (zero, stringer, 0); |
800eeca4 JW |
4897 | } |
4898 | ||
4899 | static void | |
5a49b8ac | 4900 | dot_xdata_ua (int size) |
800eeca4 | 4901 | { |
ef6a2b41 | 4902 | cross_section (size, cons, 1); |
800eeca4 JW |
4903 | } |
4904 | ||
4905 | static void | |
5a49b8ac | 4906 | dot_xfloat_cons_ua (int kind) |
800eeca4 | 4907 | { |
ef6a2b41 | 4908 | cross_section (kind, float_cons, 1); |
800eeca4 JW |
4909 | } |
4910 | ||
4911 | /* .reg.val <regname>,value */ | |
542d6675 | 4912 | |
800eeca4 | 4913 | static void |
5a49b8ac | 4914 | dot_reg_val (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
4915 | { |
4916 | expressionS reg; | |
4917 | ||
60d11e55 | 4918 | expression_and_evaluate (®); |
800eeca4 JW |
4919 | if (reg.X_op != O_register) |
4920 | { | |
4921 | as_bad (_("Register name expected")); | |
4922 | ignore_rest_of_line (); | |
4923 | } | |
4924 | else if (*input_line_pointer++ != ',') | |
4925 | { | |
4926 | as_bad (_("Comma expected")); | |
4927 | ignore_rest_of_line (); | |
4928 | } | |
197865e8 | 4929 | else |
800eeca4 JW |
4930 | { |
4931 | valueT value = get_absolute_expression (); | |
4932 | int regno = reg.X_add_number; | |
a66d2bb7 | 4933 | if (regno <= REG_GR || regno > REG_GR + 127) |
542d6675 | 4934 | as_warn (_("Register value annotation ignored")); |
800eeca4 | 4935 | else |
542d6675 KH |
4936 | { |
4937 | gr_values[regno - REG_GR].known = 1; | |
4938 | gr_values[regno - REG_GR].value = value; | |
4939 | gr_values[regno - REG_GR].path = md.path; | |
4940 | } | |
800eeca4 JW |
4941 | } |
4942 | demand_empty_rest_of_line (); | |
4943 | } | |
4944 | ||
5e819f9c JW |
4945 | /* |
4946 | .serialize.data | |
4947 | .serialize.instruction | |
4948 | */ | |
4949 | static void | |
5a49b8ac | 4950 | dot_serialize (int type) |
5e819f9c JW |
4951 | { |
4952 | insn_group_break (0, 0, 0); | |
4953 | if (type) | |
4954 | instruction_serialization (); | |
4955 | else | |
4956 | data_serialization (); | |
4957 | insn_group_break (0, 0, 0); | |
4958 | demand_empty_rest_of_line (); | |
4959 | } | |
4960 | ||
197865e8 | 4961 | /* select dv checking mode |
800eeca4 JW |
4962 | .auto |
4963 | .explicit | |
4964 | .default | |
4965 | ||
197865e8 | 4966 | A stop is inserted when changing modes |
800eeca4 | 4967 | */ |
542d6675 | 4968 | |
800eeca4 | 4969 | static void |
5a49b8ac | 4970 | dot_dv_mode (int type) |
800eeca4 JW |
4971 | { |
4972 | if (md.manual_bundling) | |
4973 | as_warn (_("Directive invalid within a bundle")); | |
4974 | ||
4975 | if (type == 'E' || type == 'A') | |
4976 | md.mode_explicitly_set = 0; | |
4977 | else | |
4978 | md.mode_explicitly_set = 1; | |
4979 | ||
4980 | md.detect_dv = 1; | |
4981 | switch (type) | |
4982 | { | |
4983 | case 'A': | |
4984 | case 'a': | |
4985 | if (md.explicit_mode) | |
542d6675 | 4986 | insn_group_break (1, 0, 0); |
800eeca4 JW |
4987 | md.explicit_mode = 0; |
4988 | break; | |
4989 | case 'E': | |
4990 | case 'e': | |
4991 | if (!md.explicit_mode) | |
542d6675 | 4992 | insn_group_break (1, 0, 0); |
800eeca4 JW |
4993 | md.explicit_mode = 1; |
4994 | break; | |
4995 | default: | |
4996 | case 'd': | |
4997 | if (md.explicit_mode != md.default_explicit_mode) | |
542d6675 | 4998 | insn_group_break (1, 0, 0); |
800eeca4 JW |
4999 | md.explicit_mode = md.default_explicit_mode; |
5000 | md.mode_explicitly_set = 0; | |
5001 | break; | |
5002 | } | |
5003 | } | |
5004 | ||
5005 | static void | |
5a49b8ac | 5006 | print_prmask (valueT mask) |
800eeca4 JW |
5007 | { |
5008 | int regno; | |
5009 | char *comma = ""; | |
542d6675 | 5010 | for (regno = 0; regno < 64; regno++) |
800eeca4 | 5011 | { |
542d6675 KH |
5012 | if (mask & ((valueT) 1 << regno)) |
5013 | { | |
5014 | fprintf (stderr, "%s p%d", comma, regno); | |
5015 | comma = ","; | |
5016 | } | |
800eeca4 JW |
5017 | } |
5018 | } | |
5019 | ||
5020 | /* | |
05ee4b0f JB |
5021 | .pred.rel.clear [p1 [,p2 [,...]]] (also .pred.rel "clear" or @clear) |
5022 | .pred.rel.imply p1, p2 (also .pred.rel "imply" or @imply) | |
5023 | .pred.rel.mutex p1, p2 [,...] (also .pred.rel "mutex" or @mutex) | |
800eeca4 JW |
5024 | .pred.safe_across_calls p1 [, p2 [,...]] |
5025 | */ | |
542d6675 | 5026 | |
800eeca4 | 5027 | static void |
5a49b8ac | 5028 | dot_pred_rel (int type) |
800eeca4 JW |
5029 | { |
5030 | valueT mask = 0; | |
5031 | int count = 0; | |
5032 | int p1 = -1, p2 = -1; | |
5033 | ||
5034 | if (type == 0) | |
5035 | { | |
05ee4b0f | 5036 | if (*input_line_pointer == '"') |
542d6675 KH |
5037 | { |
5038 | int len; | |
5039 | char *form = demand_copy_C_string (&len); | |
05ee4b0f | 5040 | |
542d6675 KH |
5041 | if (strcmp (form, "mutex") == 0) |
5042 | type = 'm'; | |
5043 | else if (strcmp (form, "clear") == 0) | |
5044 | type = 'c'; | |
5045 | else if (strcmp (form, "imply") == 0) | |
5046 | type = 'i'; | |
05ee4b0f JB |
5047 | obstack_free (¬es, form); |
5048 | } | |
5049 | else if (*input_line_pointer == '@') | |
5050 | { | |
d02603dc NC |
5051 | char *form; |
5052 | char c; | |
5053 | ||
5054 | ++input_line_pointer; | |
5055 | c = get_symbol_name (&form); | |
05ee4b0f JB |
5056 | |
5057 | if (strcmp (form, "mutex") == 0) | |
5058 | type = 'm'; | |
5059 | else if (strcmp (form, "clear") == 0) | |
5060 | type = 'c'; | |
5061 | else if (strcmp (form, "imply") == 0) | |
5062 | type = 'i'; | |
d02603dc | 5063 | (void) restore_line_pointer (c); |
05ee4b0f JB |
5064 | } |
5065 | else | |
5066 | { | |
5067 | as_bad (_("Missing predicate relation type")); | |
5068 | ignore_rest_of_line (); | |
5069 | return; | |
5070 | } | |
5071 | if (type == 0) | |
5072 | { | |
5073 | as_bad (_("Unrecognized predicate relation type")); | |
5074 | ignore_rest_of_line (); | |
5075 | return; | |
542d6675 | 5076 | } |
800eeca4 | 5077 | if (*input_line_pointer == ',') |
542d6675 | 5078 | ++input_line_pointer; |
800eeca4 JW |
5079 | SKIP_WHITESPACE (); |
5080 | } | |
5081 | ||
800eeca4 JW |
5082 | while (1) |
5083 | { | |
20b36a95 | 5084 | valueT bits = 1; |
cc941dee | 5085 | int sep, regno; |
20b36a95 JB |
5086 | expressionS pr, *pr1, *pr2; |
5087 | ||
cd42ff9c | 5088 | sep = parse_operand_and_eval (&pr, ','); |
20b36a95 JB |
5089 | if (pr.X_op == O_register |
5090 | && pr.X_add_number >= REG_P | |
5091 | && pr.X_add_number <= REG_P + 63) | |
5092 | { | |
5093 | regno = pr.X_add_number - REG_P; | |
5094 | bits <<= regno; | |
5095 | count++; | |
5096 | if (p1 == -1) | |
5097 | p1 = regno; | |
5098 | else if (p2 == -1) | |
5099 | p2 = regno; | |
5100 | } | |
5101 | else if (type != 'i' | |
5102 | && pr.X_op == O_subtract | |
5103 | && (pr1 = symbol_get_value_expression (pr.X_add_symbol)) | |
5104 | && pr1->X_op == O_register | |
5105 | && pr1->X_add_number >= REG_P | |
5106 | && pr1->X_add_number <= REG_P + 63 | |
5107 | && (pr2 = symbol_get_value_expression (pr.X_op_symbol)) | |
5108 | && pr2->X_op == O_register | |
5109 | && pr2->X_add_number >= REG_P | |
5110 | && pr2->X_add_number <= REG_P + 63) | |
5111 | { | |
5112 | /* It's a range. */ | |
5113 | int stop; | |
5114 | ||
5115 | regno = pr1->X_add_number - REG_P; | |
5116 | stop = pr2->X_add_number - REG_P; | |
5117 | if (regno >= stop) | |
542d6675 KH |
5118 | { |
5119 | as_bad (_("Bad register range")); | |
5120 | ignore_rest_of_line (); | |
5121 | return; | |
5122 | } | |
20b36a95 JB |
5123 | bits = ((bits << stop) << 1) - (bits << regno); |
5124 | count += stop - regno + 1; | |
5125 | } | |
5126 | else | |
5127 | { | |
5128 | as_bad (_("Predicate register expected")); | |
5129 | ignore_rest_of_line (); | |
5130 | return; | |
542d6675 | 5131 | } |
20b36a95 JB |
5132 | if (mask & bits) |
5133 | as_warn (_("Duplicate predicate register ignored")); | |
5134 | mask |= bits; | |
cc941dee | 5135 | if (sep != ',') |
542d6675 | 5136 | break; |
800eeca4 JW |
5137 | } |
5138 | ||
5139 | switch (type) | |
5140 | { | |
5141 | case 'c': | |
5142 | if (count == 0) | |
542d6675 | 5143 | mask = ~(valueT) 0; |
800eeca4 | 5144 | clear_qp_mutex (mask); |
197865e8 | 5145 | clear_qp_implies (mask, (valueT) 0); |
800eeca4 JW |
5146 | break; |
5147 | case 'i': | |
5148 | if (count != 2 || p1 == -1 || p2 == -1) | |
542d6675 | 5149 | as_bad (_("Predicate source and target required")); |
800eeca4 | 5150 | else if (p1 == 0 || p2 == 0) |
542d6675 | 5151 | as_bad (_("Use of p0 is not valid in this context")); |
800eeca4 | 5152 | else |
542d6675 | 5153 | add_qp_imply (p1, p2); |
800eeca4 JW |
5154 | break; |
5155 | case 'm': | |
5156 | if (count < 2) | |
542d6675 KH |
5157 | { |
5158 | as_bad (_("At least two PR arguments expected")); | |
5159 | break; | |
5160 | } | |
800eeca4 | 5161 | else if (mask & 1) |
542d6675 KH |
5162 | { |
5163 | as_bad (_("Use of p0 is not valid in this context")); | |
5164 | break; | |
5165 | } | |
800eeca4 JW |
5166 | add_qp_mutex (mask); |
5167 | break; | |
5168 | case 's': | |
5169 | /* note that we don't override any existing relations */ | |
5170 | if (count == 0) | |
542d6675 KH |
5171 | { |
5172 | as_bad (_("At least one PR argument expected")); | |
5173 | break; | |
5174 | } | |
800eeca4 | 5175 | if (md.debug_dv) |
542d6675 KH |
5176 | { |
5177 | fprintf (stderr, "Safe across calls: "); | |
5178 | print_prmask (mask); | |
5179 | fprintf (stderr, "\n"); | |
5180 | } | |
800eeca4 JW |
5181 | qp_safe_across_calls = mask; |
5182 | break; | |
5183 | } | |
5184 | demand_empty_rest_of_line (); | |
5185 | } | |
5186 | ||
5187 | /* .entry label [, label [, ...]] | |
5188 | Hint to DV code that the given labels are to be considered entry points. | |
542d6675 KH |
5189 | Otherwise, only global labels are considered entry points. */ |
5190 | ||
800eeca4 | 5191 | static void |
5a49b8ac | 5192 | dot_entry (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
5193 | { |
5194 | const char *err; | |
5195 | char *name; | |
5196 | int c; | |
5197 | symbolS *symbolP; | |
5198 | ||
5199 | do | |
5200 | { | |
d02603dc | 5201 | c = get_symbol_name (&name); |
800eeca4 JW |
5202 | symbolP = symbol_find_or_make (name); |
5203 | ||
5a49b8ac | 5204 | err = hash_insert (md.entry_hash, S_GET_NAME (symbolP), (void *) symbolP); |
800eeca4 | 5205 | if (err) |
542d6675 KH |
5206 | as_fatal (_("Inserting \"%s\" into entry hint table failed: %s"), |
5207 | name, err); | |
800eeca4 JW |
5208 | |
5209 | *input_line_pointer = c; | |
d02603dc | 5210 | SKIP_WHITESPACE_AFTER_NAME (); |
800eeca4 JW |
5211 | c = *input_line_pointer; |
5212 | if (c == ',') | |
5213 | { | |
5214 | input_line_pointer++; | |
5215 | SKIP_WHITESPACE (); | |
5216 | if (*input_line_pointer == '\n') | |
5217 | c = '\n'; | |
5218 | } | |
5219 | } | |
5220 | while (c == ','); | |
5221 | ||
5222 | demand_empty_rest_of_line (); | |
5223 | } | |
5224 | ||
197865e8 | 5225 | /* .mem.offset offset, base |
542d6675 KH |
5226 | "base" is used to distinguish between offsets from a different base. */ |
5227 | ||
800eeca4 | 5228 | static void |
5a49b8ac | 5229 | dot_mem_offset (int dummy ATTRIBUTE_UNUSED) |
800eeca4 JW |
5230 | { |
5231 | md.mem_offset.hint = 1; | |
5232 | md.mem_offset.offset = get_absolute_expression (); | |
5233 | if (*input_line_pointer != ',') | |
5234 | { | |
5235 | as_bad (_("Comma expected")); | |
5236 | ignore_rest_of_line (); | |
5237 | return; | |
5238 | } | |
5239 | ++input_line_pointer; | |
5240 | md.mem_offset.base = get_absolute_expression (); | |
5241 | demand_empty_rest_of_line (); | |
5242 | } | |
5243 | ||
542d6675 | 5244 | /* ia64-specific pseudo-ops: */ |
800eeca4 JW |
5245 | const pseudo_typeS md_pseudo_table[] = |
5246 | { | |
5247 | { "radix", dot_radix, 0 }, | |
5248 | { "lcomm", s_lcomm_bytes, 1 }, | |
196e8040 | 5249 | { "loc", dot_loc, 0 }, |
800eeca4 JW |
5250 | { "bss", dot_special_section, SPECIAL_SECTION_BSS }, |
5251 | { "sbss", dot_special_section, SPECIAL_SECTION_SBSS }, | |
5252 | { "sdata", dot_special_section, SPECIAL_SECTION_SDATA }, | |
5253 | { "rodata", dot_special_section, SPECIAL_SECTION_RODATA }, | |
5254 | { "comment", dot_special_section, SPECIAL_SECTION_COMMENT }, | |
5255 | { "ia_64.unwind", dot_special_section, SPECIAL_SECTION_UNWIND }, | |
5256 | { "ia_64.unwind_info", dot_special_section, SPECIAL_SECTION_UNWIND_INFO }, | |
557debba JW |
5257 | { "init_array", dot_special_section, SPECIAL_SECTION_INIT_ARRAY }, |
5258 | { "fini_array", dot_special_section, SPECIAL_SECTION_FINI_ARRAY }, | |
800eeca4 JW |
5259 | { "proc", dot_proc, 0 }, |
5260 | { "body", dot_body, 0 }, | |
5261 | { "prologue", dot_prologue, 0 }, | |
2434f565 | 5262 | { "endp", dot_endp, 0 }, |
2434f565 JW |
5263 | |
5264 | { "fframe", dot_fframe, 0 }, | |
5265 | { "vframe", dot_vframe, 0 }, | |
5266 | { "vframesp", dot_vframesp, 0 }, | |
e4e8248d | 5267 | { "vframepsp", dot_vframesp, 1 }, |
2434f565 JW |
5268 | { "save", dot_save, 0 }, |
5269 | { "restore", dot_restore, 0 }, | |
5270 | { "restorereg", dot_restorereg, 0 }, | |
e4e8248d | 5271 | { "restorereg.p", dot_restorereg, 1 }, |
2434f565 JW |
5272 | { "handlerdata", dot_handlerdata, 0 }, |
5273 | { "unwentry", dot_unwentry, 0 }, | |
5274 | { "altrp", dot_altrp, 0 }, | |
e0c9811a JW |
5275 | { "savesp", dot_savemem, 0 }, |
5276 | { "savepsp", dot_savemem, 1 }, | |
2434f565 JW |
5277 | { "save.g", dot_saveg, 0 }, |
5278 | { "save.f", dot_savef, 0 }, | |
5279 | { "save.b", dot_saveb, 0 }, | |
5280 | { "save.gf", dot_savegf, 0 }, | |
5281 | { "spill", dot_spill, 0 }, | |
5282 | { "spillreg", dot_spillreg, 0 }, | |
e0c9811a JW |
5283 | { "spillsp", dot_spillmem, 0 }, |
5284 | { "spillpsp", dot_spillmem, 1 }, | |
e4e8248d JB |
5285 | { "spillreg.p", dot_spillreg, 1 }, |
5286 | { "spillsp.p", dot_spillmem, ~0 }, | |
5287 | { "spillpsp.p", dot_spillmem, ~1 }, | |
2434f565 JW |
5288 | { "label_state", dot_label_state, 0 }, |
5289 | { "copy_state", dot_copy_state, 0 }, | |
5290 | { "unwabi", dot_unwabi, 0 }, | |
5291 | { "personality", dot_personality, 0 }, | |
800eeca4 JW |
5292 | { "mii", dot_template, 0x0 }, |
5293 | { "mli", dot_template, 0x2 }, /* old format, for compatibility */ | |
5294 | { "mlx", dot_template, 0x2 }, | |
5295 | { "mmi", dot_template, 0x4 }, | |
5296 | { "mfi", dot_template, 0x6 }, | |
5297 | { "mmf", dot_template, 0x7 }, | |
5298 | { "mib", dot_template, 0x8 }, | |
5299 | { "mbb", dot_template, 0x9 }, | |
5300 | { "bbb", dot_template, 0xb }, | |
5301 | { "mmb", dot_template, 0xc }, | |
5302 | { "mfb", dot_template, 0xe }, | |
d9201763 | 5303 | { "align", dot_align, 0 }, |
800eeca4 JW |
5304 | { "regstk", dot_regstk, 0 }, |
5305 | { "rotr", dot_rot, DYNREG_GR }, | |
5306 | { "rotf", dot_rot, DYNREG_FR }, | |
5307 | { "rotp", dot_rot, DYNREG_PR }, | |
5308 | { "lsb", dot_byteorder, 0 }, | |
5309 | { "msb", dot_byteorder, 1 }, | |
5310 | { "psr", dot_psr, 0 }, | |
5311 | { "alias", dot_alias, 0 }, | |
35f5df7f | 5312 | { "secalias", dot_alias, 1 }, |
800eeca4 JW |
5313 | { "ln", dot_ln, 0 }, /* source line info (for debugging) */ |
5314 | ||
5315 | { "xdata1", dot_xdata, 1 }, | |
5316 | { "xdata2", dot_xdata, 2 }, | |
5317 | { "xdata4", dot_xdata, 4 }, | |
5318 | { "xdata8", dot_xdata, 8 }, | |
b3f19c14 | 5319 | { "xdata16", dot_xdata, 16 }, |
800eeca4 JW |
5320 | { "xreal4", dot_xfloat_cons, 'f' }, |
5321 | { "xreal8", dot_xfloat_cons, 'd' }, | |
5322 | { "xreal10", dot_xfloat_cons, 'x' }, | |
165a7f90 | 5323 | { "xreal16", dot_xfloat_cons, 'X' }, |
38a57ae7 NC |
5324 | { "xstring", dot_xstringer, 8 + 0 }, |
5325 | { "xstringz", dot_xstringer, 8 + 1 }, | |
800eeca4 | 5326 | |
542d6675 | 5327 | /* unaligned versions: */ |
800eeca4 JW |
5328 | { "xdata2.ua", dot_xdata_ua, 2 }, |
5329 | { "xdata4.ua", dot_xdata_ua, 4 }, | |
5330 | { "xdata8.ua", dot_xdata_ua, 8 }, | |
b3f19c14 | 5331 | { "xdata16.ua", dot_xdata_ua, 16 }, |
800eeca4 JW |
5332 | { "xreal4.ua", dot_xfloat_cons_ua, 'f' }, |
5333 | { "xreal8.ua", dot_xfloat_cons_ua, 'd' }, | |
5334 | { "xreal10.ua", dot_xfloat_cons_ua, 'x' }, | |
165a7f90 | 5335 | { "xreal16.ua", dot_xfloat_cons_ua, 'X' }, |
800eeca4 JW |
5336 | |
5337 | /* annotations/DV checking support */ | |
5338 | { "entry", dot_entry, 0 }, | |
2434f565 | 5339 | { "mem.offset", dot_mem_offset, 0 }, |
800eeca4 JW |
5340 | { "pred.rel", dot_pred_rel, 0 }, |
5341 | { "pred.rel.clear", dot_pred_rel, 'c' }, | |
5342 | { "pred.rel.imply", dot_pred_rel, 'i' }, | |
5343 | { "pred.rel.mutex", dot_pred_rel, 'm' }, | |
5344 | { "pred.safe_across_calls", dot_pred_rel, 's' }, | |
2434f565 | 5345 | { "reg.val", dot_reg_val, 0 }, |
5e819f9c JW |
5346 | { "serialize.data", dot_serialize, 0 }, |
5347 | { "serialize.instruction", dot_serialize, 1 }, | |
800eeca4 JW |
5348 | { "auto", dot_dv_mode, 'a' }, |
5349 | { "explicit", dot_dv_mode, 'e' }, | |
5350 | { "default", dot_dv_mode, 'd' }, | |
5351 | ||
87885043 JW |
5352 | /* ??? These are needed to make gas/testsuite/gas/elf/ehopt.s work. |
5353 | IA-64 aligns data allocation pseudo-ops by default, so we have to | |
5354 | tell it that these ones are supposed to be unaligned. Long term, | |
5355 | should rewrite so that only IA-64 specific data allocation pseudo-ops | |
5356 | are aligned by default. */ | |
5357 | {"2byte", stmt_cons_ua, 2}, | |
5358 | {"4byte", stmt_cons_ua, 4}, | |
5359 | {"8byte", stmt_cons_ua, 8}, | |
5360 | ||
2b0bc501 TG |
5361 | #ifdef TE_VMS |
5362 | {"vms_common", obj_elf_vms_common, 0}, | |
5363 | #endif | |
5364 | ||
800eeca4 JW |
5365 | { NULL, 0, 0 } |
5366 | }; | |
5367 | ||
5368 | static const struct pseudo_opcode | |
5369 | { | |
5370 | const char *name; | |
5371 | void (*handler) (int); | |
5372 | int arg; | |
5373 | } | |
5374 | pseudo_opcode[] = | |
5375 | { | |
5376 | /* these are more like pseudo-ops, but don't start with a dot */ | |
5377 | { "data1", cons, 1 }, | |
5378 | { "data2", cons, 2 }, | |
5379 | { "data4", cons, 4 }, | |
5380 | { "data8", cons, 8 }, | |
3969b680 | 5381 | { "data16", cons, 16 }, |
800eeca4 JW |
5382 | { "real4", stmt_float_cons, 'f' }, |
5383 | { "real8", stmt_float_cons, 'd' }, | |
5384 | { "real10", stmt_float_cons, 'x' }, | |
165a7f90 | 5385 | { "real16", stmt_float_cons, 'X' }, |
38a57ae7 NC |
5386 | { "string", stringer, 8 + 0 }, |
5387 | { "stringz", stringer, 8 + 1 }, | |
800eeca4 | 5388 | |
542d6675 | 5389 | /* unaligned versions: */ |
800eeca4 JW |
5390 | { "data2.ua", stmt_cons_ua, 2 }, |
5391 | { "data4.ua", stmt_cons_ua, 4 }, | |
5392 | { "data8.ua", stmt_cons_ua, 8 }, | |
3969b680 | 5393 | { "data16.ua", stmt_cons_ua, 16 }, |
800eeca4 JW |
5394 | { "real4.ua", float_cons, 'f' }, |
5395 | { "real8.ua", float_cons, 'd' }, | |
5396 | { "real10.ua", float_cons, 'x' }, | |
165a7f90 | 5397 | { "real16.ua", float_cons, 'X' }, |
800eeca4 JW |
5398 | }; |
5399 | ||
5400 | /* Declare a register by creating a symbol for it and entering it in | |
5401 | the symbol table. */ | |
542d6675 KH |
5402 | |
5403 | static symbolS * | |
5a49b8ac | 5404 | declare_register (const char *name, unsigned int regnum) |
800eeca4 JW |
5405 | { |
5406 | const char *err; | |
5407 | symbolS *sym; | |
5408 | ||
5e0bd176 | 5409 | sym = symbol_create (name, reg_section, regnum, &zero_address_frag); |
800eeca4 | 5410 | |
5a49b8ac | 5411 | err = hash_insert (md.reg_hash, S_GET_NAME (sym), (void *) sym); |
800eeca4 JW |
5412 | if (err) |
5413 | as_fatal ("Inserting \"%s\" into register table failed: %s", | |
5414 | name, err); | |
5415 | ||
5416 | return sym; | |
5417 | } | |
5418 | ||
5419 | static void | |
5a49b8ac AM |
5420 | declare_register_set (const char *prefix, |
5421 | unsigned int num_regs, | |
5422 | unsigned int base_regnum) | |
800eeca4 JW |
5423 | { |
5424 | char name[8]; | |
8b84be9d | 5425 | unsigned int i; |
800eeca4 JW |
5426 | |
5427 | for (i = 0; i < num_regs; ++i) | |
5428 | { | |
f9f21a03 | 5429 | snprintf (name, sizeof (name), "%s%u", prefix, i); |
800eeca4 JW |
5430 | declare_register (name, base_regnum + i); |
5431 | } | |
5432 | } | |
5433 | ||
5434 | static unsigned int | |
5a49b8ac | 5435 | operand_width (enum ia64_opnd opnd) |
800eeca4 JW |
5436 | { |
5437 | const struct ia64_operand *odesc = &elf64_ia64_operands[opnd]; | |
5438 | unsigned int bits = 0; | |
5439 | int i; | |
5440 | ||
5441 | bits = 0; | |
5442 | for (i = 0; i < NELEMS (odesc->field) && odesc->field[i].bits; ++i) | |
5443 | bits += odesc->field[i].bits; | |
5444 | ||
5445 | return bits; | |
5446 | } | |
5447 | ||
87f8eb97 | 5448 | static enum operand_match_result |
91d6fa6a | 5449 | operand_match (const struct ia64_opcode *idesc, int res_index, expressionS *e) |
800eeca4 | 5450 | { |
91d6fa6a | 5451 | enum ia64_opnd opnd = idesc->operands[res_index]; |
800eeca4 JW |
5452 | int bits, relocatable = 0; |
5453 | struct insn_fix *fix; | |
5454 | bfd_signed_vma val; | |
5455 | ||
5456 | switch (opnd) | |
5457 | { | |
542d6675 | 5458 | /* constants: */ |
800eeca4 JW |
5459 | |
5460 | case IA64_OPND_AR_CCV: | |
5461 | if (e->X_op == O_register && e->X_add_number == REG_AR + 32) | |
87f8eb97 | 5462 | return OPERAND_MATCH; |
800eeca4 JW |
5463 | break; |
5464 | ||
c10d9d8f JW |
5465 | case IA64_OPND_AR_CSD: |
5466 | if (e->X_op == O_register && e->X_add_number == REG_AR + 25) | |
5467 | return OPERAND_MATCH; | |
5468 | break; | |
5469 | ||
800eeca4 JW |
5470 | case IA64_OPND_AR_PFS: |
5471 | if (e->X_op == O_register && e->X_add_number == REG_AR + 64) | |
87f8eb97 | 5472 | return OPERAND_MATCH; |
800eeca4 JW |
5473 | break; |
5474 | ||
5475 | case IA64_OPND_GR0: | |
5476 | if (e->X_op == O_register && e->X_add_number == REG_GR + 0) | |
87f8eb97 | 5477 | return OPERAND_MATCH; |
800eeca4 JW |
5478 | break; |
5479 | ||
5480 | case IA64_OPND_IP: | |
5481 | if (e->X_op == O_register && e->X_add_number == REG_IP) | |
87f8eb97 | 5482 | return OPERAND_MATCH; |
800eeca4 JW |
5483 | break; |
5484 | ||
5485 | case IA64_OPND_PR: | |
5486 | if (e->X_op == O_register && e->X_add_number == REG_PR) | |
87f8eb97 | 5487 | return OPERAND_MATCH; |
800eeca4 JW |
5488 | break; |
5489 | ||
5490 | case IA64_OPND_PR_ROT: | |
5491 | if (e->X_op == O_register && e->X_add_number == REG_PR_ROT) | |
87f8eb97 | 5492 | return OPERAND_MATCH; |
800eeca4 JW |
5493 | break; |
5494 | ||
5495 | case IA64_OPND_PSR: | |
5496 | if (e->X_op == O_register && e->X_add_number == REG_PSR) | |
87f8eb97 | 5497 | return OPERAND_MATCH; |
800eeca4 JW |
5498 | break; |
5499 | ||
5500 | case IA64_OPND_PSR_L: | |
5501 | if (e->X_op == O_register && e->X_add_number == REG_PSR_L) | |
87f8eb97 | 5502 | return OPERAND_MATCH; |
800eeca4 JW |
5503 | break; |
5504 | ||
5505 | case IA64_OPND_PSR_UM: | |
5506 | if (e->X_op == O_register && e->X_add_number == REG_PSR_UM) | |
87f8eb97 | 5507 | return OPERAND_MATCH; |
800eeca4 JW |
5508 | break; |
5509 | ||
5510 | case IA64_OPND_C1: | |
87f8eb97 JW |
5511 | if (e->X_op == O_constant) |
5512 | { | |
5513 | if (e->X_add_number == 1) | |
5514 | return OPERAND_MATCH; | |
5515 | else | |
5516 | return OPERAND_OUT_OF_RANGE; | |
5517 | } | |
800eeca4 JW |
5518 | break; |
5519 | ||
5520 | case IA64_OPND_C8: | |
87f8eb97 JW |
5521 | if (e->X_op == O_constant) |
5522 | { | |
5523 | if (e->X_add_number == 8) | |
5524 | return OPERAND_MATCH; | |
5525 | else | |
5526 | return OPERAND_OUT_OF_RANGE; | |
5527 | } | |
800eeca4 JW |
5528 | break; |
5529 | ||
5530 | case IA64_OPND_C16: | |
87f8eb97 JW |
5531 | if (e->X_op == O_constant) |
5532 | { | |
5533 | if (e->X_add_number == 16) | |
5534 | return OPERAND_MATCH; | |
5535 | else | |
5536 | return OPERAND_OUT_OF_RANGE; | |
5537 | } | |
800eeca4 JW |
5538 | break; |
5539 | ||
542d6675 | 5540 | /* register operands: */ |
800eeca4 JW |
5541 | |
5542 | case IA64_OPND_AR3: | |
5543 | if (e->X_op == O_register && e->X_add_number >= REG_AR | |
5544 | && e->X_add_number < REG_AR + 128) | |
87f8eb97 | 5545 | return OPERAND_MATCH; |
800eeca4 JW |
5546 | break; |
5547 | ||
5548 | case IA64_OPND_B1: | |
5549 | case IA64_OPND_B2: | |
5550 | if (e->X_op == O_register && e->X_add_number >= REG_BR | |
5551 | && e->X_add_number < REG_BR + 8) | |
87f8eb97 | 5552 | return OPERAND_MATCH; |
800eeca4 JW |
5553 | break; |
5554 | ||
5555 | case IA64_OPND_CR3: | |
5556 | if (e->X_op == O_register && e->X_add_number >= REG_CR | |
5557 | && e->X_add_number < REG_CR + 128) | |
87f8eb97 | 5558 | return OPERAND_MATCH; |
800eeca4 JW |
5559 | break; |
5560 | ||
b3e14eda L |
5561 | case IA64_OPND_DAHR3: |
5562 | if (e->X_op == O_register && e->X_add_number >= REG_DAHR | |
5563 | && e->X_add_number < REG_DAHR + 8) | |
5564 | return OPERAND_MATCH; | |
5565 | break; | |
5566 | ||
800eeca4 JW |
5567 | case IA64_OPND_F1: |
5568 | case IA64_OPND_F2: | |
5569 | case IA64_OPND_F3: | |
5570 | case IA64_OPND_F4: | |
5571 | if (e->X_op == O_register && e->X_add_number >= REG_FR | |
5572 | && e->X_add_number < REG_FR + 128) | |
87f8eb97 | 5573 | return OPERAND_MATCH; |
800eeca4 JW |
5574 | break; |
5575 | ||
5576 | case IA64_OPND_P1: | |
5577 | case IA64_OPND_P2: | |
5578 | if (e->X_op == O_register && e->X_add_number >= REG_P | |
5579 | && e->X_add_number < REG_P + 64) | |
87f8eb97 | 5580 | return OPERAND_MATCH; |
800eeca4 JW |
5581 | break; |
5582 | ||
5583 | case IA64_OPND_R1: | |
5584 | case IA64_OPND_R2: | |
5585 | case IA64_OPND_R3: | |
5586 | if (e->X_op == O_register && e->X_add_number >= REG_GR | |
5587 | && e->X_add_number < REG_GR + 128) | |
87f8eb97 | 5588 | return OPERAND_MATCH; |
800eeca4 JW |
5589 | break; |
5590 | ||
5591 | case IA64_OPND_R3_2: | |
87f8eb97 | 5592 | if (e->X_op == O_register && e->X_add_number >= REG_GR) |
40449e9f | 5593 | { |
87f8eb97 JW |
5594 | if (e->X_add_number < REG_GR + 4) |
5595 | return OPERAND_MATCH; | |
5596 | else if (e->X_add_number < REG_GR + 128) | |
5597 | return OPERAND_OUT_OF_RANGE; | |
5598 | } | |
800eeca4 JW |
5599 | break; |
5600 | ||
542d6675 | 5601 | /* indirect operands: */ |
800eeca4 JW |
5602 | case IA64_OPND_CPUID_R3: |
5603 | case IA64_OPND_DBR_R3: | |
5604 | case IA64_OPND_DTR_R3: | |
5605 | case IA64_OPND_ITR_R3: | |
5606 | case IA64_OPND_IBR_R3: | |
5607 | case IA64_OPND_MSR_R3: | |
5608 | case IA64_OPND_PKR_R3: | |
5609 | case IA64_OPND_PMC_R3: | |
5610 | case IA64_OPND_PMD_R3: | |
b3e14eda | 5611 | case IA64_OPND_DAHR_R3: |
800eeca4 JW |
5612 | case IA64_OPND_RR_R3: |
5613 | if (e->X_op == O_index && e->X_op_symbol | |
5614 | && (S_GET_VALUE (e->X_op_symbol) - IND_CPUID | |
5615 | == opnd - IA64_OPND_CPUID_R3)) | |
87f8eb97 | 5616 | return OPERAND_MATCH; |
800eeca4 JW |
5617 | break; |
5618 | ||
5619 | case IA64_OPND_MR3: | |
5620 | if (e->X_op == O_index && !e->X_op_symbol) | |
87f8eb97 | 5621 | return OPERAND_MATCH; |
800eeca4 JW |
5622 | break; |
5623 | ||
542d6675 | 5624 | /* immediate operands: */ |
800eeca4 JW |
5625 | case IA64_OPND_CNT2a: |
5626 | case IA64_OPND_LEN4: | |
5627 | case IA64_OPND_LEN6: | |
91d6fa6a | 5628 | bits = operand_width (idesc->operands[res_index]); |
87f8eb97 JW |
5629 | if (e->X_op == O_constant) |
5630 | { | |
5631 | if ((bfd_vma) (e->X_add_number - 1) < ((bfd_vma) 1 << bits)) | |
5632 | return OPERAND_MATCH; | |
5633 | else | |
5634 | return OPERAND_OUT_OF_RANGE; | |
5635 | } | |
800eeca4 JW |
5636 | break; |
5637 | ||
5638 | case IA64_OPND_CNT2b: | |
87f8eb97 JW |
5639 | if (e->X_op == O_constant) |
5640 | { | |
5641 | if ((bfd_vma) (e->X_add_number - 1) < 3) | |
5642 | return OPERAND_MATCH; | |
5643 | else | |
5644 | return OPERAND_OUT_OF_RANGE; | |
5645 | } | |
800eeca4 JW |
5646 | break; |
5647 | ||
5648 | case IA64_OPND_CNT2c: | |
5649 | val = e->X_add_number; | |
87f8eb97 JW |
5650 | if (e->X_op == O_constant) |
5651 | { | |
5652 | if ((val == 0 || val == 7 || val == 15 || val == 16)) | |
5653 | return OPERAND_MATCH; | |
5654 | else | |
5655 | return OPERAND_OUT_OF_RANGE; | |
5656 | } | |
800eeca4 JW |
5657 | break; |
5658 | ||
5659 | case IA64_OPND_SOR: | |
5660 | /* SOR must be an integer multiple of 8 */ | |
87f8eb97 JW |
5661 | if (e->X_op == O_constant && e->X_add_number & 0x7) |
5662 | return OPERAND_OUT_OF_RANGE; | |
800eeca4 JW |
5663 | case IA64_OPND_SOF: |
5664 | case IA64_OPND_SOL: | |
87f8eb97 JW |
5665 | if (e->X_op == O_constant) |
5666 | { | |
5667 | if ((bfd_vma) e->X_add_number <= 96) | |
5668 | return OPERAND_MATCH; | |
5669 | else | |
5670 | return OPERAND_OUT_OF_RANGE; | |
5671 | } | |
800eeca4 JW |
5672 | break; |
5673 | ||
5674 | case IA64_OPND_IMMU62: | |
5675 | if (e->X_op == O_constant) | |
542d6675 | 5676 | { |
800eeca4 | 5677 | if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << 62)) |
87f8eb97 JW |
5678 | return OPERAND_MATCH; |
5679 | else | |
5680 | return OPERAND_OUT_OF_RANGE; | |
542d6675 | 5681 | } |
197865e8 | 5682 | else |
542d6675 KH |
5683 | { |
5684 | /* FIXME -- need 62-bit relocation type */ | |
5685 | as_bad (_("62-bit relocation not yet implemented")); | |
5686 | } | |
800eeca4 JW |
5687 | break; |
5688 | ||
5689 | case IA64_OPND_IMMU64: | |
5690 | if (e->X_op == O_symbol || e->X_op == O_pseudo_fixup | |
5691 | || e->X_op == O_subtract) | |
5692 | { | |
5693 | fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups; | |
5694 | fix->code = BFD_RELOC_IA64_IMM64; | |
5695 | if (e->X_op != O_subtract) | |
5696 | { | |
5697 | fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code); | |
5698 | if (e->X_op == O_pseudo_fixup) | |
5699 | e->X_op = O_symbol; | |
5700 | } | |
5701 | ||
91d6fa6a | 5702 | fix->opnd = idesc->operands[res_index]; |
800eeca4 JW |
5703 | fix->expr = *e; |
5704 | fix->is_pcrel = 0; | |
5705 | ++CURR_SLOT.num_fixups; | |
87f8eb97 | 5706 | return OPERAND_MATCH; |
800eeca4 JW |
5707 | } |
5708 | else if (e->X_op == O_constant) | |
87f8eb97 | 5709 | return OPERAND_MATCH; |
800eeca4 JW |
5710 | break; |
5711 | ||
59cf82fe L |
5712 | case IA64_OPND_IMMU5b: |
5713 | if (e->X_op == O_constant) | |
5714 | { | |
5715 | val = e->X_add_number; | |
5716 | if (val >= 32 && val <= 63) | |
5717 | return OPERAND_MATCH; | |
5718 | else | |
5719 | return OPERAND_OUT_OF_RANGE; | |
5720 | } | |
5721 | break; | |
5722 | ||
800eeca4 JW |
5723 | case IA64_OPND_CCNT5: |
5724 | case IA64_OPND_CNT5: | |
5725 | case IA64_OPND_CNT6: | |
5726 | case IA64_OPND_CPOS6a: | |
5727 | case IA64_OPND_CPOS6b: | |
5728 | case IA64_OPND_CPOS6c: | |
5729 | case IA64_OPND_IMMU2: | |
5730 | case IA64_OPND_IMMU7a: | |
5731 | case IA64_OPND_IMMU7b: | |
b3e14eda L |
5732 | case IA64_OPND_IMMU16: |
5733 | case IA64_OPND_IMMU19: | |
800eeca4 JW |
5734 | case IA64_OPND_IMMU21: |
5735 | case IA64_OPND_IMMU24: | |
5736 | case IA64_OPND_MBTYPE4: | |
5737 | case IA64_OPND_MHTYPE8: | |
5738 | case IA64_OPND_POS6: | |
91d6fa6a | 5739 | bits = operand_width (idesc->operands[res_index]); |
87f8eb97 JW |
5740 | if (e->X_op == O_constant) |
5741 | { | |
5742 | if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits)) | |
5743 | return OPERAND_MATCH; | |
5744 | else | |
5745 | return OPERAND_OUT_OF_RANGE; | |
5746 | } | |
800eeca4 JW |
5747 | break; |
5748 | ||
bf3ca999 | 5749 | case IA64_OPND_IMMU9: |
91d6fa6a | 5750 | bits = operand_width (idesc->operands[res_index]); |
87f8eb97 | 5751 | if (e->X_op == O_constant) |
542d6675 | 5752 | { |
87f8eb97 JW |
5753 | if ((bfd_vma) e->X_add_number < ((bfd_vma) 1 << bits)) |
5754 | { | |
5755 | int lobits = e->X_add_number & 0x3; | |
5756 | if (((bfd_vma) e->X_add_number & 0x3C) != 0 && lobits == 0) | |
5757 | e->X_add_number |= (bfd_vma) 0x3; | |
5758 | return OPERAND_MATCH; | |
5759 | } | |
5760 | else | |
5761 | return OPERAND_OUT_OF_RANGE; | |
542d6675 | 5762 | } |
bf3ca999 TW |
5763 | break; |
5764 | ||
800eeca4 JW |
5765 | case IA64_OPND_IMM44: |
5766 | /* least 16 bits must be zero */ | |
5767 | if ((e->X_add_number & 0xffff) != 0) | |
87f8eb97 JW |
5768 | /* XXX technically, this is wrong: we should not be issuing warning |
5769 | messages until we're sure this instruction pattern is going to | |
5770 | be used! */ | |
542d6675 | 5771 | as_warn (_("lower 16 bits of mask ignored")); |
800eeca4 | 5772 | |
87f8eb97 | 5773 | if (e->X_op == O_constant) |
542d6675 | 5774 | { |
87f8eb97 JW |
5775 | if (((e->X_add_number >= 0 |
5776 | && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 44)) | |
5777 | || (e->X_add_number < 0 | |
5778 | && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 44)))) | |
542d6675 | 5779 | { |
87f8eb97 JW |
5780 | /* sign-extend */ |
5781 | if (e->X_add_number >= 0 | |
5782 | && (e->X_add_number & ((bfd_vma) 1 << 43)) != 0) | |
5783 | { | |
5784 | e->X_add_number |= ~(((bfd_vma) 1 << 44) - 1); | |
5785 | } | |
5786 | return OPERAND_MATCH; | |
542d6675 | 5787 | } |
87f8eb97 JW |
5788 | else |
5789 | return OPERAND_OUT_OF_RANGE; | |
542d6675 | 5790 | } |
800eeca4 JW |
5791 | break; |
5792 | ||
5793 | case IA64_OPND_IMM17: | |
5794 | /* bit 0 is a don't care (pr0 is hardwired to 1) */ | |
87f8eb97 | 5795 | if (e->X_op == O_constant) |
542d6675 | 5796 | { |
87f8eb97 JW |
5797 | if (((e->X_add_number >= 0 |
5798 | && (bfd_vma) e->X_add_number < ((bfd_vma) 1 << 17)) | |
5799 | || (e->X_add_number < 0 | |
5800 | && (bfd_vma) -e->X_add_number <= ((bfd_vma) 1 << 17)))) | |
542d6675 | 5801 | { |
87f8eb97 JW |
5802 | /* sign-extend */ |
5803 | if (e->X_add_number >= 0 | |
5804 | && (e->X_add_number & ((bfd_vma) 1 << 16)) != 0) | |
5805 | { | |
5806 | e->X_add_number |= ~(((bfd_vma) 1 << 17) - 1); | |
5807 | } | |
5808 | return OPERAND_MATCH; | |
542d6675 | 5809 | } |
87f8eb97 JW |
5810 | else |
5811 | return OPERAND_OUT_OF_RANGE; | |
542d6675 | 5812 | } |
800eeca4 JW |
5813 | break; |
5814 | ||
5815 | case IA64_OPND_IMM14: | |
5816 | case IA64_OPND_IMM22: | |
5817 | relocatable = 1; | |
5818 | case IA64_OPND_IMM1: | |
5819 | case IA64_OPND_IMM8: | |
5820 | case IA64_OPND_IMM8U4: | |
5821 | case IA64_OPND_IMM8M1: | |
5822 | case IA64_OPND_IMM8M1U4: | |
5823 | case IA64_OPND_IMM8M1U8: | |
5824 | case IA64_OPND_IMM9a: | |
5825 | case IA64_OPND_IMM9b: | |
91d6fa6a | 5826 | bits = operand_width (idesc->operands[res_index]); |
800eeca4 JW |
5827 | if (relocatable && (e->X_op == O_symbol |
5828 | || e->X_op == O_subtract | |
5829 | || e->X_op == O_pseudo_fixup)) | |
5830 | { | |
5831 | fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups; | |
5832 | ||
91d6fa6a | 5833 | if (idesc->operands[res_index] == IA64_OPND_IMM14) |
800eeca4 JW |
5834 | fix->code = BFD_RELOC_IA64_IMM14; |
5835 | else | |
5836 | fix->code = BFD_RELOC_IA64_IMM22; | |
5837 | ||
5838 | if (e->X_op != O_subtract) | |
5839 | { | |
5840 | fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code); | |
5841 | if (e->X_op == O_pseudo_fixup) | |
5842 | e->X_op = O_symbol; | |
5843 | } | |
5844 | ||
91d6fa6a | 5845 | fix->opnd = idesc->operands[res_index]; |
800eeca4 JW |
5846 | fix->expr = *e; |
5847 | fix->is_pcrel = 0; | |
5848 | ++CURR_SLOT.num_fixups; | |
87f8eb97 | 5849 | return OPERAND_MATCH; |
800eeca4 JW |
5850 | } |
5851 | else if (e->X_op != O_constant | |
5852 | && ! (e->X_op == O_big && opnd == IA64_OPND_IMM8M1U8)) | |
87f8eb97 | 5853 | return OPERAND_MISMATCH; |
800eeca4 JW |
5854 | |
5855 | if (opnd == IA64_OPND_IMM8M1U4) | |
5856 | { | |
5857 | /* Zero is not valid for unsigned compares that take an adjusted | |
5858 | constant immediate range. */ | |
5859 | if (e->X_add_number == 0) | |
87f8eb97 | 5860 | return OPERAND_OUT_OF_RANGE; |
800eeca4 JW |
5861 | |
5862 | /* Sign-extend 32-bit unsigned numbers, so that the following range | |
5863 | checks will work. */ | |
5864 | val = e->X_add_number; | |
197865e8 KH |
5865 | if (((val & (~(bfd_vma) 0 << 32)) == 0) |
5866 | && ((val & ((bfd_vma) 1 << 31)) != 0)) | |
800eeca4 JW |
5867 | val = ((val << 32) >> 32); |
5868 | ||
5869 | /* Check for 0x100000000. This is valid because | |
5870 | 0x100000000-1 is the same as ((uint32_t) -1). */ | |
5871 | if (val == ((bfd_signed_vma) 1 << 32)) | |
87f8eb97 | 5872 | return OPERAND_MATCH; |
800eeca4 JW |
5873 | |
5874 | val = val - 1; | |
5875 | } | |
5876 | else if (opnd == IA64_OPND_IMM8M1U8) | |
5877 | { | |
5878 | /* Zero is not valid for unsigned compares that take an adjusted | |
5879 | constant immediate range. */ | |
5880 | if (e->X_add_number == 0) | |
87f8eb97 | 5881 | return OPERAND_OUT_OF_RANGE; |
800eeca4 JW |
5882 | |
5883 | /* Check for 0x10000000000000000. */ | |
5884 | if (e->X_op == O_big) | |
5885 | { | |
5886 | if (generic_bignum[0] == 0 | |
5887 | && generic_bignum[1] == 0 | |
5888 | && generic_bignum[2] == 0 | |
5889 | && generic_bignum[3] == 0 | |
5890 | && generic_bignum[4] == 1) | |
87f8eb97 | 5891 | return OPERAND_MATCH; |
800eeca4 | 5892 | else |
87f8eb97 | 5893 | return OPERAND_OUT_OF_RANGE; |
800eeca4 JW |
5894 | } |
5895 | else | |
5896 | val = e->X_add_number - 1; | |
5897 | } | |
5898 | else if (opnd == IA64_OPND_IMM8M1) | |
5899 | val = e->X_add_number - 1; | |
5900 | else if (opnd == IA64_OPND_IMM8U4) | |
5901 | { | |
5902 | /* Sign-extend 32-bit unsigned numbers, so that the following range | |
5903 | checks will work. */ | |
5904 | val = e->X_add_number; | |
197865e8 KH |
5905 | if (((val & (~(bfd_vma) 0 << 32)) == 0) |
5906 | && ((val & ((bfd_vma) 1 << 31)) != 0)) | |
800eeca4 JW |
5907 | val = ((val << 32) >> 32); |
5908 | } | |
5909 | else | |
5910 | val = e->X_add_number; | |
5911 | ||
2434f565 JW |
5912 | if ((val >= 0 && (bfd_vma) val < ((bfd_vma) 1 << (bits - 1))) |
5913 | || (val < 0 && (bfd_vma) -val <= ((bfd_vma) 1 << (bits - 1)))) | |
87f8eb97 JW |
5914 | return OPERAND_MATCH; |
5915 | else | |
5916 | return OPERAND_OUT_OF_RANGE; | |
800eeca4 JW |
5917 | |
5918 | case IA64_OPND_INC3: | |
5919 | /* +/- 1, 4, 8, 16 */ | |
5920 | val = e->X_add_number; | |
5921 | if (val < 0) | |
5922 | val = -val; | |
87f8eb97 JW |
5923 | if (e->X_op == O_constant) |
5924 | { | |
5925 | if ((val == 1 || val == 4 || val == 8 || val == 16)) | |
5926 | return OPERAND_MATCH; | |
5927 | else | |
5928 | return OPERAND_OUT_OF_RANGE; | |
5929 | } | |
800eeca4 JW |
5930 | break; |
5931 | ||
5932 | case IA64_OPND_TGT25: | |
5933 | case IA64_OPND_TGT25b: | |
5934 | case IA64_OPND_TGT25c: | |
5935 | case IA64_OPND_TGT64: | |
5936 | if (e->X_op == O_symbol) | |
5937 | { | |
5938 | fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups; | |
5939 | if (opnd == IA64_OPND_TGT25) | |
5940 | fix->code = BFD_RELOC_IA64_PCREL21F; | |
5941 | else if (opnd == IA64_OPND_TGT25b) | |
5942 | fix->code = BFD_RELOC_IA64_PCREL21M; | |
5943 | else if (opnd == IA64_OPND_TGT25c) | |
5944 | fix->code = BFD_RELOC_IA64_PCREL21B; | |
542d6675 | 5945 | else if (opnd == IA64_OPND_TGT64) |
c67e42c9 RH |
5946 | fix->code = BFD_RELOC_IA64_PCREL60B; |
5947 | else | |
5948 | abort (); | |
5949 | ||
800eeca4 | 5950 | fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code); |
91d6fa6a | 5951 | fix->opnd = idesc->operands[res_index]; |
800eeca4 JW |
5952 | fix->expr = *e; |
5953 | fix->is_pcrel = 1; | |
5954 | ++CURR_SLOT.num_fixups; | |
87f8eb97 | 5955 | return OPERAND_MATCH; |
800eeca4 JW |
5956 | } |
5957 | case IA64_OPND_TAG13: | |
5958 | case IA64_OPND_TAG13b: | |
5959 | switch (e->X_op) | |
5960 | { | |
5961 | case O_constant: | |
87f8eb97 | 5962 | return OPERAND_MATCH; |
800eeca4 JW |
5963 | |
5964 | case O_symbol: | |
5965 | fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups; | |
fa1cb89c | 5966 | /* There are no external relocs for TAG13/TAG13b fields, so we |
55cf6793 | 5967 | create a dummy reloc. This will not live past md_apply_fix. */ |
fa1cb89c JW |
5968 | fix->code = BFD_RELOC_UNUSED; |
5969 | fix->code = ia64_gen_real_reloc_type (e->X_op_symbol, fix->code); | |
91d6fa6a | 5970 | fix->opnd = idesc->operands[res_index]; |
800eeca4 JW |
5971 | fix->expr = *e; |
5972 | fix->is_pcrel = 1; | |
5973 | ++CURR_SLOT.num_fixups; | |
87f8eb97 | 5974 | return OPERAND_MATCH; |
800eeca4 JW |
5975 | |
5976 | default: | |
5977 | break; | |
5978 | } | |
5979 | break; | |
5980 | ||
a823923b RH |
5981 | case IA64_OPND_LDXMOV: |
5982 | fix = CURR_SLOT.fixup + CURR_SLOT.num_fixups; | |
5983 | fix->code = BFD_RELOC_IA64_LDXMOV; | |
91d6fa6a | 5984 | fix->opnd = idesc->operands[res_index]; |
a823923b RH |
5985 | fix->expr = *e; |
5986 | fix->is_pcrel = 0; | |
5987 | ++CURR_SLOT.num_fixups; | |
5988 | return OPERAND_MATCH; | |
5989 | ||
b3e14eda L |
5990 | case IA64_OPND_STRD5b: |
5991 | if (e->X_op == O_constant) | |
5992 | { | |
5993 | /* 5-bit signed scaled by 64 */ | |
3739860c | 5994 | if ((e->X_add_number <= ( 0xf << 6 )) |
b3e14eda L |
5995 | && (e->X_add_number >= -( 0x10 << 6 ))) |
5996 | { | |
3739860c | 5997 | |
b3e14eda L |
5998 | /* Must be a multiple of 64 */ |
5999 | if ((e->X_add_number & 0x3f) != 0) | |
6000 | as_warn (_("stride must be a multiple of 64; lower 6 bits ignored")); | |
6001 | ||
6002 | e->X_add_number &= ~ 0x3f; | |
6003 | return OPERAND_MATCH; | |
6004 | } | |
6005 | else | |
6006 | return OPERAND_OUT_OF_RANGE; | |
6007 | } | |
6008 | break; | |
6009 | case IA64_OPND_CNT6a: | |
6010 | if (e->X_op == O_constant) | |
6011 | { | |
6012 | /* 6-bit unsigned biased by 1 -- count 0 is meaningless */ | |
3739860c | 6013 | if ((e->X_add_number <= 64) |
b3e14eda L |
6014 | && (e->X_add_number > 0) ) |
6015 | { | |
6016 | return OPERAND_MATCH; | |
6017 | } | |
6018 | else | |
6019 | return OPERAND_OUT_OF_RANGE; | |
6020 | } | |
6021 | break; | |
6022 | ||
800eeca4 JW |
6023 | default: |
6024 | break; | |
6025 | } | |
87f8eb97 | 6026 | return OPERAND_MISMATCH; |
800eeca4 JW |
6027 | } |
6028 | ||
6029 | static int | |
5a49b8ac | 6030 | parse_operand (expressionS *e, int more) |
800eeca4 JW |
6031 | { |
6032 | int sep = '\0'; | |
6033 | ||
6034 | memset (e, 0, sizeof (*e)); | |
6035 | e->X_op = O_absent; | |
6036 | SKIP_WHITESPACE (); | |
cd42ff9c | 6037 | expression (e); |
e4e8248d JB |
6038 | sep = *input_line_pointer; |
6039 | if (more && (sep == ',' || sep == more)) | |
6040 | ++input_line_pointer; | |
800eeca4 JW |
6041 | return sep; |
6042 | } | |
6043 | ||
cd42ff9c AM |
6044 | static int |
6045 | parse_operand_and_eval (expressionS *e, int more) | |
6046 | { | |
6047 | int sep = parse_operand (e, more); | |
6048 | resolve_expression (e); | |
6049 | return sep; | |
6050 | } | |
6051 | ||
6052 | static int | |
6053 | parse_operand_maybe_eval (expressionS *e, int more, enum ia64_opnd op) | |
6054 | { | |
6055 | int sep = parse_operand (e, more); | |
6056 | switch (op) | |
6057 | { | |
6058 | case IA64_OPND_IMM14: | |
6059 | case IA64_OPND_IMM22: | |
6060 | case IA64_OPND_IMMU64: | |
6061 | case IA64_OPND_TGT25: | |
6062 | case IA64_OPND_TGT25b: | |
6063 | case IA64_OPND_TGT25c: | |
6064 | case IA64_OPND_TGT64: | |
6065 | case IA64_OPND_TAG13: | |
6066 | case IA64_OPND_TAG13b: | |
6067 | case IA64_OPND_LDXMOV: | |
6068 | break; | |
6069 | default: | |
6070 | resolve_expression (e); | |
6071 | break; | |
6072 | } | |
6073 | return sep; | |
6074 | } | |
6075 | ||
800eeca4 JW |
6076 | /* Returns the next entry in the opcode table that matches the one in |
6077 | IDESC, and frees the entry in IDESC. If no matching entry is | |
197865e8 | 6078 | found, NULL is returned instead. */ |
800eeca4 JW |
6079 | |
6080 | static struct ia64_opcode * | |
6081 | get_next_opcode (struct ia64_opcode *idesc) | |
6082 | { | |
6083 | struct ia64_opcode *next = ia64_find_next_opcode (idesc); | |
6084 | ia64_free_opcode (idesc); | |
6085 | return next; | |
6086 | } | |
6087 | ||
6088 | /* Parse the operands for the opcode and find the opcode variant that | |
6089 | matches the specified operands, or NULL if no match is possible. */ | |
542d6675 KH |
6090 | |
6091 | static struct ia64_opcode * | |
5a49b8ac | 6092 | parse_operands (struct ia64_opcode *idesc) |
800eeca4 JW |
6093 | { |
6094 | int i = 0, highest_unmatched_operand, num_operands = 0, num_outputs = 0; | |
87f8eb97 | 6095 | int error_pos, out_of_range_pos, curr_out_of_range_pos, sep = 0; |
4b09e828 JB |
6096 | int reg1, reg2; |
6097 | char reg_class; | |
800eeca4 | 6098 | enum ia64_opnd expected_operand = IA64_OPND_NIL; |
87f8eb97 | 6099 | enum operand_match_result result; |
800eeca4 JW |
6100 | char mnemonic[129]; |
6101 | char *first_arg = 0, *end, *saved_input_pointer; | |
6102 | unsigned int sof; | |
6103 | ||
9c2799c2 | 6104 | gas_assert (strlen (idesc->name) <= 128); |
800eeca4 JW |
6105 | |
6106 | strcpy (mnemonic, idesc->name); | |
60b9a617 JB |
6107 | if (idesc->operands[2] == IA64_OPND_SOF |
6108 | || idesc->operands[1] == IA64_OPND_SOF) | |
800eeca4 JW |
6109 | { |
6110 | /* To make the common idiom "alloc loc?=ar.pfs,0,1,0,0" work, we | |
6111 | can't parse the first operand until we have parsed the | |
6112 | remaining operands of the "alloc" instruction. */ | |
6113 | SKIP_WHITESPACE (); | |
6114 | first_arg = input_line_pointer; | |
6115 | end = strchr (input_line_pointer, '='); | |
6116 | if (!end) | |
6117 | { | |
ad4b42b4 | 6118 | as_bad (_("Expected separator `='")); |
800eeca4 JW |
6119 | return 0; |
6120 | } | |
6121 | input_line_pointer = end + 1; | |
6122 | ++i; | |
6123 | ++num_outputs; | |
6124 | } | |
6125 | ||
d3156ecc | 6126 | for (; ; ++i) |
800eeca4 | 6127 | { |
3739860c | 6128 | if (i < NELEMS (CURR_SLOT.opnd)) |
d3156ecc | 6129 | { |
cd42ff9c AM |
6130 | sep = parse_operand_maybe_eval (CURR_SLOT.opnd + i, '=', |
6131 | idesc->operands[i]); | |
d3156ecc JB |
6132 | if (CURR_SLOT.opnd[i].X_op == O_absent) |
6133 | break; | |
6134 | } | |
6135 | else | |
6136 | { | |
6137 | expressionS dummy; | |
6138 | ||
e4e8248d | 6139 | sep = parse_operand (&dummy, '='); |
d3156ecc JB |
6140 | if (dummy.X_op == O_absent) |
6141 | break; | |
6142 | } | |
800eeca4 JW |
6143 | |
6144 | ++num_operands; | |
6145 | ||
6146 | if (sep != '=' && sep != ',') | |
6147 | break; | |
6148 | ||
6149 | if (sep == '=') | |
6150 | { | |
6151 | if (num_outputs > 0) | |
ad4b42b4 | 6152 | as_bad (_("Duplicate equal sign (=) in instruction")); |
800eeca4 JW |
6153 | else |
6154 | num_outputs = i + 1; | |
6155 | } | |
6156 | } | |
6157 | if (sep != '\0') | |
6158 | { | |
ad4b42b4 | 6159 | as_bad (_("Illegal operand separator `%c'"), sep); |
800eeca4 JW |
6160 | return 0; |
6161 | } | |
197865e8 | 6162 | |
60b9a617 JB |
6163 | if (idesc->operands[2] == IA64_OPND_SOF |
6164 | || idesc->operands[1] == IA64_OPND_SOF) | |
800eeca4 | 6165 | { |
ef0241e7 JB |
6166 | /* Map alloc r1=ar.pfs,i,l,o,r to alloc r1=ar.pfs,(i+l+o),(i+l),r. |
6167 | Note, however, that due to that mapping operand numbers in error | |
6168 | messages for any of the constant operands will not be correct. */ | |
800eeca4 | 6169 | know (strcmp (idesc->name, "alloc") == 0); |
ef0241e7 JB |
6170 | /* The first operand hasn't been parsed/initialized, yet (but |
6171 | num_operands intentionally doesn't account for that). */ | |
6172 | i = num_operands > 4 ? 2 : 1; | |
6173 | #define FORCE_CONST(n) (CURR_SLOT.opnd[n].X_op == O_constant \ | |
6174 | ? CURR_SLOT.opnd[n].X_add_number \ | |
6175 | : 0) | |
6176 | sof = set_regstack (FORCE_CONST(i), | |
6177 | FORCE_CONST(i + 1), | |
6178 | FORCE_CONST(i + 2), | |
6179 | FORCE_CONST(i + 3)); | |
6180 | #undef FORCE_CONST | |
6181 | ||
6182 | /* now we can parse the first arg: */ | |
6183 | saved_input_pointer = input_line_pointer; | |
6184 | input_line_pointer = first_arg; | |
cd42ff9c AM |
6185 | sep = parse_operand_maybe_eval (CURR_SLOT.opnd + 0, '=', |
6186 | idesc->operands[0]); | |
ef0241e7 JB |
6187 | if (sep != '=') |
6188 | --num_outputs; /* force error */ | |
6189 | input_line_pointer = saved_input_pointer; | |
6190 | ||
6191 | CURR_SLOT.opnd[i].X_add_number = sof; | |
6192 | if (CURR_SLOT.opnd[i + 1].X_op == O_constant | |
6193 | && CURR_SLOT.opnd[i + 2].X_op == O_constant) | |
6194 | CURR_SLOT.opnd[i + 1].X_add_number | |
6195 | = sof - CURR_SLOT.opnd[i + 2].X_add_number; | |
6196 | else | |
6197 | CURR_SLOT.opnd[i + 1].X_op = O_illegal; | |
6198 | CURR_SLOT.opnd[i + 2] = CURR_SLOT.opnd[i + 3]; | |
800eeca4 JW |
6199 | } |
6200 | ||
d3156ecc | 6201 | highest_unmatched_operand = -4; |
87f8eb97 JW |
6202 | curr_out_of_range_pos = -1; |
6203 | error_pos = 0; | |
800eeca4 JW |
6204 | for (; idesc; idesc = get_next_opcode (idesc)) |
6205 | { | |
6206 | if (num_outputs != idesc->num_outputs) | |
6207 | continue; /* mismatch in # of outputs */ | |
d3156ecc JB |
6208 | if (highest_unmatched_operand < 0) |
6209 | highest_unmatched_operand |= 1; | |
6210 | if (num_operands > NELEMS (idesc->operands) | |
6211 | || (num_operands < NELEMS (idesc->operands) | |
6212 | && idesc->operands[num_operands]) | |
6213 | || (num_operands > 0 && !idesc->operands[num_operands - 1])) | |
6214 | continue; /* mismatch in number of arguments */ | |
6215 | if (highest_unmatched_operand < 0) | |
6216 | highest_unmatched_operand |= 2; | |
800eeca4 JW |
6217 | |
6218 | CURR_SLOT.num_fixups = 0; | |
87f8eb97 JW |
6219 | |
6220 | /* Try to match all operands. If we see an out-of-range operand, | |
6221 | then continue trying to match the rest of the operands, since if | |
6222 | the rest match, then this idesc will give the best error message. */ | |
6223 | ||
6224 | out_of_range_pos = -1; | |
800eeca4 | 6225 | for (i = 0; i < num_operands && idesc->operands[i]; ++i) |
87f8eb97 JW |
6226 | { |
6227 | result = operand_match (idesc, i, CURR_SLOT.opnd + i); | |
6228 | if (result != OPERAND_MATCH) | |
6229 | { | |
6230 | if (result != OPERAND_OUT_OF_RANGE) | |
6231 | break; | |
6232 | if (out_of_range_pos < 0) | |
6233 | /* remember position of the first out-of-range operand: */ | |
6234 | out_of_range_pos = i; | |
6235 | } | |
6236 | } | |
800eeca4 | 6237 | |
87f8eb97 JW |
6238 | /* If we did not match all operands, or if at least one operand was |
6239 | out-of-range, then this idesc does not match. Keep track of which | |
6240 | idesc matched the most operands before failing. If we have two | |
6241 | idescs that failed at the same position, and one had an out-of-range | |
6242 | operand, then prefer the out-of-range operand. Thus if we have | |
6243 | "add r0=0x1000000,r1" we get an error saying the constant is out | |
6244 | of range instead of an error saying that the constant should have been | |
6245 | a register. */ | |
6246 | ||
6247 | if (i != num_operands || out_of_range_pos >= 0) | |
800eeca4 | 6248 | { |
87f8eb97 JW |
6249 | if (i > highest_unmatched_operand |
6250 | || (i == highest_unmatched_operand | |
6251 | && out_of_range_pos > curr_out_of_range_pos)) | |
800eeca4 JW |
6252 | { |
6253 | highest_unmatched_operand = i; | |
87f8eb97 JW |
6254 | if (out_of_range_pos >= 0) |
6255 | { | |
6256 | expected_operand = idesc->operands[out_of_range_pos]; | |
6257 | error_pos = out_of_range_pos; | |
6258 | } | |
6259 | else | |
6260 | { | |
6261 | expected_operand = idesc->operands[i]; | |
6262 | error_pos = i; | |
6263 | } | |
6264 | curr_out_of_range_pos = out_of_range_pos; | |
800eeca4 JW |
6265 | } |
6266 | continue; | |
6267 | } | |
6268 | ||
800eeca4 JW |
6269 | break; |
6270 | } | |
6271 | if (!idesc) | |
6272 | { | |
6273 | if (expected_operand) | |
ad4b42b4 | 6274 | as_bad (_("Operand %u of `%s' should be %s"), |
87f8eb97 | 6275 | error_pos + 1, mnemonic, |
800eeca4 | 6276 | elf64_ia64_operands[expected_operand].desc); |
d3156ecc | 6277 | else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 1)) |
ad4b42b4 | 6278 | as_bad (_("Wrong number of output operands")); |
d3156ecc | 6279 | else if (highest_unmatched_operand < 0 && !(highest_unmatched_operand & 2)) |
ad4b42b4 | 6280 | as_bad (_("Wrong number of input operands")); |
800eeca4 | 6281 | else |
ad4b42b4 | 6282 | as_bad (_("Operand mismatch")); |
800eeca4 JW |
6283 | return 0; |
6284 | } | |
4b09e828 JB |
6285 | |
6286 | /* Check that the instruction doesn't use | |
6287 | - r0, f0, or f1 as output operands | |
6288 | - the same predicate twice as output operands | |
6289 | - r0 as address of a base update load or store | |
6290 | - the same GR as output and address of a base update load | |
6291 | - two even- or two odd-numbered FRs as output operands of a floating | |
6292 | point parallel load. | |
6293 | At most two (conflicting) output (or output-like) operands can exist, | |
6294 | (floating point parallel loads have three outputs, but the base register, | |
6295 | if updated, cannot conflict with the actual outputs). */ | |
6296 | reg2 = reg1 = -1; | |
6297 | for (i = 0; i < num_operands; ++i) | |
6298 | { | |
6299 | int regno = 0; | |
6300 | ||
6301 | reg_class = 0; | |
6302 | switch (idesc->operands[i]) | |
6303 | { | |
6304 | case IA64_OPND_R1: | |
6305 | case IA64_OPND_R2: | |
6306 | case IA64_OPND_R3: | |
6307 | if (i < num_outputs) | |
6308 | { | |
6309 | if (CURR_SLOT.opnd[i].X_add_number == REG_GR) | |
6310 | reg_class = 'r'; | |
6311 | else if (reg1 < 0) | |
6312 | reg1 = CURR_SLOT.opnd[i].X_add_number; | |
6313 | else if (reg2 < 0) | |
6314 | reg2 = CURR_SLOT.opnd[i].X_add_number; | |
6315 | } | |
6316 | break; | |
6317 | case IA64_OPND_P1: | |
6318 | case IA64_OPND_P2: | |
6319 | if (i < num_outputs) | |
6320 | { | |
6321 | if (reg1 < 0) | |
6322 | reg1 = CURR_SLOT.opnd[i].X_add_number; | |
6323 | else if (reg2 < 0) | |
6324 | reg2 = CURR_SLOT.opnd[i].X_add_number; | |
6325 | } | |
6326 | break; | |
6327 | case IA64_OPND_F1: | |
6328 | case IA64_OPND_F2: | |
6329 | case IA64_OPND_F3: | |
6330 | case IA64_OPND_F4: | |
6331 | if (i < num_outputs) | |
6332 | { | |
6333 | if (CURR_SLOT.opnd[i].X_add_number >= REG_FR | |
6334 | && CURR_SLOT.opnd[i].X_add_number <= REG_FR + 1) | |
6335 | { | |
6336 | reg_class = 'f'; | |
6337 | regno = CURR_SLOT.opnd[i].X_add_number - REG_FR; | |
6338 | } | |
6339 | else if (reg1 < 0) | |
6340 | reg1 = CURR_SLOT.opnd[i].X_add_number; | |
6341 | else if (reg2 < 0) | |
6342 | reg2 = CURR_SLOT.opnd[i].X_add_number; | |
6343 | } | |
6344 | break; | |
6345 | case IA64_OPND_MR3: | |
6346 | if (idesc->flags & IA64_OPCODE_POSTINC) | |
6347 | { | |
6348 | if (CURR_SLOT.opnd[i].X_add_number == REG_GR) | |
6349 | reg_class = 'm'; | |
6350 | else if (reg1 < 0) | |
6351 | reg1 = CURR_SLOT.opnd[i].X_add_number; | |
6352 | else if (reg2 < 0) | |
6353 | reg2 = CURR_SLOT.opnd[i].X_add_number; | |
6354 | } | |
6355 | break; | |
6356 | default: | |
6357 | break; | |
6358 | } | |
6359 | switch (reg_class) | |
6360 | { | |
6361 | case 0: | |
6362 | break; | |
6363 | default: | |
ad4b42b4 | 6364 | as_warn (_("Invalid use of `%c%d' as output operand"), reg_class, regno); |
4b09e828 JB |
6365 | break; |
6366 | case 'm': | |
ad4b42b4 | 6367 | as_warn (_("Invalid use of `r%d' as base update address operand"), regno); |
4b09e828 JB |
6368 | break; |
6369 | } | |
6370 | } | |
6371 | if (reg1 == reg2) | |
6372 | { | |
6373 | if (reg1 >= REG_GR && reg1 <= REG_GR + 127) | |
6374 | { | |
6375 | reg1 -= REG_GR; | |
6376 | reg_class = 'r'; | |
6377 | } | |
6378 | else if (reg1 >= REG_P && reg1 <= REG_P + 63) | |
6379 | { | |
6380 | reg1 -= REG_P; | |
6381 | reg_class = 'p'; | |
6382 | } | |
6383 | else if (reg1 >= REG_FR && reg1 <= REG_FR + 127) | |
6384 | { | |
6385 | reg1 -= REG_FR; | |
6386 | reg_class = 'f'; | |
6387 | } | |
6388 | else | |
6389 | reg_class = 0; | |
6390 | if (reg_class) | |
ad4b42b4 | 6391 | as_warn (_("Invalid duplicate use of `%c%d'"), reg_class, reg1); |
4b09e828 JB |
6392 | } |
6393 | else if (((reg1 >= REG_FR && reg1 <= REG_FR + 31 | |
6394 | && reg2 >= REG_FR && reg2 <= REG_FR + 31) | |
6395 | || (reg1 >= REG_FR + 32 && reg1 <= REG_FR + 127 | |
6396 | && reg2 >= REG_FR + 32 && reg2 <= REG_FR + 127)) | |
6397 | && ! ((reg1 ^ reg2) & 1)) | |
ad4b42b4 | 6398 | as_warn (_("Invalid simultaneous use of `f%d' and `f%d'"), |
4b09e828 JB |
6399 | reg1 - REG_FR, reg2 - REG_FR); |
6400 | else if ((reg1 >= REG_FR && reg1 <= REG_FR + 31 | |
6401 | && reg2 >= REG_FR + 32 && reg2 <= REG_FR + 127) | |
6402 | || (reg1 >= REG_FR + 32 && reg1 <= REG_FR + 127 | |
6403 | && reg2 >= REG_FR && reg2 <= REG_FR + 31)) | |
ad4b42b4 | 6404 | as_warn (_("Dangerous simultaneous use of `f%d' and `f%d'"), |
4b09e828 | 6405 | reg1 - REG_FR, reg2 - REG_FR); |
800eeca4 JW |
6406 | return idesc; |
6407 | } | |
6408 | ||
6409 | static void | |
5a49b8ac | 6410 | build_insn (struct slot *slot, bfd_vma *insnp) |
800eeca4 JW |
6411 | { |
6412 | const struct ia64_operand *odesc, *o2desc; | |
6413 | struct ia64_opcode *idesc = slot->idesc; | |
2132e3a3 AM |
6414 | bfd_vma insn; |
6415 | bfd_signed_vma val; | |
800eeca4 JW |
6416 | const char *err; |
6417 | int i; | |
6418 | ||
6419 | insn = idesc->opcode | slot->qp_regno; | |
6420 | ||
6421 | for (i = 0; i < NELEMS (idesc->operands) && idesc->operands[i]; ++i) | |
6422 | { | |
c67e42c9 RH |
6423 | if (slot->opnd[i].X_op == O_register |
6424 | || slot->opnd[i].X_op == O_constant | |
6425 | || slot->opnd[i].X_op == O_index) | |
6426 | val = slot->opnd[i].X_add_number; | |
6427 | else if (slot->opnd[i].X_op == O_big) | |
800eeca4 | 6428 | { |
c67e42c9 | 6429 | /* This must be the value 0x10000000000000000. */ |
9c2799c2 | 6430 | gas_assert (idesc->operands[i] == IA64_OPND_IMM8M1U8); |
c67e42c9 RH |
6431 | val = 0; |
6432 | } | |
6433 | else | |
6434 | val = 0; | |
6435 | ||
6436 | switch (idesc->operands[i]) | |
6437 | { | |
6438 | case IA64_OPND_IMMU64: | |
800eeca4 JW |
6439 | *insnp++ = (val >> 22) & 0x1ffffffffffLL; |
6440 | insn |= (((val & 0x7f) << 13) | (((val >> 7) & 0x1ff) << 27) | |
6441 | | (((val >> 16) & 0x1f) << 22) | (((val >> 21) & 0x1) << 21) | |
6442 | | (((val >> 63) & 0x1) << 36)); | |
c67e42c9 RH |
6443 | continue; |
6444 | ||
6445 | case IA64_OPND_IMMU62: | |
542d6675 KH |
6446 | val &= 0x3fffffffffffffffULL; |
6447 | if (val != slot->opnd[i].X_add_number) | |
6448 | as_warn (_("Value truncated to 62 bits")); | |
6449 | *insnp++ = (val >> 21) & 0x1ffffffffffLL; | |
6450 | insn |= (((val & 0xfffff) << 6) | (((val >> 20) & 0x1) << 36)); | |
c67e42c9 | 6451 | continue; |
800eeca4 | 6452 | |
c67e42c9 RH |
6453 | case IA64_OPND_TGT64: |
6454 | val >>= 4; | |
6455 | *insnp++ = ((val >> 20) & 0x7fffffffffLL) << 2; | |
6456 | insn |= ((((val >> 59) & 0x1) << 36) | |
6457 | | (((val >> 0) & 0xfffff) << 13)); | |
6458 | continue; | |
800eeca4 | 6459 | |
c67e42c9 RH |
6460 | case IA64_OPND_AR3: |
6461 | val -= REG_AR; | |
6462 | break; | |
6463 | ||
6464 | case IA64_OPND_B1: | |
6465 | case IA64_OPND_B2: | |
6466 | val -= REG_BR; | |
6467 | break; | |
6468 | ||
6469 | case IA64_OPND_CR3: | |
6470 | val -= REG_CR; | |
6471 | break; | |
6472 | ||
b3e14eda L |
6473 | case IA64_OPND_DAHR3: |
6474 | val -= REG_DAHR; | |
6475 | break; | |
6476 | ||
c67e42c9 RH |
6477 | case IA64_OPND_F1: |
6478 | case IA64_OPND_F2: | |
6479 | case IA64_OPND_F3: | |
6480 | case IA64_OPND_F4: | |
6481 | val -= REG_FR; | |
6482 | break; | |
6483 | ||
6484 | case IA64_OPND_P1: | |
6485 | case IA64_OPND_P2: | |
6486 | val -= REG_P; | |
6487 | break; | |
6488 | ||
6489 | case IA64_OPND_R1: | |
6490 | case IA64_OPND_R2: | |
6491 | case IA64_OPND_R3: | |
6492 | case IA64_OPND_R3_2: | |
6493 | case IA64_OPND_CPUID_R3: | |
6494 | case IA64_OPND_DBR_R3: | |
6495 | case IA64_OPND_DTR_R3: | |
6496 | case IA64_OPND_ITR_R3: | |
6497 | case IA64_OPND_IBR_R3: | |
6498 | case IA64_OPND_MR3: | |
6499 | case IA64_OPND_MSR_R3: | |
6500 | case IA64_OPND_PKR_R3: | |
6501 | case IA64_OPND_PMC_R3: | |
6502 | case IA64_OPND_PMD_R3: | |
b3e14eda | 6503 | case IA64_OPND_DAHR_R3: |
197865e8 | 6504 | case IA64_OPND_RR_R3: |
c67e42c9 RH |
6505 | val -= REG_GR; |
6506 | break; | |
6507 | ||
6508 | default: | |
6509 | break; | |
6510 | } | |
6511 | ||
6512 | odesc = elf64_ia64_operands + idesc->operands[i]; | |
6513 | err = (*odesc->insert) (odesc, val, &insn); | |
6514 | if (err) | |
6515 | as_bad_where (slot->src_file, slot->src_line, | |
ad4b42b4 | 6516 | _("Bad operand value: %s"), err); |
c67e42c9 RH |
6517 | if (idesc->flags & IA64_OPCODE_PSEUDO) |
6518 | { | |
6519 | if ((idesc->flags & IA64_OPCODE_F2_EQ_F3) | |
6520 | && odesc == elf64_ia64_operands + IA64_OPND_F3) | |
6521 | { | |
6522 | o2desc = elf64_ia64_operands + IA64_OPND_F2; | |
6523 | (*o2desc->insert) (o2desc, val, &insn); | |
800eeca4 | 6524 | } |
c67e42c9 RH |
6525 | if ((idesc->flags & IA64_OPCODE_LEN_EQ_64MCNT) |
6526 | && (odesc == elf64_ia64_operands + IA64_OPND_CPOS6a | |
6527 | || odesc == elf64_ia64_operands + IA64_OPND_POS6)) | |
800eeca4 | 6528 | { |
c67e42c9 RH |
6529 | o2desc = elf64_ia64_operands + IA64_OPND_LEN6; |
6530 | (*o2desc->insert) (o2desc, 64 - val, &insn); | |
800eeca4 JW |
6531 | } |
6532 | } | |
6533 | } | |
6534 | *insnp = insn; | |
6535 | } | |
6536 | ||
6537 | static void | |
5a49b8ac | 6538 | emit_one_bundle (void) |
800eeca4 | 6539 | { |
f4660e2c | 6540 | int manual_bundling_off = 0, manual_bundling = 0; |
800eeca4 JW |
6541 | enum ia64_unit required_unit, insn_unit = 0; |
6542 | enum ia64_insn_type type[3], insn_type; | |
d3ce72d0 | 6543 | unsigned int template_val, orig_template; |
542d6675 | 6544 | bfd_vma insn[3] = { -1, -1, -1 }; |
800eeca4 JW |
6545 | struct ia64_opcode *idesc; |
6546 | int end_of_insn_group = 0, user_template = -1; | |
9b505842 | 6547 | int n, i, j, first, curr, last_slot; |
800eeca4 JW |
6548 | bfd_vma t0 = 0, t1 = 0; |
6549 | struct label_fix *lfix; | |
07a53e5c | 6550 | bfd_boolean mark_label; |
800eeca4 JW |
6551 | struct insn_fix *ifix; |
6552 | char mnemonic[16]; | |
6553 | fixS *fix; | |
6554 | char *f; | |
5a9ff93d | 6555 | int addr_mod; |
800eeca4 JW |
6556 | |
6557 | first = (md.curr_slot + NUM_SLOTS - md.num_slots_in_use) % NUM_SLOTS; | |
c13781b8 | 6558 | know (first >= 0 && first < NUM_SLOTS); |
800eeca4 JW |
6559 | n = MIN (3, md.num_slots_in_use); |
6560 | ||
6561 | /* Determine template: user user_template if specified, best match | |
542d6675 | 6562 | otherwise: */ |
800eeca4 JW |
6563 | |
6564 | if (md.slot[first].user_template >= 0) | |
d3ce72d0 | 6565 | user_template = template_val = md.slot[first].user_template; |
800eeca4 JW |
6566 | else |
6567 | { | |
032efc85 | 6568 | /* Auto select appropriate template. */ |
800eeca4 JW |
6569 | memset (type, 0, sizeof (type)); |
6570 | curr = first; | |
6571 | for (i = 0; i < n; ++i) | |
6572 | { | |
032efc85 RH |
6573 | if (md.slot[curr].label_fixups && i != 0) |
6574 | break; | |
800eeca4 JW |
6575 | type[i] = md.slot[curr].idesc->type; |
6576 | curr = (curr + 1) % NUM_SLOTS; | |
6577 | } | |
d3ce72d0 | 6578 | template_val = best_template[type[0]][type[1]][type[2]]; |
800eeca4 JW |
6579 | } |
6580 | ||
542d6675 | 6581 | /* initialize instructions with appropriate nops: */ |
800eeca4 | 6582 | for (i = 0; i < 3; ++i) |
d3ce72d0 | 6583 | insn[i] = nop[ia64_templ_desc[template_val].exec_unit[i]]; |
800eeca4 JW |
6584 | |
6585 | f = frag_more (16); | |
6586 | ||
5a9ff93d JW |
6587 | /* Check to see if this bundle is at an offset that is a multiple of 16-bytes |
6588 | from the start of the frag. */ | |
6589 | addr_mod = frag_now_fix () & 15; | |
6590 | if (frag_now->has_code && frag_now->insn_addr != addr_mod) | |
6591 | as_bad (_("instruction address is not a multiple of 16")); | |
6592 | frag_now->insn_addr = addr_mod; | |
6593 | frag_now->has_code = 1; | |
6594 | ||
542d6675 | 6595 | /* now fill in slots with as many insns as possible: */ |
800eeca4 JW |
6596 | curr = first; |
6597 | idesc = md.slot[curr].idesc; | |
6598 | end_of_insn_group = 0; | |
9b505842 | 6599 | last_slot = -1; |
800eeca4 JW |
6600 | for (i = 0; i < 3 && md.num_slots_in_use > 0; ++i) |
6601 | { | |
d6e78c11 | 6602 | /* If we have unwind records, we may need to update some now. */ |
75214fb0 JB |
6603 | unw_rec_list *ptr = md.slot[curr].unwind_record; |
6604 | unw_rec_list *end_ptr = NULL; | |
6605 | ||
d6e78c11 JW |
6606 | if (ptr) |
6607 | { | |
6608 | /* Find the last prologue/body record in the list for the current | |
6609 | insn, and set the slot number for all records up to that point. | |
6610 | This needs to be done now, because prologue/body records refer to | |
6611 | the current point, not the point after the instruction has been | |
6612 | issued. This matters because there may have been nops emitted | |
6613 | meanwhile. Any non-prologue non-body record followed by a | |
6614 | prologue/body record must also refer to the current point. */ | |
75214fb0 JB |
6615 | unw_rec_list *last_ptr; |
6616 | ||
6617 | for (j = 1; end_ptr == NULL && j < md.num_slots_in_use; ++j) | |
6618 | end_ptr = md.slot[(curr + j) % NUM_SLOTS].unwind_record; | |
6619 | for (last_ptr = NULL; ptr != end_ptr; ptr = ptr->next) | |
d6e78c11 JW |
6620 | if (ptr->r.type == prologue || ptr->r.type == prologue_gr |
6621 | || ptr->r.type == body) | |
6622 | last_ptr = ptr; | |
6623 | if (last_ptr) | |
6624 | { | |
6625 | /* Make last_ptr point one after the last prologue/body | |
6626 | record. */ | |
6627 | last_ptr = last_ptr->next; | |
6628 | for (ptr = md.slot[curr].unwind_record; ptr != last_ptr; | |
6629 | ptr = ptr->next) | |
6630 | { | |
6631 | ptr->slot_number = (unsigned long) f + i; | |
6632 | ptr->slot_frag = frag_now; | |
6633 | } | |
6634 | /* Remove the initialized records, so that we won't accidentally | |
6635 | update them again if we insert a nop and continue. */ | |
6636 | md.slot[curr].unwind_record = last_ptr; | |
6637 | } | |
6638 | } | |
e0c9811a | 6639 | |
f4660e2c JB |
6640 | manual_bundling_off = md.slot[curr].manual_bundling_off; |
6641 | if (md.slot[curr].manual_bundling_on) | |
800eeca4 | 6642 | { |
f4660e2c JB |
6643 | if (curr == first) |
6644 | manual_bundling = 1; | |
800eeca4 | 6645 | else |
f4660e2c JB |
6646 | break; /* Need to start a new bundle. */ |
6647 | } | |
6648 | ||
744b6414 JW |
6649 | /* If this instruction specifies a template, then it must be the first |
6650 | instruction of a bundle. */ | |
6651 | if (curr != first && md.slot[curr].user_template >= 0) | |
6652 | break; | |
6653 | ||
f4660e2c JB |
6654 | if (idesc->flags & IA64_OPCODE_SLOT2) |
6655 | { | |
6656 | if (manual_bundling && !manual_bundling_off) | |
6657 | { | |
6658 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6659 | _("`%s' must be last in bundle"), idesc->name); |
f4660e2c JB |
6660 | if (i < 2) |
6661 | manual_bundling = -1; /* Suppress meaningless post-loop errors. */ | |
6662 | } | |
6663 | i = 2; | |
800eeca4 JW |
6664 | } |
6665 | if (idesc->flags & IA64_OPCODE_LAST) | |
6666 | { | |
2434f565 JW |
6667 | int required_slot; |
6668 | unsigned int required_template; | |
800eeca4 JW |
6669 | |
6670 | /* If we need a stop bit after an M slot, our only choice is | |
6671 | template 5 (M;;MI). If we need a stop bit after a B | |
6672 | slot, our only choice is to place it at the end of the | |
6673 | bundle, because the only available templates are MIB, | |
6674 | MBB, BBB, MMB, and MFB. We don't handle anything other | |
6675 | than M and B slots because these are the only kind of | |
6676 | instructions that can have the IA64_OPCODE_LAST bit set. */ | |
d3ce72d0 | 6677 | required_template = template_val; |
800eeca4 JW |
6678 | switch (idesc->type) |
6679 | { | |
6680 | case IA64_TYPE_M: | |
6681 | required_slot = 0; | |
6682 | required_template = 5; | |
6683 | break; | |
6684 | ||
6685 | case IA64_TYPE_B: | |
6686 | required_slot = 2; | |
6687 | break; | |
6688 | ||
6689 | default: | |
6690 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 NC |
6691 | _("Internal error: don't know how to force %s to end of instruction group"), |
6692 | idesc->name); | |
800eeca4 JW |
6693 | required_slot = i; |
6694 | break; | |
6695 | } | |
f4660e2c JB |
6696 | if (manual_bundling |
6697 | && (i > required_slot | |
6698 | || (required_slot == 2 && !manual_bundling_off) | |
6699 | || (user_template >= 0 | |
6700 | /* Changing from MMI to M;MI is OK. */ | |
d3ce72d0 | 6701 | && (template_val ^ required_template) > 1))) |
f4660e2c JB |
6702 | { |
6703 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6704 | _("`%s' must be last in instruction group"), |
f4660e2c JB |
6705 | idesc->name); |
6706 | if (i < 2 && required_slot == 2 && !manual_bundling_off) | |
6707 | manual_bundling = -1; /* Suppress meaningless post-loop errors. */ | |
6708 | } | |
800eeca4 JW |
6709 | if (required_slot < i) |
6710 | /* Can't fit this instruction. */ | |
6711 | break; | |
6712 | ||
6713 | i = required_slot; | |
d3ce72d0 | 6714 | if (required_template != template_val) |
800eeca4 JW |
6715 | { |
6716 | /* If we switch the template, we need to reset the NOPs | |
6717 | after slot i. The slot-types of the instructions ahead | |
6718 | of i never change, so we don't need to worry about | |
6719 | changing NOPs in front of this slot. */ | |
6720 | for (j = i; j < 3; ++j) | |
6721 | insn[j] = nop[ia64_templ_desc[required_template].exec_unit[j]]; | |
53022e4a JW |
6722 | |
6723 | /* We just picked a template that includes the stop bit in the | |
6724 | middle, so we don't need another one emitted later. */ | |
6725 | md.slot[curr].end_of_insn_group = 0; | |
800eeca4 | 6726 | } |
d3ce72d0 | 6727 | template_val = required_template; |
800eeca4 JW |
6728 | } |
6729 | if (curr != first && md.slot[curr].label_fixups) | |
6730 | { | |
f4660e2c JB |
6731 | if (manual_bundling) |
6732 | { | |
6733 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6734 | _("Label must be first in a bundle")); |
f4660e2c JB |
6735 | manual_bundling = -1; /* Suppress meaningless post-loop errors. */ |
6736 | } | |
800eeca4 JW |
6737 | /* This insn must go into the first slot of a bundle. */ |
6738 | break; | |
6739 | } | |
6740 | ||
800eeca4 JW |
6741 | if (end_of_insn_group && md.num_slots_in_use >= 1) |
6742 | { | |
6743 | /* We need an instruction group boundary in the middle of a | |
6744 | bundle. See if we can switch to an other template with | |
6745 | an appropriate boundary. */ | |
6746 | ||
d3ce72d0 | 6747 | orig_template = template_val; |
800eeca4 JW |
6748 | if (i == 1 && (user_template == 4 |
6749 | || (user_template < 0 | |
d3ce72d0 | 6750 | && (ia64_templ_desc[template_val].exec_unit[0] |
800eeca4 JW |
6751 | == IA64_UNIT_M)))) |
6752 | { | |
d3ce72d0 | 6753 | template_val = 5; |
800eeca4 JW |
6754 | end_of_insn_group = 0; |
6755 | } | |
6756 | else if (i == 2 && (user_template == 0 | |
6757 | || (user_template < 0 | |
d3ce72d0 | 6758 | && (ia64_templ_desc[template_val].exec_unit[1] |
800eeca4 JW |
6759 | == IA64_UNIT_I))) |
6760 | /* This test makes sure we don't switch the template if | |
6761 | the next instruction is one that needs to be first in | |
6762 | an instruction group. Since all those instructions are | |
6763 | in the M group, there is no way such an instruction can | |
6764 | fit in this bundle even if we switch the template. The | |
6765 | reason we have to check for this is that otherwise we | |
6766 | may end up generating "MI;;I M.." which has the deadly | |
6767 | effect that the second M instruction is no longer the | |
f4660e2c | 6768 | first in the group! --davidm 99/12/16 */ |
800eeca4 JW |
6769 | && (idesc->flags & IA64_OPCODE_FIRST) == 0) |
6770 | { | |
d3ce72d0 | 6771 | template_val = 1; |
800eeca4 JW |
6772 | end_of_insn_group = 0; |
6773 | } | |
f4660e2c JB |
6774 | else if (i == 1 |
6775 | && user_template == 0 | |
6776 | && !(idesc->flags & IA64_OPCODE_FIRST)) | |
6777 | /* Use the next slot. */ | |
6778 | continue; | |
800eeca4 JW |
6779 | else if (curr != first) |
6780 | /* can't fit this insn */ | |
6781 | break; | |
6782 | ||
d3ce72d0 | 6783 | if (template_val != orig_template) |
800eeca4 JW |
6784 | /* if we switch the template, we need to reset the NOPs |
6785 | after slot i. The slot-types of the instructions ahead | |
6786 | of i never change, so we don't need to worry about | |
6787 | changing NOPs in front of this slot. */ | |
6788 | for (j = i; j < 3; ++j) | |
d3ce72d0 | 6789 | insn[j] = nop[ia64_templ_desc[template_val].exec_unit[j]]; |
800eeca4 | 6790 | } |
d3ce72d0 | 6791 | required_unit = ia64_templ_desc[template_val].exec_unit[i]; |
800eeca4 | 6792 | |
c10d9d8f | 6793 | /* resolve dynamic opcodes such as "break", "hint", and "nop": */ |
800eeca4 JW |
6794 | if (idesc->type == IA64_TYPE_DYN) |
6795 | { | |
97762d08 JB |
6796 | enum ia64_opnd opnd1, opnd2; |
6797 | ||
800eeca4 JW |
6798 | if ((strcmp (idesc->name, "nop") == 0) |
6799 | || (strcmp (idesc->name, "break") == 0)) | |
6800 | insn_unit = required_unit; | |
91d777ee L |
6801 | else if (strcmp (idesc->name, "hint") == 0) |
6802 | { | |
6803 | insn_unit = required_unit; | |
6804 | if (required_unit == IA64_UNIT_B) | |
6805 | { | |
6806 | switch (md.hint_b) | |
6807 | { | |
6808 | case hint_b_ok: | |
6809 | break; | |
6810 | case hint_b_warning: | |
ad4b42b4 | 6811 | as_warn (_("hint in B unit may be treated as nop")); |
91d777ee L |
6812 | break; |
6813 | case hint_b_error: | |
6814 | /* When manual bundling is off and there is no | |
6815 | user template, we choose a different unit so | |
6816 | that hint won't go into the current slot. We | |
6817 | will fill the current bundle with nops and | |
6818 | try to put hint into the next bundle. */ | |
6819 | if (!manual_bundling && user_template < 0) | |
6820 | insn_unit = IA64_UNIT_I; | |
6821 | else | |
ad4b42b4 | 6822 | as_bad (_("hint in B unit can't be used")); |
91d777ee L |
6823 | break; |
6824 | } | |
6825 | } | |
6826 | } | |
97762d08 JB |
6827 | else if (strcmp (idesc->name, "chk.s") == 0 |
6828 | || strcmp (idesc->name, "mov") == 0) | |
800eeca4 JW |
6829 | { |
6830 | insn_unit = IA64_UNIT_M; | |
97762d08 | 6831 | if (required_unit == IA64_UNIT_I |
d3ce72d0 | 6832 | || (required_unit == IA64_UNIT_F && template_val == 6)) |
800eeca4 JW |
6833 | insn_unit = IA64_UNIT_I; |
6834 | } | |
6835 | else | |
ad4b42b4 | 6836 | as_fatal (_("emit_one_bundle: unexpected dynamic op")); |
800eeca4 | 6837 | |
f9f21a03 L |
6838 | snprintf (mnemonic, sizeof (mnemonic), "%s.%c", |
6839 | idesc->name, "?imbfxx"[insn_unit]); | |
97762d08 JB |
6840 | opnd1 = idesc->operands[0]; |
6841 | opnd2 = idesc->operands[1]; | |
3d56ab85 | 6842 | ia64_free_opcode (idesc); |
97762d08 JB |
6843 | idesc = ia64_find_opcode (mnemonic); |
6844 | /* moves to/from ARs have collisions */ | |
6845 | if (opnd1 == IA64_OPND_AR3 || opnd2 == IA64_OPND_AR3) | |
6846 | { | |
6847 | while (idesc != NULL | |
6848 | && (idesc->operands[0] != opnd1 | |
6849 | || idesc->operands[1] != opnd2)) | |
6850 | idesc = get_next_opcode (idesc); | |
6851 | } | |
97762d08 | 6852 | md.slot[curr].idesc = idesc; |
800eeca4 JW |
6853 | } |
6854 | else | |
6855 | { | |
6856 | insn_type = idesc->type; | |
6857 | insn_unit = IA64_UNIT_NIL; | |
6858 | switch (insn_type) | |
6859 | { | |
6860 | case IA64_TYPE_A: | |
6861 | if (required_unit == IA64_UNIT_I || required_unit == IA64_UNIT_M) | |
6862 | insn_unit = required_unit; | |
6863 | break; | |
542d6675 | 6864 | case IA64_TYPE_X: insn_unit = IA64_UNIT_L; break; |
800eeca4 JW |
6865 | case IA64_TYPE_I: insn_unit = IA64_UNIT_I; break; |
6866 | case IA64_TYPE_M: insn_unit = IA64_UNIT_M; break; | |
6867 | case IA64_TYPE_B: insn_unit = IA64_UNIT_B; break; | |
6868 | case IA64_TYPE_F: insn_unit = IA64_UNIT_F; break; | |
6869 | default: break; | |
6870 | } | |
6871 | } | |
6872 | ||
6873 | if (insn_unit != required_unit) | |
9b505842 | 6874 | continue; /* Try next slot. */ |
800eeca4 | 6875 | |
07a53e5c RH |
6876 | /* Now is a good time to fix up the labels for this insn. */ |
6877 | mark_label = FALSE; | |
6878 | for (lfix = md.slot[curr].label_fixups; lfix; lfix = lfix->next) | |
6879 | { | |
6880 | S_SET_VALUE (lfix->sym, frag_now_fix () - 16); | |
6881 | symbol_set_frag (lfix->sym, frag_now); | |
6882 | mark_label |= lfix->dw2_mark_labels; | |
6883 | } | |
6884 | for (lfix = md.slot[curr].tag_fixups; lfix; lfix = lfix->next) | |
6885 | { | |
6886 | S_SET_VALUE (lfix->sym, frag_now_fix () - 16 + i); | |
6887 | symbol_set_frag (lfix->sym, frag_now); | |
6888 | } | |
6889 | ||
6890 | if (debug_type == DEBUG_DWARF2 | |
6891 | || md.slot[curr].loc_directive_seen | |
6892 | || mark_label) | |
196e8040 JW |
6893 | { |
6894 | bfd_vma addr = frag_now->fr_address + frag_now_fix () - 16 + i; | |
800eeca4 | 6895 | |
196e8040 | 6896 | md.slot[curr].loc_directive_seen = 0; |
07a53e5c RH |
6897 | if (mark_label) |
6898 | md.slot[curr].debug_line.flags |= DWARF2_FLAG_BASIC_BLOCK; | |
6899 | ||
196e8040 JW |
6900 | dwarf2_gen_line_info (addr, &md.slot[curr].debug_line); |
6901 | } | |
800eeca4 JW |
6902 | |
6903 | build_insn (md.slot + curr, insn + i); | |
6904 | ||
d6e78c11 JW |
6905 | ptr = md.slot[curr].unwind_record; |
6906 | if (ptr) | |
6907 | { | |
6908 | /* Set slot numbers for all remaining unwind records belonging to the | |
6909 | current insn. There can not be any prologue/body unwind records | |
6910 | here. */ | |
d6e78c11 JW |
6911 | for (; ptr != end_ptr; ptr = ptr->next) |
6912 | { | |
6913 | ptr->slot_number = (unsigned long) f + i; | |
6914 | ptr->slot_frag = frag_now; | |
6915 | } | |
6916 | md.slot[curr].unwind_record = NULL; | |
6917 | } | |
10850f29 | 6918 | |
800eeca4 JW |
6919 | for (j = 0; j < md.slot[curr].num_fixups; ++j) |
6920 | { | |
6921 | ifix = md.slot[curr].fixup + j; | |
5a080f89 | 6922 | fix = fix_new_exp (frag_now, frag_now_fix () - 16 + i, 8, |
800eeca4 JW |
6923 | &ifix->expr, ifix->is_pcrel, ifix->code); |
6924 | fix->tc_fix_data.opnd = ifix->opnd; | |
800eeca4 JW |
6925 | fix->fx_file = md.slot[curr].src_file; |
6926 | fix->fx_line = md.slot[curr].src_line; | |
6927 | } | |
6928 | ||
6929 | end_of_insn_group = md.slot[curr].end_of_insn_group; | |
6930 | ||
9699c833 TG |
6931 | /* This adjustment to "i" must occur after the fix, otherwise the fix |
6932 | is assigned to the wrong slot, and the VMS linker complains. */ | |
6933 | if (required_unit == IA64_UNIT_L) | |
6934 | { | |
6935 | know (i == 1); | |
6936 | /* skip one slot for long/X-unit instructions */ | |
6937 | ++i; | |
6938 | } | |
6939 | --md.num_slots_in_use; | |
6940 | last_slot = i; | |
6941 | ||
542d6675 | 6942 | /* clear slot: */ |
800eeca4 JW |
6943 | ia64_free_opcode (md.slot[curr].idesc); |
6944 | memset (md.slot + curr, 0, sizeof (md.slot[curr])); | |
6945 | md.slot[curr].user_template = -1; | |
6946 | ||
6947 | if (manual_bundling_off) | |
6948 | { | |
6949 | manual_bundling = 0; | |
6950 | break; | |
6951 | } | |
6952 | curr = (curr + 1) % NUM_SLOTS; | |
6953 | idesc = md.slot[curr].idesc; | |
6954 | } | |
6abae71c JW |
6955 | |
6956 | /* A user template was specified, but the first following instruction did | |
6957 | not fit. This can happen with or without manual bundling. */ | |
6958 | if (md.num_slots_in_use > 0 && last_slot < 0) | |
6959 | { | |
6960 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6961 | _("`%s' does not fit into %s template"), |
d3ce72d0 | 6962 | idesc->name, ia64_templ_desc[template_val].name); |
6abae71c JW |
6963 | /* Drop first insn so we don't livelock. */ |
6964 | --md.num_slots_in_use; | |
6965 | know (curr == first); | |
6966 | ia64_free_opcode (md.slot[curr].idesc); | |
6967 | memset (md.slot + curr, 0, sizeof (md.slot[curr])); | |
6968 | md.slot[curr].user_template = -1; | |
6969 | } | |
6970 | else if (manual_bundling > 0) | |
800eeca4 JW |
6971 | { |
6972 | if (md.num_slots_in_use > 0) | |
ac025970 | 6973 | { |
9b505842 JB |
6974 | if (last_slot >= 2) |
6975 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6976 | _("`%s' does not fit into bundle"), idesc->name); |
9b505842 JB |
6977 | else |
6978 | { | |
6979 | const char *where; | |
6980 | ||
d3ce72d0 | 6981 | if (template_val == 2) |
9b505842 JB |
6982 | where = "X slot"; |
6983 | else if (last_slot == 0) | |
6984 | where = "slots 2 or 3"; | |
6985 | else | |
6986 | where = "slot 3"; | |
6987 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6988 | _("`%s' can't go in %s of %s template"), |
d3ce72d0 | 6989 | idesc->name, where, ia64_templ_desc[template_val].name); |
9b505842 | 6990 | } |
ac025970 | 6991 | } |
800eeca4 JW |
6992 | else |
6993 | as_bad_where (md.slot[curr].src_file, md.slot[curr].src_line, | |
ad4b42b4 | 6994 | _("Missing '}' at end of file")); |
800eeca4 | 6995 | } |
3739860c | 6996 | |
800eeca4 JW |
6997 | know (md.num_slots_in_use < NUM_SLOTS); |
6998 | ||
d3ce72d0 | 6999 | t0 = end_of_insn_group | (template_val << 1) | (insn[0] << 5) | (insn[1] << 46); |
800eeca4 JW |
7000 | t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23); |
7001 | ||
44f5c83a JW |
7002 | number_to_chars_littleendian (f + 0, t0, 8); |
7003 | number_to_chars_littleendian (f + 8, t1, 8); | |
800eeca4 JW |
7004 | } |
7005 | ||
7006 | int | |
5a49b8ac | 7007 | md_parse_option (int c, char *arg) |
800eeca4 | 7008 | { |
7463c317 | 7009 | |
800eeca4 JW |
7010 | switch (c) |
7011 | { | |
c43c2cc5 | 7012 | /* Switches from the Intel assembler. */ |
44f5c83a | 7013 | case 'm': |
800eeca4 JW |
7014 | if (strcmp (arg, "ilp64") == 0 |
7015 | || strcmp (arg, "lp64") == 0 | |
7016 | || strcmp (arg, "p64") == 0) | |
7017 | { | |
7018 | md.flags |= EF_IA_64_ABI64; | |
7019 | } | |
7020 | else if (strcmp (arg, "ilp32") == 0) | |
7021 | { | |
7022 | md.flags &= ~EF_IA_64_ABI64; | |
7023 | } | |
7024 | else if (strcmp (arg, "le") == 0) | |
7025 | { | |
7026 | md.flags &= ~EF_IA_64_BE; | |
549f748d | 7027 | default_big_endian = 0; |
800eeca4 JW |
7028 | } |
7029 | else if (strcmp (arg, "be") == 0) | |
7030 | { | |
7031 | md.flags |= EF_IA_64_BE; | |
549f748d | 7032 | default_big_endian = 1; |
800eeca4 | 7033 | } |
970d6792 L |
7034 | else if (strncmp (arg, "unwind-check=", 13) == 0) |
7035 | { | |
7036 | arg += 13; | |
7037 | if (strcmp (arg, "warning") == 0) | |
7038 | md.unwind_check = unwind_check_warning; | |
7039 | else if (strcmp (arg, "error") == 0) | |
7040 | md.unwind_check = unwind_check_error; | |
7041 | else | |
7042 | return 0; | |
7043 | } | |
91d777ee L |
7044 | else if (strncmp (arg, "hint.b=", 7) == 0) |
7045 | { | |
7046 | arg += 7; | |
7047 | if (strcmp (arg, "ok") == 0) | |
7048 | md.hint_b = hint_b_ok; | |
7049 | else if (strcmp (arg, "warning") == 0) | |
7050 | md.hint_b = hint_b_warning; | |
7051 | else if (strcmp (arg, "error") == 0) | |
7052 | md.hint_b = hint_b_error; | |
7053 | else | |
7054 | return 0; | |
7055 | } | |
8c2fda1d L |
7056 | else if (strncmp (arg, "tune=", 5) == 0) |
7057 | { | |
7058 | arg += 5; | |
7059 | if (strcmp (arg, "itanium1") == 0) | |
7060 | md.tune = itanium1; | |
7061 | else if (strcmp (arg, "itanium2") == 0) | |
7062 | md.tune = itanium2; | |
7063 | else | |
7064 | return 0; | |
7065 | } | |
800eeca4 JW |
7066 | else |
7067 | return 0; | |
7068 | break; | |
7069 | ||
7070 | case 'N': | |
7071 | if (strcmp (arg, "so") == 0) | |
7072 | { | |
542d6675 | 7073 | /* Suppress signon message. */ |
800eeca4 JW |
7074 | } |
7075 | else if (strcmp (arg, "pi") == 0) | |
7076 | { | |
7077 | /* Reject privileged instructions. FIXME */ | |
7078 | } | |
7079 | else if (strcmp (arg, "us") == 0) | |
7080 | { | |
7081 | /* Allow union of signed and unsigned range. FIXME */ | |
7082 | } | |
7083 | else if (strcmp (arg, "close_fcalls") == 0) | |
7084 | { | |
7085 | /* Do not resolve global function calls. */ | |
7086 | } | |
7087 | else | |
7088 | return 0; | |
7089 | break; | |
7090 | ||
7091 | case 'C': | |
7092 | /* temp[="prefix"] Insert temporary labels into the object file | |
7093 | symbol table prefixed by "prefix". | |
7094 | Default prefix is ":temp:". | |
7095 | */ | |
7096 | break; | |
7097 | ||
7098 | case 'a': | |
800eeca4 JW |
7099 | /* indirect=<tgt> Assume unannotated indirect branches behavior |
7100 | according to <tgt> -- | |
7101 | exit: branch out from the current context (default) | |
7102 | labels: all labels in context may be branch targets | |
7103 | */ | |
85b40035 L |
7104 | if (strncmp (arg, "indirect=", 9) != 0) |
7105 | return 0; | |
800eeca4 JW |
7106 | break; |
7107 | ||
7108 | case 'x': | |
7109 | /* -X conflicts with an ignored option, use -x instead */ | |
7110 | md.detect_dv = 1; | |
7111 | if (!arg || strcmp (arg, "explicit") == 0) | |
542d6675 KH |
7112 | { |
7113 | /* set default mode to explicit */ | |
7114 | md.default_explicit_mode = 1; | |
7115 | break; | |
7116 | } | |
800eeca4 | 7117 | else if (strcmp (arg, "auto") == 0) |
542d6675 KH |
7118 | { |
7119 | md.default_explicit_mode = 0; | |
7120 | } | |
f1dab70d JB |
7121 | else if (strcmp (arg, "none") == 0) |
7122 | { | |
7123 | md.detect_dv = 0; | |
7124 | } | |
800eeca4 | 7125 | else if (strcmp (arg, "debug") == 0) |
542d6675 KH |
7126 | { |
7127 | md.debug_dv = 1; | |
7128 | } | |
800eeca4 | 7129 | else if (strcmp (arg, "debugx") == 0) |
542d6675 KH |
7130 | { |
7131 | md.default_explicit_mode = 1; | |
7132 | md.debug_dv = 1; | |
7133 | } | |
f1dab70d JB |
7134 | else if (strcmp (arg, "debugn") == 0) |
7135 | { | |
7136 | md.debug_dv = 1; | |
7137 | md.detect_dv = 0; | |
7138 | } | |
800eeca4 | 7139 | else |
542d6675 KH |
7140 | { |
7141 | as_bad (_("Unrecognized option '-x%s'"), arg); | |
7142 | } | |
800eeca4 JW |
7143 | break; |
7144 | ||
7145 | case 'S': | |
7146 | /* nops Print nops statistics. */ | |
7147 | break; | |
7148 | ||
c43c2cc5 JW |
7149 | /* GNU specific switches for gcc. */ |
7150 | case OPTION_MCONSTANT_GP: | |
7151 | md.flags |= EF_IA_64_CONS_GP; | |
7152 | break; | |
7153 | ||
7154 | case OPTION_MAUTO_PIC: | |
7155 | md.flags |= EF_IA_64_NOFUNCDESC_CONS_GP; | |
7156 | break; | |
7157 | ||
800eeca4 JW |
7158 | default: |
7159 | return 0; | |
7160 | } | |
7161 | ||
7162 | return 1; | |
7163 | } | |
7164 | ||
7165 | void | |
5a49b8ac | 7166 | md_show_usage (FILE *stream) |
800eeca4 | 7167 | { |
542d6675 | 7168 | fputs (_("\ |
800eeca4 | 7169 | IA-64 options:\n\ |
6290819d NC |
7170 | --mconstant-gp mark output file as using the constant-GP model\n\ |
7171 | (sets ELF header flag EF_IA_64_CONS_GP)\n\ | |
7172 | --mauto-pic mark output file as using the constant-GP model\n\ | |
7173 | without function descriptors (sets ELF header flag\n\ | |
7174 | EF_IA_64_NOFUNCDESC_CONS_GP)\n\ | |
44f5c83a JW |
7175 | -milp32|-milp64|-mlp64|-mp64 select data model (default -mlp64)\n\ |
7176 | -mle | -mbe select little- or big-endian byte order (default -mle)\n\ | |
8c2fda1d L |
7177 | -mtune=[itanium1|itanium2]\n\ |
7178 | tune for a specific CPU (default -mtune=itanium2)\n\ | |
970d6792 L |
7179 | -munwind-check=[warning|error]\n\ |
7180 | unwind directive check (default -munwind-check=warning)\n\ | |
91d777ee L |
7181 | -mhint.b=[ok|warning|error]\n\ |
7182 | hint.b check (default -mhint.b=error)\n\ | |
a1727c1a NC |
7183 | -x | -xexplicit turn on dependency violation checking\n"), stream); |
7184 | /* Note for translators: "automagically" can be translated as "automatically" here. */ | |
7185 | fputs (_("\ | |
f1dab70d JB |
7186 | -xauto automagically remove dependency violations (default)\n\ |
7187 | -xnone turn off dependency violation checking\n\ | |
7188 | -xdebug debug dependency violation checker\n\ | |
7189 | -xdebugn debug dependency violation checker but turn off\n\ | |
7190 | dependency violation checking\n\ | |
7191 | -xdebugx debug dependency violation checker and turn on\n\ | |
7192 | dependency violation checking\n"), | |
800eeca4 JW |
7193 | stream); |
7194 | } | |
7195 | ||
acebd4ce | 7196 | void |
5a49b8ac | 7197 | ia64_after_parse_args (void) |
acebd4ce AS |
7198 | { |
7199 | if (debug_type == DEBUG_STABS) | |
7200 | as_fatal (_("--gstabs is not supported for ia64")); | |
7201 | } | |
7202 | ||
44576e1f RH |
7203 | /* Return true if TYPE fits in TEMPL at SLOT. */ |
7204 | ||
7205 | static int | |
800eeca4 JW |
7206 | match (int templ, int type, int slot) |
7207 | { | |
7208 | enum ia64_unit unit; | |
7209 | int result; | |
7210 | ||
7211 | unit = ia64_templ_desc[templ].exec_unit[slot]; | |
7212 | switch (type) | |
7213 | { | |
7214 | case IA64_TYPE_DYN: result = 1; break; /* for nop and break */ | |
7215 | case IA64_TYPE_A: | |
7216 | result = (unit == IA64_UNIT_I || unit == IA64_UNIT_M); | |
7217 | break; | |
7218 | case IA64_TYPE_X: result = (unit == IA64_UNIT_L); break; | |
7219 | case IA64_TYPE_I: result = (unit == IA64_UNIT_I); break; | |
7220 | case IA64_TYPE_M: result = (unit == IA64_UNIT_M); break; | |
7221 | case IA64_TYPE_B: result = (unit == IA64_UNIT_B); break; | |
7222 | case IA64_TYPE_F: result = (unit == IA64_UNIT_F); break; | |
7223 | default: result = 0; break; | |
7224 | } | |
7225 | return result; | |
7226 | } | |
7227 | ||
7c06efaa JW |
7228 | /* For Itanium 1, add a bit of extra goodness if a nop of type F or B would fit |
7229 | in TEMPL at SLOT. For Itanium 2, add a bit of extra goodness if a nop of | |
7230 | type M or I would fit in TEMPL at SLOT. */ | |
44576e1f RH |
7231 | |
7232 | static inline int | |
7233 | extra_goodness (int templ, int slot) | |
7234 | { | |
8c2fda1d L |
7235 | switch (md.tune) |
7236 | { | |
7237 | case itanium1: | |
7238 | if (slot == 1 && match (templ, IA64_TYPE_F, slot)) | |
7239 | return 2; | |
7240 | else if (slot == 2 && match (templ, IA64_TYPE_B, slot)) | |
7241 | return 1; | |
7242 | else | |
7243 | return 0; | |
7244 | break; | |
7245 | case itanium2: | |
7246 | if (match (templ, IA64_TYPE_M, slot) | |
7247 | || match (templ, IA64_TYPE_I, slot)) | |
7248 | /* Favor M- and I-unit NOPs. We definitely want to avoid | |
7249 | F-unit and B-unit may cause split-issue or less-than-optimal | |
7250 | branch-prediction. */ | |
7251 | return 2; | |
7252 | else | |
7253 | return 0; | |
7254 | break; | |
7255 | default: | |
7256 | abort (); | |
7257 | return 0; | |
7258 | } | |
44576e1f RH |
7259 | } |
7260 | ||
800eeca4 JW |
7261 | /* This function is called once, at assembler startup time. It sets |
7262 | up all the tables, etc. that the MD part of the assembler will need | |
7263 | that can be determined before arguments are parsed. */ | |
7264 | void | |
5a49b8ac | 7265 | md_begin (void) |
800eeca4 | 7266 | { |
8b84be9d | 7267 | int i, j, k, t, goodness, best, ok; |
800eeca4 JW |
7268 | const char *err; |
7269 | char name[8]; | |
7270 | ||
7271 | md.auto_align = 1; | |
7272 | md.explicit_mode = md.default_explicit_mode; | |
7273 | ||
7274 | bfd_set_section_alignment (stdoutput, text_section, 4); | |
7275 | ||
0234cb7c | 7276 | /* Make sure function pointers get initialized. */ |
10a98291 | 7277 | target_big_endian = -1; |
549f748d | 7278 | dot_byteorder (default_big_endian); |
10a98291 | 7279 | |
35f5df7f L |
7280 | alias_hash = hash_new (); |
7281 | alias_name_hash = hash_new (); | |
7282 | secalias_hash = hash_new (); | |
7283 | secalias_name_hash = hash_new (); | |
7284 | ||
13ae64f3 JJ |
7285 | pseudo_func[FUNC_DTP_MODULE].u.sym = |
7286 | symbol_new (".<dtpmod>", undefined_section, FUNC_DTP_MODULE, | |
7287 | &zero_address_frag); | |
7288 | ||
7289 | pseudo_func[FUNC_DTP_RELATIVE].u.sym = | |
7290 | symbol_new (".<dtprel>", undefined_section, FUNC_DTP_RELATIVE, | |
7291 | &zero_address_frag); | |
7292 | ||
800eeca4 | 7293 | pseudo_func[FUNC_FPTR_RELATIVE].u.sym = |
542d6675 KH |
7294 | symbol_new (".<fptr>", undefined_section, FUNC_FPTR_RELATIVE, |
7295 | &zero_address_frag); | |
800eeca4 JW |
7296 | |
7297 | pseudo_func[FUNC_GP_RELATIVE].u.sym = | |
542d6675 KH |
7298 | symbol_new (".<gprel>", undefined_section, FUNC_GP_RELATIVE, |
7299 | &zero_address_frag); | |
800eeca4 JW |
7300 | |
7301 | pseudo_func[FUNC_LT_RELATIVE].u.sym = | |
542d6675 KH |
7302 | symbol_new (".<ltoff>", undefined_section, FUNC_LT_RELATIVE, |
7303 | &zero_address_frag); | |
800eeca4 | 7304 | |
fa2c7eff RH |
7305 | pseudo_func[FUNC_LT_RELATIVE_X].u.sym = |
7306 | symbol_new (".<ltoffx>", undefined_section, FUNC_LT_RELATIVE_X, | |
7307 | &zero_address_frag); | |
7308 | ||
c67e42c9 | 7309 | pseudo_func[FUNC_PC_RELATIVE].u.sym = |
542d6675 KH |
7310 | symbol_new (".<pcrel>", undefined_section, FUNC_PC_RELATIVE, |
7311 | &zero_address_frag); | |
c67e42c9 | 7312 | |
800eeca4 | 7313 | pseudo_func[FUNC_PLT_RELATIVE].u.sym = |
542d6675 KH |
7314 | symbol_new (".<pltoff>", undefined_section, FUNC_PLT_RELATIVE, |
7315 | &zero_address_frag); | |
800eeca4 JW |
7316 | |
7317 | pseudo_func[FUNC_SEC_RELATIVE].u.sym = | |
542d6675 KH |
7318 | symbol_new (".<secrel>", undefined_section, FUNC_SEC_RELATIVE, |
7319 | &zero_address_frag); | |
800eeca4 JW |
7320 | |
7321 | pseudo_func[FUNC_SEG_RELATIVE].u.sym = | |
542d6675 KH |
7322 | symbol_new (".<segrel>", undefined_section, FUNC_SEG_RELATIVE, |
7323 | &zero_address_frag); | |
800eeca4 | 7324 | |
13ae64f3 JJ |
7325 | pseudo_func[FUNC_TP_RELATIVE].u.sym = |
7326 | symbol_new (".<tprel>", undefined_section, FUNC_TP_RELATIVE, | |
7327 | &zero_address_frag); | |
7328 | ||
800eeca4 | 7329 | pseudo_func[FUNC_LTV_RELATIVE].u.sym = |
542d6675 KH |
7330 | symbol_new (".<ltv>", undefined_section, FUNC_LTV_RELATIVE, |
7331 | &zero_address_frag); | |
800eeca4 JW |
7332 | |
7333 | pseudo_func[FUNC_LT_FPTR_RELATIVE].u.sym = | |
542d6675 KH |
7334 | symbol_new (".<ltoff.fptr>", undefined_section, FUNC_LT_FPTR_RELATIVE, |
7335 | &zero_address_frag); | |
800eeca4 | 7336 | |
13ae64f3 JJ |
7337 | pseudo_func[FUNC_LT_DTP_MODULE].u.sym = |
7338 | symbol_new (".<ltoff.dtpmod>", undefined_section, FUNC_LT_DTP_MODULE, | |
7339 | &zero_address_frag); | |
7340 | ||
7341 | pseudo_func[FUNC_LT_DTP_RELATIVE].u.sym = | |
7342 | symbol_new (".<ltoff.dptrel>", undefined_section, FUNC_LT_DTP_RELATIVE, | |
7343 | &zero_address_frag); | |
7344 | ||
7345 | pseudo_func[FUNC_LT_TP_RELATIVE].u.sym = | |
7346 | symbol_new (".<ltoff.tprel>", undefined_section, FUNC_LT_TP_RELATIVE, | |
7347 | &zero_address_frag); | |
7348 | ||
3969b680 RH |
7349 | pseudo_func[FUNC_IPLT_RELOC].u.sym = |
7350 | symbol_new (".<iplt>", undefined_section, FUNC_IPLT_RELOC, | |
7351 | &zero_address_frag); | |
7352 | ||
9d0e8497 TG |
7353 | #ifdef TE_VMS |
7354 | pseudo_func[FUNC_SLOTCOUNT_RELOC].u.sym = | |
7355 | symbol_new (".<slotcount>", undefined_section, FUNC_SLOTCOUNT_RELOC, | |
7356 | &zero_address_frag); | |
7357 | #endif | |
7358 | ||
f6fe78d6 JW |
7359 | if (md.tune != itanium1) |
7360 | { | |
7361 | /* Convert MFI NOPs bundles into MMI NOPs bundles. */ | |
7362 | le_nop[0] = 0x8; | |
7363 | le_nop_stop[0] = 0x9; | |
7364 | } | |
7365 | ||
197865e8 | 7366 | /* Compute the table of best templates. We compute goodness as a |
8c2fda1d L |
7367 | base 4 value, in which each match counts for 3. Match-failures |
7368 | result in NOPs and we use extra_goodness() to pick the execution | |
7369 | units that are best suited for issuing the NOP. */ | |
800eeca4 JW |
7370 | for (i = 0; i < IA64_NUM_TYPES; ++i) |
7371 | for (j = 0; j < IA64_NUM_TYPES; ++j) | |
7372 | for (k = 0; k < IA64_NUM_TYPES; ++k) | |
7373 | { | |
7374 | best = 0; | |
7375 | for (t = 0; t < NELEMS (ia64_templ_desc); ++t) | |
7376 | { | |
7377 | goodness = 0; | |
7378 | if (match (t, i, 0)) | |
7379 | { | |
7380 | if (match (t, j, 1)) | |
7381 | { | |
286cee81 | 7382 | if ((t == 2 && j == IA64_TYPE_X) || match (t, k, 2)) |
44576e1f | 7383 | goodness = 3 + 3 + 3; |
800eeca4 | 7384 | else |
44576e1f | 7385 | goodness = 3 + 3 + extra_goodness (t, 2); |
800eeca4 JW |
7386 | } |
7387 | else if (match (t, j, 2)) | |
44576e1f | 7388 | goodness = 3 + 3 + extra_goodness (t, 1); |
800eeca4 | 7389 | else |
44576e1f RH |
7390 | { |
7391 | goodness = 3; | |
7392 | goodness += extra_goodness (t, 1); | |
7393 | goodness += extra_goodness (t, 2); | |
7394 | } | |
800eeca4 JW |
7395 | } |
7396 | else if (match (t, i, 1)) | |
7397 | { | |
286cee81 | 7398 | if ((t == 2 && i == IA64_TYPE_X) || match (t, j, 2)) |
44576e1f | 7399 | goodness = 3 + 3; |
800eeca4 | 7400 | else |
44576e1f | 7401 | goodness = 3 + extra_goodness (t, 2); |
800eeca4 JW |
7402 | } |
7403 | else if (match (t, i, 2)) | |
44576e1f | 7404 | goodness = 3 + extra_goodness (t, 1); |
800eeca4 JW |
7405 | |
7406 | if (goodness > best) | |
7407 | { | |
7408 | best = goodness; | |
7409 | best_template[i][j][k] = t; | |
7410 | } | |
7411 | } | |
7412 | } | |
7413 | ||
7c06efaa JW |
7414 | #ifdef DEBUG_TEMPLATES |
7415 | /* For debugging changes to the best_template calculations. We don't care | |
7416 | about combinations with invalid instructions, so start the loops at 1. */ | |
7417 | for (i = 0; i < IA64_NUM_TYPES; ++i) | |
7418 | for (j = 0; j < IA64_NUM_TYPES; ++j) | |
7419 | for (k = 0; k < IA64_NUM_TYPES; ++k) | |
7420 | { | |
7421 | char type_letter[IA64_NUM_TYPES] = { 'n', 'a', 'i', 'm', 'b', 'f', | |
7422 | 'x', 'd' }; | |
7423 | fprintf (stderr, "%c%c%c %s\n", type_letter[i], type_letter[j], | |
7424 | type_letter[k], | |
7425 | ia64_templ_desc[best_template[i][j][k]].name); | |
7426 | } | |
7427 | #endif | |
7428 | ||
800eeca4 JW |
7429 | for (i = 0; i < NUM_SLOTS; ++i) |
7430 | md.slot[i].user_template = -1; | |
7431 | ||
7432 | md.pseudo_hash = hash_new (); | |
7433 | for (i = 0; i < NELEMS (pseudo_opcode); ++i) | |
7434 | { | |
7435 | err = hash_insert (md.pseudo_hash, pseudo_opcode[i].name, | |
7436 | (void *) (pseudo_opcode + i)); | |
7437 | if (err) | |
ad4b42b4 | 7438 | as_fatal (_("ia64.md_begin: can't hash `%s': %s"), |
800eeca4 JW |
7439 | pseudo_opcode[i].name, err); |
7440 | } | |
7441 | ||
7442 | md.reg_hash = hash_new (); | |
7443 | md.dynreg_hash = hash_new (); | |
7444 | md.const_hash = hash_new (); | |
7445 | md.entry_hash = hash_new (); | |
7446 | ||
542d6675 | 7447 | /* general registers: */ |
8b84be9d JB |
7448 | declare_register_set ("r", 128, REG_GR); |
7449 | declare_register ("gp", REG_GR + 1); | |
7450 | declare_register ("sp", REG_GR + 12); | |
7451 | declare_register ("tp", REG_GR + 13); | |
7452 | declare_register_set ("ret", 4, REG_GR + 8); | |
800eeca4 | 7453 | |
542d6675 | 7454 | /* floating point registers: */ |
8b84be9d JB |
7455 | declare_register_set ("f", 128, REG_FR); |
7456 | declare_register_set ("farg", 8, REG_FR + 8); | |
7457 | declare_register_set ("fret", 8, REG_FR + 8); | |
800eeca4 | 7458 | |
542d6675 | 7459 | /* branch registers: */ |
8b84be9d JB |
7460 | declare_register_set ("b", 8, REG_BR); |
7461 | declare_register ("rp", REG_BR + 0); | |
800eeca4 | 7462 | |
8b84be9d JB |
7463 | /* predicate registers: */ |
7464 | declare_register_set ("p", 64, REG_P); | |
7465 | declare_register ("pr", REG_PR); | |
7466 | declare_register ("pr.rot", REG_PR_ROT); | |
800eeca4 | 7467 | |
8b84be9d JB |
7468 | /* application registers: */ |
7469 | declare_register_set ("ar", 128, REG_AR); | |
5e0bd176 JB |
7470 | for (i = 0; i < NELEMS (ar); ++i) |
7471 | declare_register (ar[i].name, REG_AR + ar[i].regnum); | |
800eeca4 | 7472 | |
8b84be9d JB |
7473 | /* control registers: */ |
7474 | declare_register_set ("cr", 128, REG_CR); | |
5e0bd176 JB |
7475 | for (i = 0; i < NELEMS (cr); ++i) |
7476 | declare_register (cr[i].name, REG_CR + cr[i].regnum); | |
800eeca4 | 7477 | |
b3e14eda L |
7478 | /* dahr registers: */ |
7479 | declare_register_set ("dahr", 8, REG_DAHR); | |
7480 | ||
8b84be9d JB |
7481 | declare_register ("ip", REG_IP); |
7482 | declare_register ("cfm", REG_CFM); | |
7483 | declare_register ("psr", REG_PSR); | |
7484 | declare_register ("psr.l", REG_PSR_L); | |
7485 | declare_register ("psr.um", REG_PSR_UM); | |
7486 | ||
7487 | for (i = 0; i < NELEMS (indirect_reg); ++i) | |
7488 | { | |
7489 | unsigned int regnum = indirect_reg[i].regnum; | |
7490 | ||
7491 | md.indregsym[regnum - IND_CPUID] = declare_register (indirect_reg[i].name, regnum); | |
7492 | } | |
800eeca4 | 7493 | |
542d6675 | 7494 | /* pseudo-registers used to specify unwind info: */ |
e0c9811a JW |
7495 | declare_register ("psp", REG_PSP); |
7496 | ||
800eeca4 JW |
7497 | for (i = 0; i < NELEMS (const_bits); ++i) |
7498 | { | |
7499 | err = hash_insert (md.const_hash, const_bits[i].name, | |
5a49b8ac | 7500 | (void *) (const_bits + i)); |
800eeca4 | 7501 | if (err) |
ad4b42b4 | 7502 | as_fatal (_("Inserting \"%s\" into constant hash table failed: %s"), |
800eeca4 JW |
7503 | name, err); |
7504 | } | |
7505 | ||
44f5c83a JW |
7506 | /* Set the architecture and machine depending on defaults and command line |
7507 | options. */ | |
7508 | if (md.flags & EF_IA_64_ABI64) | |
7509 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf64); | |
7510 | else | |
7511 | ok = bfd_set_arch_mach (stdoutput, bfd_arch_ia64, bfd_mach_ia64_elf32); | |
7512 | ||
7513 | if (! ok) | |
7514 | as_warn (_("Could not set architecture and machine")); | |
800eeca4 | 7515 | |
557debba JW |
7516 | /* Set the pointer size and pointer shift size depending on md.flags */ |
7517 | ||
7518 | if (md.flags & EF_IA_64_ABI64) | |
7519 | { | |
7520 | md.pointer_size = 8; /* pointers are 8 bytes */ | |
7521 | md.pointer_size_shift = 3; /* alignment is 8 bytes = 2^2 */ | |
7522 | } | |
7523 | else | |
7524 | { | |
7525 | md.pointer_size = 4; /* pointers are 4 bytes */ | |
7526 | md.pointer_size_shift = 2; /* alignment is 4 bytes = 2^2 */ | |
7527 | } | |
7528 | ||
800eeca4 JW |
7529 | md.mem_offset.hint = 0; |
7530 | md.path = 0; | |
7531 | md.maxpaths = 0; | |
7532 | md.entry_labels = NULL; | |
7533 | } | |
7534 | ||
970d6792 L |
7535 | /* Set the default options in md. Cannot do this in md_begin because |
7536 | that is called after md_parse_option which is where we set the | |
7537 | options in md based on command line options. */ | |
44f5c83a JW |
7538 | |
7539 | void | |
5a49b8ac | 7540 | ia64_init (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) |
44f5c83a | 7541 | { |
1cd8ff38 | 7542 | md.flags = MD_FLAGS_DEFAULT; |
01e1a5bc NC |
7543 | #ifndef TE_VMS |
7544 | /* Don't turn on dependency checking for VMS, doesn't work. */ | |
f1dab70d | 7545 | md.detect_dv = 1; |
01e1a5bc | 7546 | #endif |
970d6792 L |
7547 | /* FIXME: We should change it to unwind_check_error someday. */ |
7548 | md.unwind_check = unwind_check_warning; | |
91d777ee | 7549 | md.hint_b = hint_b_error; |
8c2fda1d | 7550 | md.tune = itanium2; |
44f5c83a JW |
7551 | } |
7552 | ||
7553 | /* Return a string for the target object file format. */ | |
7554 | ||
7555 | const char * | |
5a49b8ac | 7556 | ia64_target_format (void) |
44f5c83a JW |
7557 | { |
7558 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
7559 | { | |
72a76794 JW |
7560 | if (md.flags & EF_IA_64_BE) |
7561 | { | |
7562 | if (md.flags & EF_IA_64_ABI64) | |
1cd8ff38 | 7563 | #if defined(TE_AIX50) |
7463c317 | 7564 | return "elf64-ia64-aix-big"; |
1cd8ff38 NC |
7565 | #elif defined(TE_HPUX) |
7566 | return "elf64-ia64-hpux-big"; | |
7463c317 | 7567 | #else |
72a76794 | 7568 | return "elf64-ia64-big"; |
7463c317 | 7569 | #endif |
72a76794 | 7570 | else |
1cd8ff38 | 7571 | #if defined(TE_AIX50) |
7463c317 | 7572 | return "elf32-ia64-aix-big"; |
1cd8ff38 NC |
7573 | #elif defined(TE_HPUX) |
7574 | return "elf32-ia64-hpux-big"; | |
7463c317 | 7575 | #else |
72a76794 | 7576 | return "elf32-ia64-big"; |
7463c317 | 7577 | #endif |
72a76794 | 7578 | } |
44f5c83a | 7579 | else |
72a76794 JW |
7580 | { |
7581 | if (md.flags & EF_IA_64_ABI64) | |
01e1a5bc | 7582 | #if defined (TE_AIX50) |
7463c317 | 7583 | return "elf64-ia64-aix-little"; |
01e1a5bc NC |
7584 | #elif defined (TE_VMS) |
7585 | { | |
7586 | md.flags |= EF_IA_64_ARCHVER_1; | |
7587 | return "elf64-ia64-vms"; | |
7588 | } | |
7463c317 | 7589 | #else |
72a76794 | 7590 | return "elf64-ia64-little"; |
7463c317 | 7591 | #endif |
72a76794 | 7592 | else |
7463c317 TW |
7593 | #ifdef TE_AIX50 |
7594 | return "elf32-ia64-aix-little"; | |
7595 | #else | |
72a76794 | 7596 | return "elf32-ia64-little"; |
7463c317 | 7597 | #endif |
72a76794 | 7598 | } |
44f5c83a JW |
7599 | } |
7600 | else | |
7601 | return "unknown-format"; | |
7602 | } | |
7603 | ||
800eeca4 | 7604 | void |
5a49b8ac | 7605 | ia64_end_of_source (void) |
800eeca4 | 7606 | { |
542d6675 | 7607 | /* terminate insn group upon reaching end of file: */ |
800eeca4 JW |
7608 | insn_group_break (1, 0, 0); |
7609 | ||
542d6675 | 7610 | /* emits slots we haven't written yet: */ |
800eeca4 JW |
7611 | ia64_flush_insns (); |
7612 | ||
7613 | bfd_set_private_flags (stdoutput, md.flags); | |
7614 | ||
800eeca4 JW |
7615 | md.mem_offset.hint = 0; |
7616 | } | |
7617 | ||
7618 | void | |
5a49b8ac | 7619 | ia64_start_line (void) |
800eeca4 | 7620 | { |
e4e8248d JB |
7621 | static int first; |
7622 | ||
7623 | if (!first) { | |
7624 | /* Make sure we don't reference input_line_pointer[-1] when that's | |
7625 | not valid. */ | |
7626 | first = 1; | |
7627 | return; | |
7628 | } | |
7629 | ||
f1bcba5b | 7630 | if (md.qp.X_op == O_register) |
ad4b42b4 | 7631 | as_bad (_("qualifying predicate not followed by instruction")); |
800eeca4 JW |
7632 | md.qp.X_op = O_absent; |
7633 | ||
7634 | if (ignore_input ()) | |
7635 | return; | |
7636 | ||
7637 | if (input_line_pointer[0] == ';' && input_line_pointer[-1] == ';') | |
7638 | { | |
7639 | if (md.detect_dv && !md.explicit_mode) | |
f1dab70d JB |
7640 | { |
7641 | static int warned; | |
7642 | ||
7643 | if (!warned) | |
7644 | { | |
7645 | warned = 1; | |
7646 | as_warn (_("Explicit stops are ignored in auto mode")); | |
7647 | } | |
7648 | } | |
800eeca4 | 7649 | else |
542d6675 | 7650 | insn_group_break (1, 0, 0); |
800eeca4 | 7651 | } |
e4e8248d | 7652 | else if (input_line_pointer[-1] == '{') |
800eeca4 | 7653 | { |
800eeca4 | 7654 | if (md.manual_bundling) |
ad4b42b4 | 7655 | as_warn (_("Found '{' when manual bundling is already turned on")); |
800eeca4 JW |
7656 | else |
7657 | CURR_SLOT.manual_bundling_on = 1; | |
7658 | md.manual_bundling = 1; | |
7659 | ||
542d6675 KH |
7660 | /* Bundling is only acceptable in explicit mode |
7661 | or when in default automatic mode. */ | |
800eeca4 | 7662 | if (md.detect_dv && !md.explicit_mode) |
542d6675 KH |
7663 | { |
7664 | if (!md.mode_explicitly_set | |
7665 | && !md.default_explicit_mode) | |
7666 | dot_dv_mode ('E'); | |
7667 | else | |
7668 | as_warn (_("Found '{' after explicit switch to automatic mode")); | |
7669 | } | |
e4e8248d JB |
7670 | } |
7671 | else if (input_line_pointer[-1] == '}') | |
7672 | { | |
800eeca4 | 7673 | if (!md.manual_bundling) |
ad4b42b4 | 7674 | as_warn (_("Found '}' when manual bundling is off")); |
800eeca4 JW |
7675 | else |
7676 | PREV_SLOT.manual_bundling_off = 1; | |
7677 | md.manual_bundling = 0; | |
7678 | ||
7679 | /* switch back to automatic mode, if applicable */ | |
197865e8 | 7680 | if (md.detect_dv |
542d6675 KH |
7681 | && md.explicit_mode |
7682 | && !md.mode_explicitly_set | |
7683 | && !md.default_explicit_mode) | |
7684 | dot_dv_mode ('A'); | |
e4e8248d JB |
7685 | } |
7686 | } | |
800eeca4 | 7687 | |
e4e8248d JB |
7688 | /* This is a hook for ia64_frob_label, so that it can distinguish tags from |
7689 | labels. */ | |
7690 | static int defining_tag = 0; | |
7691 | ||
7692 | int | |
5a49b8ac | 7693 | ia64_unrecognized_line (int ch) |
e4e8248d JB |
7694 | { |
7695 | switch (ch) | |
7696 | { | |
7697 | case '(': | |
60d11e55 | 7698 | expression_and_evaluate (&md.qp); |
e4e8248d | 7699 | if (*input_line_pointer++ != ')') |
800eeca4 | 7700 | { |
ad4b42b4 | 7701 | as_bad (_("Expected ')'")); |
e4e8248d JB |
7702 | return 0; |
7703 | } | |
7704 | if (md.qp.X_op != O_register) | |
7705 | { | |
ad4b42b4 | 7706 | as_bad (_("Qualifying predicate expected")); |
e4e8248d JB |
7707 | return 0; |
7708 | } | |
7709 | if (md.qp.X_add_number < REG_P || md.qp.X_add_number >= REG_P + 64) | |
7710 | { | |
ad4b42b4 | 7711 | as_bad (_("Predicate register expected")); |
e4e8248d | 7712 | return 0; |
800eeca4 | 7713 | } |
800eeca4 JW |
7714 | return 1; |
7715 | ||
f1bcba5b JW |
7716 | case '[': |
7717 | { | |
7718 | char *s; | |
7719 | char c; | |
7720 | symbolS *tag; | |
4d5a53ff | 7721 | int temp; |
f1bcba5b JW |
7722 | |
7723 | if (md.qp.X_op == O_register) | |
7724 | { | |
ad4b42b4 | 7725 | as_bad (_("Tag must come before qualifying predicate.")); |
f1bcba5b JW |
7726 | return 0; |
7727 | } | |
4d5a53ff JW |
7728 | |
7729 | /* This implements just enough of read_a_source_file in read.c to | |
7730 | recognize labels. */ | |
7731 | if (is_name_beginner (*input_line_pointer)) | |
7732 | { | |
d02603dc | 7733 | c = get_symbol_name (&s); |
4d5a53ff JW |
7734 | } |
7735 | else if (LOCAL_LABELS_FB | |
3882b010 | 7736 | && ISDIGIT (*input_line_pointer)) |
4d5a53ff JW |
7737 | { |
7738 | temp = 0; | |
3882b010 | 7739 | while (ISDIGIT (*input_line_pointer)) |
4d5a53ff JW |
7740 | temp = (temp * 10) + *input_line_pointer++ - '0'; |
7741 | fb_label_instance_inc (temp); | |
7742 | s = fb_label_name (temp, 0); | |
7743 | c = *input_line_pointer; | |
7744 | } | |
7745 | else | |
7746 | { | |
7747 | s = NULL; | |
7748 | c = '\0'; | |
7749 | } | |
f1bcba5b JW |
7750 | if (c != ':') |
7751 | { | |
7752 | /* Put ':' back for error messages' sake. */ | |
7753 | *input_line_pointer++ = ':'; | |
ad4b42b4 | 7754 | as_bad (_("Expected ':'")); |
f1bcba5b JW |
7755 | return 0; |
7756 | } | |
4d5a53ff | 7757 | |
f1bcba5b JW |
7758 | defining_tag = 1; |
7759 | tag = colon (s); | |
7760 | defining_tag = 0; | |
7761 | /* Put ':' back for error messages' sake. */ | |
7762 | *input_line_pointer++ = ':'; | |
7763 | if (*input_line_pointer++ != ']') | |
7764 | { | |
ad4b42b4 | 7765 | as_bad (_("Expected ']'")); |
f1bcba5b JW |
7766 | return 0; |
7767 | } | |
7768 | if (! tag) | |
7769 | { | |
ad4b42b4 | 7770 | as_bad (_("Tag name expected")); |
f1bcba5b JW |
7771 | return 0; |
7772 | } | |
7773 | return 1; | |
7774 | } | |
7775 | ||
800eeca4 JW |
7776 | default: |
7777 | break; | |
7778 | } | |
542d6675 KH |
7779 | |
7780 | /* Not a valid line. */ | |
7781 | return 0; | |
800eeca4 JW |
7782 | } |
7783 | ||
7784 | void | |
5a49b8ac | 7785 | ia64_frob_label (struct symbol *sym) |
800eeca4 JW |
7786 | { |
7787 | struct label_fix *fix; | |
7788 | ||
f1bcba5b JW |
7789 | /* Tags need special handling since they are not bundle breaks like |
7790 | labels. */ | |
7791 | if (defining_tag) | |
7792 | { | |
7793 | fix = obstack_alloc (¬es, sizeof (*fix)); | |
7794 | fix->sym = sym; | |
7795 | fix->next = CURR_SLOT.tag_fixups; | |
07a53e5c | 7796 | fix->dw2_mark_labels = FALSE; |
f1bcba5b JW |
7797 | CURR_SLOT.tag_fixups = fix; |
7798 | ||
7799 | return; | |
7800 | } | |
7801 | ||
800eeca4 JW |
7802 | if (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) |
7803 | { | |
7804 | md.last_text_seg = now_seg; | |
7805 | fix = obstack_alloc (¬es, sizeof (*fix)); | |
7806 | fix->sym = sym; | |
7807 | fix->next = CURR_SLOT.label_fixups; | |
07a53e5c | 7808 | fix->dw2_mark_labels = dwarf2_loc_mark_labels; |
800eeca4 JW |
7809 | CURR_SLOT.label_fixups = fix; |
7810 | ||
542d6675 | 7811 | /* Keep track of how many code entry points we've seen. */ |
800eeca4 | 7812 | if (md.path == md.maxpaths) |
542d6675 KH |
7813 | { |
7814 | md.maxpaths += 20; | |
7815 | md.entry_labels = (const char **) | |
7816 | xrealloc ((void *) md.entry_labels, | |
7817 | md.maxpaths * sizeof (char *)); | |
7818 | } | |
800eeca4 JW |
7819 | md.entry_labels[md.path++] = S_GET_NAME (sym); |
7820 | } | |
7821 | } | |
7822 | ||
936cf02e JW |
7823 | #ifdef TE_HPUX |
7824 | /* The HP-UX linker will give unresolved symbol errors for symbols | |
7825 | that are declared but unused. This routine removes declared, | |
7826 | unused symbols from an object. */ | |
7827 | int | |
5a49b8ac | 7828 | ia64_frob_symbol (struct symbol *sym) |
936cf02e | 7829 | { |
45dfa85a | 7830 | if ((S_GET_SEGMENT (sym) == bfd_und_section_ptr && ! symbol_used_p (sym) && |
936cf02e | 7831 | ELF_ST_VISIBILITY (S_GET_OTHER (sym)) == STV_DEFAULT) |
45dfa85a | 7832 | || (S_GET_SEGMENT (sym) == bfd_abs_section_ptr |
936cf02e JW |
7833 | && ! S_IS_EXTERNAL (sym))) |
7834 | return 1; | |
7835 | return 0; | |
7836 | } | |
7837 | #endif | |
7838 | ||
800eeca4 | 7839 | void |
5a49b8ac | 7840 | ia64_flush_pending_output (void) |
800eeca4 | 7841 | { |
4d5a53ff JW |
7842 | if (!md.keep_pending_output |
7843 | && bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) | |
800eeca4 JW |
7844 | { |
7845 | /* ??? This causes many unnecessary stop bits to be emitted. | |
7846 | Unfortunately, it isn't clear if it is safe to remove this. */ | |
7847 | insn_group_break (1, 0, 0); | |
7848 | ia64_flush_insns (); | |
7849 | } | |
7850 | } | |
7851 | ||
7852 | /* Do ia64-specific expression optimization. All that's done here is | |
7853 | to transform index expressions that are either due to the indexing | |
7854 | of rotating registers or due to the indexing of indirect register | |
7855 | sets. */ | |
7856 | int | |
5a49b8ac | 7857 | ia64_optimize_expr (expressionS *l, operatorT op, expressionS *r) |
800eeca4 | 7858 | { |
6a2375c6 JB |
7859 | if (op != O_index) |
7860 | return 0; | |
7861 | resolve_expression (l); | |
7862 | if (l->X_op == O_register) | |
800eeca4 | 7863 | { |
6a2375c6 JB |
7864 | unsigned num_regs = l->X_add_number >> 16; |
7865 | ||
7866 | resolve_expression (r); | |
7867 | if (num_regs) | |
800eeca4 | 7868 | { |
6a2375c6 JB |
7869 | /* Left side is a .rotX-allocated register. */ |
7870 | if (r->X_op != O_constant) | |
800eeca4 | 7871 | { |
ad4b42b4 | 7872 | as_bad (_("Rotating register index must be a non-negative constant")); |
6a2375c6 JB |
7873 | r->X_add_number = 0; |
7874 | } | |
7875 | else if ((valueT) r->X_add_number >= num_regs) | |
7876 | { | |
ad4b42b4 | 7877 | as_bad (_("Index out of range 0..%u"), num_regs - 1); |
800eeca4 JW |
7878 | r->X_add_number = 0; |
7879 | } | |
7880 | l->X_add_number = (l->X_add_number & 0xffff) + r->X_add_number; | |
7881 | return 1; | |
7882 | } | |
6a2375c6 | 7883 | else if (l->X_add_number >= IND_CPUID && l->X_add_number <= IND_RR) |
800eeca4 | 7884 | { |
6a2375c6 JB |
7885 | if (r->X_op != O_register |
7886 | || r->X_add_number < REG_GR | |
7887 | || r->X_add_number > REG_GR + 127) | |
800eeca4 | 7888 | { |
ad4b42b4 | 7889 | as_bad (_("Indirect register index must be a general register")); |
6a2375c6 | 7890 | r->X_add_number = REG_GR; |
800eeca4 JW |
7891 | } |
7892 | l->X_op = O_index; | |
8b84be9d | 7893 | l->X_op_symbol = md.indregsym[l->X_add_number - IND_CPUID]; |
800eeca4 JW |
7894 | l->X_add_number = r->X_add_number; |
7895 | return 1; | |
7896 | } | |
7897 | } | |
ad4b42b4 | 7898 | as_bad (_("Index can only be applied to rotating or indirect registers")); |
6a2375c6 JB |
7899 | /* Fall back to some register use of which has as little as possible |
7900 | side effects, to minimize subsequent error messages. */ | |
7901 | l->X_op = O_register; | |
7902 | l->X_add_number = REG_GR + 3; | |
7903 | return 1; | |
800eeca4 JW |
7904 | } |
7905 | ||
7906 | int | |
5a49b8ac | 7907 | ia64_parse_name (char *name, expressionS *e, char *nextcharP) |
800eeca4 JW |
7908 | { |
7909 | struct const_desc *cdesc; | |
7910 | struct dynreg *dr = 0; | |
16a48f83 | 7911 | unsigned int idx; |
800eeca4 JW |
7912 | struct symbol *sym; |
7913 | char *end; | |
7914 | ||
16a48f83 JB |
7915 | if (*name == '@') |
7916 | { | |
7917 | enum pseudo_type pseudo_type = PSEUDO_FUNC_NONE; | |
7918 | ||
7919 | /* Find what relocation pseudo-function we're dealing with. */ | |
7920 | for (idx = 0; idx < NELEMS (pseudo_func); ++idx) | |
7921 | if (pseudo_func[idx].name | |
7922 | && pseudo_func[idx].name[0] == name[1] | |
7923 | && strcmp (pseudo_func[idx].name + 1, name + 2) == 0) | |
7924 | { | |
7925 | pseudo_type = pseudo_func[idx].type; | |
7926 | break; | |
7927 | } | |
7928 | switch (pseudo_type) | |
7929 | { | |
7930 | case PSEUDO_FUNC_RELOC: | |
7931 | end = input_line_pointer; | |
7932 | if (*nextcharP != '(') | |
7933 | { | |
ad4b42b4 | 7934 | as_bad (_("Expected '('")); |
2f6d622e | 7935 | break; |
16a48f83 JB |
7936 | } |
7937 | /* Skip '('. */ | |
7938 | ++input_line_pointer; | |
7939 | expression (e); | |
7940 | if (*input_line_pointer != ')') | |
7941 | { | |
ad4b42b4 | 7942 | as_bad (_("Missing ')'")); |
16a48f83 JB |
7943 | goto done; |
7944 | } | |
7945 | /* Skip ')'. */ | |
7946 | ++input_line_pointer; | |
9d0e8497 TG |
7947 | #ifdef TE_VMS |
7948 | if (idx == FUNC_SLOTCOUNT_RELOC) | |
7949 | { | |
7950 | /* @slotcount can accept any expression. Canonicalize. */ | |
7951 | e->X_add_symbol = make_expr_symbol (e); | |
7952 | e->X_op = O_symbol; | |
7953 | e->X_add_number = 0; | |
7954 | } | |
7955 | #endif | |
16a48f83 JB |
7956 | if (e->X_op != O_symbol) |
7957 | { | |
7958 | if (e->X_op != O_pseudo_fixup) | |
7959 | { | |
ad4b42b4 | 7960 | as_bad (_("Not a symbolic expression")); |
16a48f83 JB |
7961 | goto done; |
7962 | } | |
7963 | if (idx != FUNC_LT_RELATIVE) | |
7964 | { | |
ad4b42b4 | 7965 | as_bad (_("Illegal combination of relocation functions")); |
16a48f83 JB |
7966 | goto done; |
7967 | } | |
7968 | switch (S_GET_VALUE (e->X_op_symbol)) | |
7969 | { | |
7970 | case FUNC_FPTR_RELATIVE: | |
7971 | idx = FUNC_LT_FPTR_RELATIVE; break; | |
7972 | case FUNC_DTP_MODULE: | |
7973 | idx = FUNC_LT_DTP_MODULE; break; | |
7974 | case FUNC_DTP_RELATIVE: | |
7975 | idx = FUNC_LT_DTP_RELATIVE; break; | |
7976 | case FUNC_TP_RELATIVE: | |
7977 | idx = FUNC_LT_TP_RELATIVE; break; | |
7978 | default: | |
ad4b42b4 | 7979 | as_bad (_("Illegal combination of relocation functions")); |
16a48f83 JB |
7980 | goto done; |
7981 | } | |
7982 | } | |
7983 | /* Make sure gas doesn't get rid of local symbols that are used | |
7984 | in relocs. */ | |
7985 | e->X_op = O_pseudo_fixup; | |
7986 | e->X_op_symbol = pseudo_func[idx].u.sym; | |
2f6d622e JB |
7987 | done: |
7988 | *nextcharP = *input_line_pointer; | |
16a48f83 JB |
7989 | break; |
7990 | ||
7991 | case PSEUDO_FUNC_CONST: | |
7992 | e->X_op = O_constant; | |
7993 | e->X_add_number = pseudo_func[idx].u.ival; | |
7994 | break; | |
7995 | ||
7996 | case PSEUDO_FUNC_REG: | |
7997 | e->X_op = O_register; | |
7998 | e->X_add_number = pseudo_func[idx].u.ival; | |
7999 | break; | |
8000 | ||
8001 | default: | |
8002 | return 0; | |
8003 | } | |
16a48f83 JB |
8004 | return 1; |
8005 | } | |
8006 | ||
542d6675 | 8007 | /* first see if NAME is a known register name: */ |
800eeca4 JW |
8008 | sym = hash_find (md.reg_hash, name); |
8009 | if (sym) | |
8010 | { | |
8011 | e->X_op = O_register; | |
8012 | e->X_add_number = S_GET_VALUE (sym); | |
8013 | return 1; | |
8014 | } | |
8015 | ||
8016 | cdesc = hash_find (md.const_hash, name); | |
8017 | if (cdesc) | |
8018 | { | |
8019 | e->X_op = O_constant; | |
8020 | e->X_add_number = cdesc->value; | |
8021 | return 1; | |
8022 | } | |
8023 | ||
542d6675 | 8024 | /* check for inN, locN, or outN: */ |
26b810ce | 8025 | idx = 0; |
800eeca4 JW |
8026 | switch (name[0]) |
8027 | { | |
8028 | case 'i': | |
3882b010 | 8029 | if (name[1] == 'n' && ISDIGIT (name[2])) |
800eeca4 JW |
8030 | { |
8031 | dr = &md.in; | |
26b810ce | 8032 | idx = 2; |
800eeca4 JW |
8033 | } |
8034 | break; | |
8035 | ||
8036 | case 'l': | |
3882b010 | 8037 | if (name[1] == 'o' && name[2] == 'c' && ISDIGIT (name[3])) |
800eeca4 JW |
8038 | { |
8039 | dr = &md.loc; | |
26b810ce | 8040 | idx = 3; |
800eeca4 JW |
8041 | } |
8042 | break; | |
8043 | ||
8044 | case 'o': | |
3882b010 | 8045 | if (name[1] == 'u' && name[2] == 't' && ISDIGIT (name[3])) |
800eeca4 JW |
8046 | { |
8047 | dr = &md.out; | |
26b810ce | 8048 | idx = 3; |
800eeca4 JW |
8049 | } |
8050 | break; | |
8051 | ||
8052 | default: | |
8053 | break; | |
8054 | } | |
8055 | ||
26b810ce JB |
8056 | /* Ignore register numbers with leading zeroes, except zero itself. */ |
8057 | if (dr && (name[idx] != '0' || name[idx + 1] == '\0')) | |
800eeca4 | 8058 | { |
26b810ce JB |
8059 | unsigned long regnum; |
8060 | ||
542d6675 | 8061 | /* The name is inN, locN, or outN; parse the register number. */ |
26b810ce JB |
8062 | regnum = strtoul (name + idx, &end, 10); |
8063 | if (end > name + idx && *end == '\0' && regnum < 96) | |
800eeca4 | 8064 | { |
26b810ce | 8065 | if (regnum >= dr->num_regs) |
800eeca4 JW |
8066 | { |
8067 | if (!dr->num_regs) | |
ad4b42b4 | 8068 | as_bad (_("No current frame")); |
800eeca4 | 8069 | else |
ad4b42b4 | 8070 | as_bad (_("Register number out of range 0..%u"), |
542d6675 | 8071 | dr->num_regs - 1); |
800eeca4 JW |
8072 | regnum = 0; |
8073 | } | |
8074 | e->X_op = O_register; | |
8075 | e->X_add_number = dr->base + regnum; | |
8076 | return 1; | |
8077 | } | |
8078 | } | |
8079 | ||
20b36a95 JB |
8080 | end = alloca (strlen (name) + 1); |
8081 | strcpy (end, name); | |
8082 | name = ia64_canonicalize_symbol_name (end); | |
800eeca4 JW |
8083 | if ((dr = hash_find (md.dynreg_hash, name))) |
8084 | { | |
8085 | /* We've got ourselves the name of a rotating register set. | |
542d6675 KH |
8086 | Store the base register number in the low 16 bits of |
8087 | X_add_number and the size of the register set in the top 16 | |
8088 | bits. */ | |
800eeca4 JW |
8089 | e->X_op = O_register; |
8090 | e->X_add_number = dr->base | (dr->num_regs << 16); | |
8091 | return 1; | |
8092 | } | |
8093 | return 0; | |
8094 | } | |
8095 | ||
8096 | /* Remove the '#' suffix that indicates a symbol as opposed to a register. */ | |
8097 | ||
8098 | char * | |
5a49b8ac | 8099 | ia64_canonicalize_symbol_name (char *name) |
800eeca4 | 8100 | { |
20b36a95 JB |
8101 | size_t len = strlen (name), full = len; |
8102 | ||
8103 | while (len > 0 && name[len - 1] == '#') | |
8104 | --len; | |
8105 | if (len <= 0) | |
8106 | { | |
8107 | if (full > 0) | |
ad4b42b4 | 8108 | as_bad (_("Standalone `#' is illegal")); |
20b36a95 JB |
8109 | } |
8110 | else if (len < full - 1) | |
ad4b42b4 | 8111 | as_warn (_("Redundant `#' suffix operators")); |
20b36a95 | 8112 | name[len] = '\0'; |
800eeca4 JW |
8113 | return name; |
8114 | } | |
8115 | ||
3e37788f JW |
8116 | /* Return true if idesc is a conditional branch instruction. This excludes |
8117 | the modulo scheduled branches, and br.ia. Mod-sched branches are excluded | |
8118 | because they always read/write resources regardless of the value of the | |
8119 | qualifying predicate. br.ia must always use p0, and hence is always | |
8120 | taken. Thus this function returns true for branches which can fall | |
8121 | through, and which use no resources if they do fall through. */ | |
1deb8127 | 8122 | |
800eeca4 | 8123 | static int |
5a49b8ac | 8124 | is_conditional_branch (struct ia64_opcode *idesc) |
800eeca4 | 8125 | { |
1deb8127 | 8126 | /* br is a conditional branch. Everything that starts with br. except |
3e37788f JW |
8127 | br.ia, br.c{loop,top,exit}, and br.w{top,exit} is a conditional branch. |
8128 | Everything that starts with brl is a conditional branch. */ | |
1deb8127 JW |
8129 | return (idesc->name[0] == 'b' && idesc->name[1] == 'r' |
8130 | && (idesc->name[2] == '\0' | |
3e37788f JW |
8131 | || (idesc->name[2] == '.' && idesc->name[3] != 'i' |
8132 | && idesc->name[3] != 'c' && idesc->name[3] != 'w') | |
8133 | || idesc->name[2] == 'l' | |
8134 | /* br.cond, br.call, br.clr */ | |
8135 | || (idesc->name[2] == '.' && idesc->name[3] == 'c' | |
8136 | && (idesc->name[4] == 'a' || idesc->name[4] == 'o' | |
8137 | || (idesc->name[4] == 'l' && idesc->name[5] == 'r'))))); | |
800eeca4 JW |
8138 | } |
8139 | ||
8140 | /* Return whether the given opcode is a taken branch. If there's any doubt, | |
542d6675 KH |
8141 | returns zero. */ |
8142 | ||
800eeca4 | 8143 | static int |
5a49b8ac | 8144 | is_taken_branch (struct ia64_opcode *idesc) |
800eeca4 JW |
8145 | { |
8146 | return ((is_conditional_branch (idesc) && CURR_SLOT.qp_regno == 0) | |
542d6675 | 8147 | || strncmp (idesc->name, "br.ia", 5) == 0); |
800eeca4 JW |
8148 | } |
8149 | ||
8150 | /* Return whether the given opcode is an interruption or rfi. If there's any | |
542d6675 KH |
8151 | doubt, returns zero. */ |
8152 | ||
800eeca4 | 8153 | static int |
5a49b8ac | 8154 | is_interruption_or_rfi (struct ia64_opcode *idesc) |
800eeca4 JW |
8155 | { |
8156 | if (strcmp (idesc->name, "rfi") == 0) | |
8157 | return 1; | |
8158 | return 0; | |
8159 | } | |
8160 | ||
8161 | /* Returns the index of the given dependency in the opcode's list of chks, or | |
8162 | -1 if there is no dependency. */ | |
542d6675 | 8163 | |
800eeca4 | 8164 | static int |
5a49b8ac | 8165 | depends_on (int depind, struct ia64_opcode *idesc) |
800eeca4 JW |
8166 | { |
8167 | int i; | |
8168 | const struct ia64_opcode_dependency *dep = idesc->dependencies; | |
542d6675 | 8169 | for (i = 0; i < dep->nchks; i++) |
800eeca4 | 8170 | { |
542d6675 KH |
8171 | if (depind == DEP (dep->chks[i])) |
8172 | return i; | |
800eeca4 JW |
8173 | } |
8174 | return -1; | |
8175 | } | |
8176 | ||
8177 | /* Determine a set of specific resources used for a particular resource | |
8178 | class. Returns the number of specific resources identified For those | |
8179 | cases which are not determinable statically, the resource returned is | |
197865e8 | 8180 | marked nonspecific. |
800eeca4 JW |
8181 | |
8182 | Meanings of value in 'NOTE': | |
8183 | 1) only read/write when the register number is explicitly encoded in the | |
8184 | insn. | |
8185 | 2) only read CFM when accessing a rotating GR, FR, or PR. mov pr only | |
197865e8 | 8186 | accesses CFM when qualifying predicate is in the rotating region. |
800eeca4 JW |
8187 | 3) general register value is used to specify an indirect register; not |
8188 | determinable statically. | |
8189 | 4) only read the given resource when bits 7:0 of the indirect index | |
8190 | register value does not match the register number of the resource; not | |
8191 | determinable statically. | |
8192 | 5) all rules are implementation specific. | |
8193 | 6) only when both the index specified by the reader and the index specified | |
8194 | by the writer have the same value in bits 63:61; not determinable | |
197865e8 | 8195 | statically. |
800eeca4 | 8196 | 7) only access the specified resource when the corresponding mask bit is |
197865e8 | 8197 | set |
800eeca4 JW |
8198 | 8) PSR.dfh is only read when these insns reference FR32-127. PSR.dfl is |
8199 | only read when these insns reference FR2-31 | |
8200 | 9) PSR.mfl is only written when these insns write FR2-31. PSR.mfh is only | |
8201 | written when these insns write FR32-127 | |
8202 | 10) The PSR.bn bit is only accessed when one of GR16-31 is specified in the | |
8203 | instruction | |
8204 | 11) The target predicates are written independently of PR[qp], but source | |
8205 | registers are only read if PR[qp] is true. Since the state of PR[qp] | |
8206 | cannot statically be determined, all source registers are marked used. | |
8207 | 12) This insn only reads the specified predicate register when that | |
8208 | register is the PR[qp]. | |
ad4b42b4 | 8209 | 13) This reference to ld-c only applies to the GR whose value is loaded |
197865e8 | 8210 | with data returned from memory, not the post-incremented address register. |
800eeca4 JW |
8211 | 14) The RSE resource includes the implementation-specific RSE internal |
8212 | state resources. At least one (and possibly more) of these resources are | |
8213 | read by each instruction listed in IC:rse-readers. At least one (and | |
8214 | possibly more) of these resources are written by each insn listed in | |
197865e8 | 8215 | IC:rse-writers. |
800eeca4 | 8216 | 15+16) Represents reserved instructions, which the assembler does not |
197865e8 | 8217 | generate. |
7f3dfb9c L |
8218 | 17) CR[TPR] has a RAW dependency only between mov-to-CR-TPR and |
8219 | mov-to-PSR-l or ssm instructions that set PSR.i, PSR.pp or PSR.up. | |
800eeca4 JW |
8220 | |
8221 | Memory resources (i.e. locations in memory) are *not* marked or tracked by | |
8222 | this code; there are no dependency violations based on memory access. | |
800eeca4 JW |
8223 | */ |
8224 | ||
8225 | #define MAX_SPECS 256 | |
8226 | #define DV_CHK 1 | |
8227 | #define DV_REG 0 | |
8228 | ||
8229 | static int | |
5a49b8ac AM |
8230 | specify_resource (const struct ia64_dependency *dep, |
8231 | struct ia64_opcode *idesc, | |
8232 | /* is this a DV chk or a DV reg? */ | |
8233 | int type, | |
8234 | /* returned specific resources */ | |
8235 | struct rsrc specs[MAX_SPECS], | |
8236 | /* resource note for this insn's usage */ | |
8237 | int note, | |
8238 | /* which execution path to examine */ | |
8239 | int path) | |
800eeca4 JW |
8240 | { |
8241 | int count = 0; | |
8242 | int i; | |
8243 | int rsrc_write = 0; | |
8244 | struct rsrc tmpl; | |
197865e8 | 8245 | |
800eeca4 JW |
8246 | if (dep->mode == IA64_DV_WAW |
8247 | || (dep->mode == IA64_DV_RAW && type == DV_REG) | |
8248 | || (dep->mode == IA64_DV_WAR && type == DV_CHK)) | |
8249 | rsrc_write = 1; | |
8250 | ||
8251 | /* template for any resources we identify */ | |
8252 | tmpl.dependency = dep; | |
8253 | tmpl.note = note; | |
8254 | tmpl.insn_srlz = tmpl.data_srlz = 0; | |
8255 | tmpl.qp_regno = CURR_SLOT.qp_regno; | |
8256 | tmpl.link_to_qp_branch = 1; | |
8257 | tmpl.mem_offset.hint = 0; | |
1f8b1395 AS |
8258 | tmpl.mem_offset.offset = 0; |
8259 | tmpl.mem_offset.base = 0; | |
800eeca4 | 8260 | tmpl.specific = 1; |
a66d2bb7 | 8261 | tmpl.index = -1; |
7484b8e6 | 8262 | tmpl.cmp_type = CMP_NONE; |
1f8b1395 AS |
8263 | tmpl.depind = 0; |
8264 | tmpl.file = NULL; | |
8265 | tmpl.line = 0; | |
8266 | tmpl.path = 0; | |
800eeca4 JW |
8267 | |
8268 | #define UNHANDLED \ | |
8269 | as_warn (_("Unhandled dependency %s for %s (%s), note %d"), \ | |
8270 | dep->name, idesc->name, (rsrc_write?"write":"read"), note) | |
8271 | #define KNOWN(REG) (gr_values[REG].known && gr_values[REG].path >= path) | |
8272 | ||
8273 | /* we don't need to track these */ | |
8274 | if (dep->semantics == IA64_DVS_NONE) | |
8275 | return 0; | |
8276 | ||
8277 | switch (dep->specifier) | |
8278 | { | |
8279 | case IA64_RS_AR_K: | |
8280 | if (note == 1) | |
542d6675 KH |
8281 | { |
8282 | if (idesc->operands[!rsrc_write] == IA64_OPND_AR3) | |
8283 | { | |
8284 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR; | |
8285 | if (regno >= 0 && regno <= 7) | |
8286 | { | |
8287 | specs[count] = tmpl; | |
8288 | specs[count++].index = regno; | |
8289 | } | |
8290 | } | |
8291 | } | |
800eeca4 | 8292 | else if (note == 0) |
542d6675 KH |
8293 | { |
8294 | for (i = 0; i < 8; i++) | |
8295 | { | |
8296 | specs[count] = tmpl; | |
8297 | specs[count++].index = i; | |
8298 | } | |
8299 | } | |
800eeca4 | 8300 | else |
542d6675 KH |
8301 | { |
8302 | UNHANDLED; | |
8303 | } | |
800eeca4 JW |
8304 | break; |
8305 | ||
8306 | case IA64_RS_AR_UNAT: | |
8307 | /* This is a mov =AR or mov AR= instruction. */ | |
8308 | if (idesc->operands[!rsrc_write] == IA64_OPND_AR3) | |
8309 | { | |
8310 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR; | |
8311 | if (regno == AR_UNAT) | |
8312 | { | |
8313 | specs[count++] = tmpl; | |
8314 | } | |
8315 | } | |
8316 | else | |
8317 | { | |
8318 | /* This is a spill/fill, or other instruction that modifies the | |
8319 | unat register. */ | |
8320 | ||
8321 | /* Unless we can determine the specific bits used, mark the whole | |
8322 | thing; bits 8:3 of the memory address indicate the bit used in | |
8323 | UNAT. The .mem.offset hint may be used to eliminate a small | |
8324 | subset of conflicts. */ | |
8325 | specs[count] = tmpl; | |
8326 | if (md.mem_offset.hint) | |
8327 | { | |
542d6675 KH |
8328 | if (md.debug_dv) |
8329 | fprintf (stderr, " Using hint for spill/fill\n"); | |
8330 | /* The index isn't actually used, just set it to something | |
8331 | approximating the bit index. */ | |
800eeca4 JW |
8332 | specs[count].index = (md.mem_offset.offset >> 3) & 0x3F; |
8333 | specs[count].mem_offset.hint = 1; | |
8334 | specs[count].mem_offset.offset = md.mem_offset.offset; | |
8335 | specs[count++].mem_offset.base = md.mem_offset.base; | |
8336 | } | |
8337 | else | |
8338 | { | |
8339 | specs[count++].specific = 0; | |
8340 | } | |
8341 | } | |
8342 | break; | |
8343 | ||
8344 | case IA64_RS_AR: | |
8345 | if (note == 1) | |
542d6675 KH |
8346 | { |
8347 | if (idesc->operands[!rsrc_write] == IA64_OPND_AR3) | |
8348 | { | |
8349 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR; | |
8350 | if ((regno >= 8 && regno <= 15) | |
8351 | || (regno >= 20 && regno <= 23) | |
8352 | || (regno >= 31 && regno <= 39) | |
8353 | || (regno >= 41 && regno <= 47) | |
8354 | || (regno >= 67 && regno <= 111)) | |
8355 | { | |
8356 | specs[count] = tmpl; | |
8357 | specs[count++].index = regno; | |
8358 | } | |
8359 | } | |
8360 | } | |
800eeca4 | 8361 | else |
542d6675 KH |
8362 | { |
8363 | UNHANDLED; | |
8364 | } | |
800eeca4 JW |
8365 | break; |
8366 | ||
8367 | case IA64_RS_ARb: | |
8368 | if (note == 1) | |
542d6675 KH |
8369 | { |
8370 | if (idesc->operands[!rsrc_write] == IA64_OPND_AR3) | |
8371 | { | |
8372 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR; | |
8373 | if ((regno >= 48 && regno <= 63) | |
8374 | || (regno >= 112 && regno <= 127)) | |
8375 | { | |
8376 | specs[count] = tmpl; | |
8377 | specs[count++].index = regno; | |
8378 | } | |
8379 | } | |
8380 | } | |
800eeca4 | 8381 | else if (note == 0) |
542d6675 KH |
8382 | { |
8383 | for (i = 48; i < 64; i++) | |
8384 | { | |
8385 | specs[count] = tmpl; | |
8386 | specs[count++].index = i; | |
8387 | } | |
8388 | for (i = 112; i < 128; i++) | |
8389 | { | |
8390 | specs[count] = tmpl; | |
8391 | specs[count++].index = i; | |
8392 | } | |
8393 | } | |
197865e8 | 8394 | else |
542d6675 KH |
8395 | { |
8396 | UNHANDLED; | |
8397 | } | |
800eeca4 JW |
8398 | break; |
8399 | ||
8400 | case IA64_RS_BR: | |
8401 | if (note != 1) | |
542d6675 KH |
8402 | { |
8403 | UNHANDLED; | |
8404 | } | |
800eeca4 | 8405 | else |
542d6675 KH |
8406 | { |
8407 | if (rsrc_write) | |
8408 | { | |
8409 | for (i = 0; i < idesc->num_outputs; i++) | |
8410 | if (idesc->operands[i] == IA64_OPND_B1 | |
8411 | || idesc->operands[i] == IA64_OPND_B2) | |
8412 | { | |
8413 | specs[count] = tmpl; | |
8414 | specs[count++].index = | |
8415 | CURR_SLOT.opnd[i].X_add_number - REG_BR; | |
8416 | } | |
8417 | } | |
8418 | else | |
8419 | { | |
40449e9f | 8420 | for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++) |
542d6675 KH |
8421 | if (idesc->operands[i] == IA64_OPND_B1 |
8422 | || idesc->operands[i] == IA64_OPND_B2) | |
8423 | { | |
8424 | specs[count] = tmpl; | |
8425 | specs[count++].index = | |
8426 | CURR_SLOT.opnd[i].X_add_number - REG_BR; | |
8427 | } | |
8428 | } | |
8429 | } | |
800eeca4 JW |
8430 | break; |
8431 | ||
8432 | case IA64_RS_CPUID: /* four or more registers */ | |
8433 | if (note == 3) | |
542d6675 KH |
8434 | { |
8435 | if (idesc->operands[!rsrc_write] == IA64_OPND_CPUID_R3) | |
8436 | { | |
8437 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR; | |
8438 | if (regno >= 0 && regno < NELEMS (gr_values) | |
8439 | && KNOWN (regno)) | |
8440 | { | |
8441 | specs[count] = tmpl; | |
8442 | specs[count++].index = gr_values[regno].value & 0xFF; | |
8443 | } | |
8444 | else | |
8445 | { | |
8446 | specs[count] = tmpl; | |
8447 | specs[count++].specific = 0; | |
8448 | } | |
8449 | } | |
8450 | } | |
800eeca4 | 8451 | else |
542d6675 KH |
8452 | { |
8453 | UNHANDLED; | |
8454 | } | |
800eeca4 JW |
8455 | break; |
8456 | ||
8457 | case IA64_RS_DBR: /* four or more registers */ | |
8458 | if (note == 3) | |
542d6675 KH |
8459 | { |
8460 | if (idesc->operands[!rsrc_write] == IA64_OPND_DBR_R3) | |
8461 | { | |
8462 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR; | |
8463 | if (regno >= 0 && regno < NELEMS (gr_values) | |
8464 | && KNOWN (regno)) | |
8465 | { | |
8466 | specs[count] = tmpl; | |
8467 | specs[count++].index = gr_values[regno].value & 0xFF; | |
8468 | } | |
8469 | else | |
8470 | { | |
8471 | specs[count] = tmpl; | |
8472 | specs[count++].specific = 0; | |
8473 | } | |
8474 | } | |
8475 | } | |
800eeca4 | 8476 | else if (note == 0 && !rsrc_write) |
542d6675 KH |
8477 | { |
8478 | specs[count] = tmpl; | |
8479 | specs[count++].specific = 0; | |
8480 | } | |
800eeca4 | 8481 | else |
542d6675 KH |
8482 | { |
8483 | UNHANDLED; | |
8484 | } | |
800eeca4 JW |
8485 | break; |
8486 | ||
8487 | case IA64_RS_IBR: /* four or more registers */ | |
8488 | if (note == 3) | |
542d6675 KH |
8489 | { |
8490 | if (idesc->operands[!rsrc_write] == IA64_OPND_IBR_R3) | |
8491 | { | |
8492 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR; | |
8493 | if (regno >= 0 && regno < NELEMS (gr_values) | |
8494 | && KNOWN (regno)) | |
8495 | { | |
8496 | specs[count] = tmpl; | |
8497 | specs[count++].index = gr_values[regno].value & 0xFF; | |
8498 | } | |
8499 | else | |
8500 | { | |
8501 | specs[count] = tmpl; | |
8502 | specs[count++].specific = 0; | |
8503 | } | |
8504 | } | |
8505 | } | |
800eeca4 | 8506 | else |
542d6675 KH |
8507 | { |
8508 | UNHANDLED; | |
8509 | } | |
800eeca4 JW |
8510 | break; |
8511 | ||
8512 | case IA64_RS_MSR: | |
8513 | if (note == 5) | |
8514 | { | |
8515 | /* These are implementation specific. Force all references to | |
8516 | conflict with all other references. */ | |
8517 | specs[count] = tmpl; | |
8518 | specs[count++].specific = 0; | |
8519 | } | |
8520 | else | |
8521 | { | |
8522 | UNHANDLED; | |
8523 | } | |
8524 | break; | |
8525 | ||
8526 | case IA64_RS_PKR: /* 16 or more registers */ | |
8527 | if (note == 3 || note == 4) | |
542d6675 KH |
8528 | { |
8529 | if (idesc->operands[!rsrc_write] == IA64_OPND_PKR_R3) | |
8530 | { | |
8531 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR; | |
8532 | if (regno >= 0 && regno < NELEMS (gr_values) | |
8533 | && KNOWN (regno)) | |
8534 | { | |
8535 | if (note == 3) | |
8536 | { | |
8537 | specs[count] = tmpl; | |
8538 | specs[count++].index = gr_values[regno].value & 0xFF; | |
8539 | } | |
8540 | else | |
8541 | for (i = 0; i < NELEMS (gr_values); i++) | |
8542 | { | |
8543 | /* Uses all registers *except* the one in R3. */ | |
2434f565 | 8544 | if ((unsigned)i != (gr_values[regno].value & 0xFF)) |
542d6675 KH |
8545 | { |
8546 | specs[count] = tmpl; | |
8547 | specs[count++].index = i; | |
8548 | } | |
8549 | } | |
8550 | } | |
8551 | else | |
8552 | { | |
8553 | specs[count] = tmpl; | |
8554 | specs[count++].specific = 0; | |
8555 | } | |
8556 | } | |
8557 | } | |
8558 | else if (note == 0) | |
8559 | { | |
8560 | /* probe et al. */ | |
8561 | specs[count] = tmpl; | |
8562 | specs[count++].specific = 0; | |
8563 | } | |
8564 | break; | |
8565 | ||
8566 | case IA64_RS_PMC: /* four or more registers */ | |
8567 | if (note == 3) | |
8568 | { | |
8569 | if (idesc->operands[!rsrc_write] == IA64_OPND_PMC_R3 | |
8570 | || (!rsrc_write && idesc->operands[1] == IA64_OPND_PMD_R3)) | |
8571 | ||
8572 | { | |
91d6fa6a NC |
8573 | int reg_index = ((idesc->operands[1] == IA64_OPND_R3 && !rsrc_write) |
8574 | ? 1 : !rsrc_write); | |
8575 | int regno = CURR_SLOT.opnd[reg_index].X_add_number - REG_GR; | |
542d6675 KH |
8576 | if (regno >= 0 && regno < NELEMS (gr_values) |
8577 | && KNOWN (regno)) | |
8578 | { | |
8579 | specs[count] = tmpl; | |
8580 | specs[count++].index = gr_values[regno].value & 0xFF; | |
8581 | } | |
8582 | else | |
8583 | { | |
8584 | specs[count] = tmpl; | |
8585 | specs[count++].specific = 0; | |
8586 | } | |
8587 | } | |
8588 | } | |
8589 | else | |
8590 | { | |
8591 | UNHANDLED; | |
8592 | } | |
800eeca4 JW |
8593 | break; |
8594 | ||
8595 | case IA64_RS_PMD: /* four or more registers */ | |
8596 | if (note == 3) | |
542d6675 KH |
8597 | { |
8598 | if (idesc->operands[!rsrc_write] == IA64_OPND_PMD_R3) | |
8599 | { | |
8600 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR; | |
8601 | if (regno >= 0 && regno < NELEMS (gr_values) | |
8602 | && KNOWN (regno)) | |
8603 | { | |
8604 | specs[count] = tmpl; | |
8605 | specs[count++].index = gr_values[regno].value & 0xFF; | |
8606 | } | |
8607 | else | |
8608 | { | |
8609 | specs[count] = tmpl; | |
8610 | specs[count++].specific = 0; | |
8611 | } | |
8612 | } | |
8613 | } | |
800eeca4 | 8614 | else |
542d6675 KH |
8615 | { |
8616 | UNHANDLED; | |
8617 | } | |
800eeca4 JW |
8618 | break; |
8619 | ||
8620 | case IA64_RS_RR: /* eight registers */ | |
8621 | if (note == 6) | |
542d6675 KH |
8622 | { |
8623 | if (idesc->operands[!rsrc_write] == IA64_OPND_RR_R3) | |
8624 | { | |
8625 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_GR; | |
8626 | if (regno >= 0 && regno < NELEMS (gr_values) | |
8627 | && KNOWN (regno)) | |
8628 | { | |
8629 | specs[count] = tmpl; | |
8630 | specs[count++].index = (gr_values[regno].value >> 61) & 0x7; | |
8631 | } | |
8632 | else | |
8633 | { | |
8634 | specs[count] = tmpl; | |
8635 | specs[count++].specific = 0; | |
8636 | } | |
8637 | } | |
8638 | } | |
800eeca4 | 8639 | else if (note == 0 && !rsrc_write) |
542d6675 KH |
8640 | { |
8641 | specs[count] = tmpl; | |
8642 | specs[count++].specific = 0; | |
8643 | } | |
197865e8 | 8644 | else |
542d6675 KH |
8645 | { |
8646 | UNHANDLED; | |
8647 | } | |
800eeca4 JW |
8648 | break; |
8649 | ||
8650 | case IA64_RS_CR_IRR: | |
197865e8 | 8651 | if (note == 0) |
542d6675 KH |
8652 | { |
8653 | /* handle mov-from-CR-IVR; it's a read that writes CR[IRR] */ | |
8654 | int regno = CURR_SLOT.opnd[1].X_add_number - REG_CR; | |
8655 | if (rsrc_write | |
8656 | && idesc->operands[1] == IA64_OPND_CR3 | |
8657 | && regno == CR_IVR) | |
8658 | { | |
8659 | for (i = 0; i < 4; i++) | |
8660 | { | |
8661 | specs[count] = tmpl; | |
8662 | specs[count++].index = CR_IRR0 + i; | |
8663 | } | |
8664 | } | |
8665 | } | |
800eeca4 | 8666 | else if (note == 1) |
542d6675 KH |
8667 | { |
8668 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR; | |
8669 | if (idesc->operands[!rsrc_write] == IA64_OPND_CR3 | |
8670 | && regno >= CR_IRR0 | |
8671 | && regno <= CR_IRR3) | |
8672 | { | |
8673 | specs[count] = tmpl; | |
8674 | specs[count++].index = regno; | |
8675 | } | |
8676 | } | |
800eeca4 | 8677 | else |
542d6675 KH |
8678 | { |
8679 | UNHANDLED; | |
8680 | } | |
800eeca4 JW |
8681 | break; |
8682 | ||
1ca35711 L |
8683 | case IA64_RS_CR_IIB: |
8684 | if (note != 0) | |
8685 | { | |
8686 | UNHANDLED; | |
8687 | } | |
8688 | else | |
8689 | { | |
8690 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR; | |
8691 | if (idesc->operands[!rsrc_write] == IA64_OPND_CR3 | |
8692 | && (regno == CR_IIB0 || regno == CR_IIB1)) | |
8693 | { | |
8694 | specs[count] = tmpl; | |
8695 | specs[count++].index = regno; | |
8696 | } | |
8697 | } | |
8698 | break; | |
8699 | ||
800eeca4 JW |
8700 | case IA64_RS_CR_LRR: |
8701 | if (note != 1) | |
542d6675 KH |
8702 | { |
8703 | UNHANDLED; | |
8704 | } | |
197865e8 | 8705 | else |
542d6675 KH |
8706 | { |
8707 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR; | |
8708 | if (idesc->operands[!rsrc_write] == IA64_OPND_CR3 | |
8709 | && (regno == CR_LRR0 || regno == CR_LRR1)) | |
8710 | { | |
8711 | specs[count] = tmpl; | |
8712 | specs[count++].index = regno; | |
8713 | } | |
8714 | } | |
800eeca4 JW |
8715 | break; |
8716 | ||
8717 | case IA64_RS_CR: | |
8718 | if (note == 1) | |
542d6675 KH |
8719 | { |
8720 | if (idesc->operands[!rsrc_write] == IA64_OPND_CR3) | |
8721 | { | |
8722 | specs[count] = tmpl; | |
8723 | specs[count++].index = | |
8724 | CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR; | |
8725 | } | |
8726 | } | |
800eeca4 | 8727 | else |
542d6675 KH |
8728 | { |
8729 | UNHANDLED; | |
8730 | } | |
800eeca4 JW |
8731 | break; |
8732 | ||
b3e14eda L |
8733 | case IA64_RS_DAHR: |
8734 | if (note == 0) | |
8735 | { | |
8736 | if (idesc->operands[!rsrc_write] == IA64_OPND_DAHR3) | |
8737 | { | |
8738 | specs[count] = tmpl; | |
8739 | specs[count++].index = | |
8740 | CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_DAHR; | |
8741 | } | |
8742 | } | |
8743 | else | |
8744 | { | |
8745 | UNHANDLED; | |
8746 | } | |
8747 | break; | |
8748 | ||
800eeca4 JW |
8749 | case IA64_RS_FR: |
8750 | case IA64_RS_FRb: | |
8751 | if (note != 1) | |
542d6675 KH |
8752 | { |
8753 | UNHANDLED; | |
8754 | } | |
800eeca4 | 8755 | else if (rsrc_write) |
542d6675 KH |
8756 | { |
8757 | if (dep->specifier == IA64_RS_FRb | |
8758 | && idesc->operands[0] == IA64_OPND_F1) | |
8759 | { | |
8760 | specs[count] = tmpl; | |
8761 | specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_FR; | |
8762 | } | |
8763 | } | |
800eeca4 | 8764 | else |
542d6675 KH |
8765 | { |
8766 | for (i = idesc->num_outputs; i < NELEMS (idesc->operands); i++) | |
8767 | { | |
8768 | if (idesc->operands[i] == IA64_OPND_F2 | |
8769 | || idesc->operands[i] == IA64_OPND_F3 | |
8770 | || idesc->operands[i] == IA64_OPND_F4) | |
8771 | { | |
8772 | specs[count] = tmpl; | |
8773 | specs[count++].index = | |
8774 | CURR_SLOT.opnd[i].X_add_number - REG_FR; | |
8775 | } | |
8776 | } | |
8777 | } | |
800eeca4 JW |
8778 | break; |
8779 | ||
8780 | case IA64_RS_GR: | |
8781 | if (note == 13) | |
542d6675 KH |
8782 | { |
8783 | /* This reference applies only to the GR whose value is loaded with | |
8784 | data returned from memory. */ | |
8785 | specs[count] = tmpl; | |
8786 | specs[count++].index = CURR_SLOT.opnd[0].X_add_number - REG_GR; | |
8787 | } | |
800eeca4 | 8788 | else if (note == 1) |
542d6675 KH |
8789 | { |
8790 | if (rsrc_write) | |
8791 | { | |
8792 | for (i = 0; i < idesc->num_outputs; i++) | |
50b81f19 JW |
8793 | if (idesc->operands[i] == IA64_OPND_R1 |
8794 | || idesc->operands[i] == IA64_OPND_R2 | |
8795 | || idesc->operands[i] == IA64_OPND_R3) | |
8796 | { | |
8797 | specs[count] = tmpl; | |
197865e8 | 8798 | specs[count++].index = |
50b81f19 JW |
8799 | CURR_SLOT.opnd[i].X_add_number - REG_GR; |
8800 | } | |
8801 | if (idesc->flags & IA64_OPCODE_POSTINC) | |
8802 | for (i = 0; i < NELEMS (idesc->operands); i++) | |
8803 | if (idesc->operands[i] == IA64_OPND_MR3) | |
8804 | { | |
8805 | specs[count] = tmpl; | |
8806 | specs[count++].index = | |
8807 | CURR_SLOT.opnd[i].X_add_number - REG_GR; | |
8808 | } | |
542d6675 KH |
8809 | } |
8810 | else | |
8811 | { | |
8812 | /* Look for anything that reads a GR. */ | |
8813 | for (i = 0; i < NELEMS (idesc->operands); i++) | |
8814 | { | |
8815 | if (idesc->operands[i] == IA64_OPND_MR3 | |
8816 | || idesc->operands[i] == IA64_OPND_CPUID_R3 | |
8817 | || idesc->operands[i] == IA64_OPND_DBR_R3 | |
8818 | || idesc->operands[i] == IA64_OPND_IBR_R3 | |
800eeca4 | 8819 | || idesc->operands[i] == IA64_OPND_MSR_R3 |
542d6675 KH |
8820 | || idesc->operands[i] == IA64_OPND_PKR_R3 |
8821 | || idesc->operands[i] == IA64_OPND_PMC_R3 | |
8822 | || idesc->operands[i] == IA64_OPND_PMD_R3 | |
b3e14eda | 8823 | || idesc->operands[i] == IA64_OPND_DAHR_R3 |
542d6675 KH |
8824 | || idesc->operands[i] == IA64_OPND_RR_R3 |
8825 | || ((i >= idesc->num_outputs) | |
8826 | && (idesc->operands[i] == IA64_OPND_R1 | |
8827 | || idesc->operands[i] == IA64_OPND_R2 | |
8828 | || idesc->operands[i] == IA64_OPND_R3 | |
50b81f19 JW |
8829 | /* addl source register. */ |
8830 | || idesc->operands[i] == IA64_OPND_R3_2))) | |
542d6675 KH |
8831 | { |
8832 | specs[count] = tmpl; | |
8833 | specs[count++].index = | |
8834 | CURR_SLOT.opnd[i].X_add_number - REG_GR; | |
8835 | } | |
8836 | } | |
8837 | } | |
8838 | } | |
197865e8 | 8839 | else |
542d6675 KH |
8840 | { |
8841 | UNHANDLED; | |
8842 | } | |
800eeca4 JW |
8843 | break; |
8844 | ||
139368c9 JW |
8845 | /* This is the same as IA64_RS_PRr, except that the register range is |
8846 | from 1 - 15, and there are no rotating register reads/writes here. */ | |
800eeca4 JW |
8847 | case IA64_RS_PR: |
8848 | if (note == 0) | |
542d6675 | 8849 | { |
139368c9 | 8850 | for (i = 1; i < 16; i++) |
542d6675 | 8851 | { |
139368c9 JW |
8852 | specs[count] = tmpl; |
8853 | specs[count++].index = i; | |
8854 | } | |
8855 | } | |
8856 | else if (note == 7) | |
8857 | { | |
8858 | valueT mask = 0; | |
8859 | /* Mark only those registers indicated by the mask. */ | |
8860 | if (rsrc_write) | |
8861 | { | |
8862 | mask = CURR_SLOT.opnd[2].X_add_number; | |
8863 | for (i = 1; i < 16; i++) | |
8864 | if (mask & ((valueT) 1 << i)) | |
8865 | { | |
8866 | specs[count] = tmpl; | |
8867 | specs[count++].index = i; | |
8868 | } | |
8869 | } | |
8870 | else | |
8871 | { | |
8872 | UNHANDLED; | |
8873 | } | |
8874 | } | |
8875 | else if (note == 11) /* note 11 implies note 1 as well */ | |
8876 | { | |
8877 | if (rsrc_write) | |
8878 | { | |
8879 | for (i = 0; i < idesc->num_outputs; i++) | |
8880 | { | |
8881 | if (idesc->operands[i] == IA64_OPND_P1 | |
8882 | || idesc->operands[i] == IA64_OPND_P2) | |
8883 | { | |
8884 | int regno = CURR_SLOT.opnd[i].X_add_number - REG_P; | |
8885 | if (regno >= 1 && regno < 16) | |
8886 | { | |
8887 | specs[count] = tmpl; | |
8888 | specs[count++].index = regno; | |
8889 | } | |
8890 | } | |
8891 | } | |
8892 | } | |
8893 | else | |
8894 | { | |
8895 | UNHANDLED; | |
8896 | } | |
8897 | } | |
8898 | else if (note == 12) | |
8899 | { | |
8900 | if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16) | |
8901 | { | |
8902 | specs[count] = tmpl; | |
8903 | specs[count++].index = CURR_SLOT.qp_regno; | |
8904 | } | |
8905 | } | |
8906 | else if (note == 1) | |
8907 | { | |
8908 | if (rsrc_write) | |
8909 | { | |
8910 | int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P; | |
8911 | int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P; | |
07726851 KH |
8912 | int or_andcm = strstr (idesc->name, "or.andcm") != NULL; |
8913 | int and_orcm = strstr (idesc->name, "and.orcm") != NULL; | |
139368c9 JW |
8914 | |
8915 | if ((idesc->operands[0] == IA64_OPND_P1 | |
8916 | || idesc->operands[0] == IA64_OPND_P2) | |
8917 | && p1 >= 1 && p1 < 16) | |
542d6675 KH |
8918 | { |
8919 | specs[count] = tmpl; | |
139368c9 JW |
8920 | specs[count].cmp_type = |
8921 | (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE)); | |
8922 | specs[count++].index = p1; | |
8923 | } | |
8924 | if ((idesc->operands[1] == IA64_OPND_P1 | |
8925 | || idesc->operands[1] == IA64_OPND_P2) | |
8926 | && p2 >= 1 && p2 < 16) | |
8927 | { | |
8928 | specs[count] = tmpl; | |
8929 | specs[count].cmp_type = | |
8930 | (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE)); | |
8931 | specs[count++].index = p2; | |
542d6675 KH |
8932 | } |
8933 | } | |
8934 | else | |
8935 | { | |
139368c9 | 8936 | if (CURR_SLOT.qp_regno >= 1 && CURR_SLOT.qp_regno < 16) |
542d6675 KH |
8937 | { |
8938 | specs[count] = tmpl; | |
139368c9 JW |
8939 | specs[count++].index = CURR_SLOT.qp_regno; |
8940 | } | |
8941 | if (idesc->operands[1] == IA64_OPND_PR) | |
8942 | { | |
8943 | for (i = 1; i < 16; i++) | |
8944 | { | |
8945 | specs[count] = tmpl; | |
8946 | specs[count++].index = i; | |
8947 | } | |
542d6675 KH |
8948 | } |
8949 | } | |
8950 | } | |
139368c9 JW |
8951 | else |
8952 | { | |
8953 | UNHANDLED; | |
8954 | } | |
8955 | break; | |
8956 | ||
8957 | /* This is the general case for PRs. IA64_RS_PR and IA64_RS_PR63 are | |
8958 | simplified cases of this. */ | |
8959 | case IA64_RS_PRr: | |
8960 | if (note == 0) | |
8961 | { | |
8962 | for (i = 16; i < 63; i++) | |
8963 | { | |
8964 | specs[count] = tmpl; | |
8965 | specs[count++].index = i; | |
8966 | } | |
8967 | } | |
800eeca4 | 8968 | else if (note == 7) |
542d6675 KH |
8969 | { |
8970 | valueT mask = 0; | |
8971 | /* Mark only those registers indicated by the mask. */ | |
8972 | if (rsrc_write | |
8973 | && idesc->operands[0] == IA64_OPND_PR) | |
8974 | { | |
8975 | mask = CURR_SLOT.opnd[2].X_add_number; | |
40449e9f | 8976 | if (mask & ((valueT) 1 << 16)) |
139368c9 JW |
8977 | for (i = 16; i < 63; i++) |
8978 | { | |
8979 | specs[count] = tmpl; | |
8980 | specs[count++].index = i; | |
8981 | } | |
542d6675 KH |
8982 | } |
8983 | else if (rsrc_write | |
8984 | && idesc->operands[0] == IA64_OPND_PR_ROT) | |
8985 | { | |
8986 | for (i = 16; i < 63; i++) | |
8987 | { | |
8988 | specs[count] = tmpl; | |
8989 | specs[count++].index = i; | |
8990 | } | |
8991 | } | |
8992 | else | |
8993 | { | |
8994 | UNHANDLED; | |
8995 | } | |
8996 | } | |
800eeca4 | 8997 | else if (note == 11) /* note 11 implies note 1 as well */ |
542d6675 KH |
8998 | { |
8999 | if (rsrc_write) | |
9000 | { | |
9001 | for (i = 0; i < idesc->num_outputs; i++) | |
9002 | { | |
9003 | if (idesc->operands[i] == IA64_OPND_P1 | |
9004 | || idesc->operands[i] == IA64_OPND_P2) | |
9005 | { | |
9006 | int regno = CURR_SLOT.opnd[i].X_add_number - REG_P; | |
139368c9 | 9007 | if (regno >= 16 && regno < 63) |
542d6675 KH |
9008 | { |
9009 | specs[count] = tmpl; | |
9010 | specs[count++].index = regno; | |
9011 | } | |
9012 | } | |
9013 | } | |
9014 | } | |
9015 | else | |
9016 | { | |
9017 | UNHANDLED; | |
9018 | } | |
9019 | } | |
800eeca4 | 9020 | else if (note == 12) |
542d6675 | 9021 | { |
139368c9 | 9022 | if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63) |
542d6675 KH |
9023 | { |
9024 | specs[count] = tmpl; | |
9025 | specs[count++].index = CURR_SLOT.qp_regno; | |
9026 | } | |
9027 | } | |
800eeca4 | 9028 | else if (note == 1) |
542d6675 KH |
9029 | { |
9030 | if (rsrc_write) | |
9031 | { | |
9032 | int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P; | |
9033 | int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P; | |
07726851 KH |
9034 | int or_andcm = strstr (idesc->name, "or.andcm") != NULL; |
9035 | int and_orcm = strstr (idesc->name, "and.orcm") != NULL; | |
7484b8e6 | 9036 | |
542d6675 KH |
9037 | if ((idesc->operands[0] == IA64_OPND_P1 |
9038 | || idesc->operands[0] == IA64_OPND_P2) | |
139368c9 | 9039 | && p1 >= 16 && p1 < 63) |
542d6675 KH |
9040 | { |
9041 | specs[count] = tmpl; | |
4a4f25cf | 9042 | specs[count].cmp_type = |
7484b8e6 | 9043 | (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE)); |
542d6675 KH |
9044 | specs[count++].index = p1; |
9045 | } | |
9046 | if ((idesc->operands[1] == IA64_OPND_P1 | |
9047 | || idesc->operands[1] == IA64_OPND_P2) | |
139368c9 | 9048 | && p2 >= 16 && p2 < 63) |
542d6675 KH |
9049 | { |
9050 | specs[count] = tmpl; | |
4a4f25cf | 9051 | specs[count].cmp_type = |
7484b8e6 | 9052 | (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE)); |
542d6675 KH |
9053 | specs[count++].index = p2; |
9054 | } | |
9055 | } | |
9056 | else | |
9057 | { | |
139368c9 | 9058 | if (CURR_SLOT.qp_regno >= 16 && CURR_SLOT.qp_regno < 63) |
542d6675 KH |
9059 | { |
9060 | specs[count] = tmpl; | |
9061 | specs[count++].index = CURR_SLOT.qp_regno; | |
9062 | } | |
9063 | if (idesc->operands[1] == IA64_OPND_PR) | |
9064 | { | |
139368c9 | 9065 | for (i = 16; i < 63; i++) |
542d6675 KH |
9066 | { |
9067 | specs[count] = tmpl; | |
9068 | specs[count++].index = i; | |
9069 | } | |
9070 | } | |
9071 | } | |
9072 | } | |
197865e8 | 9073 | else |
542d6675 KH |
9074 | { |
9075 | UNHANDLED; | |
9076 | } | |
800eeca4 JW |
9077 | break; |
9078 | ||
9079 | case IA64_RS_PSR: | |
197865e8 | 9080 | /* Verify that the instruction is using the PSR bit indicated in |
542d6675 | 9081 | dep->regindex. */ |
800eeca4 | 9082 | if (note == 0) |
542d6675 KH |
9083 | { |
9084 | if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_UM) | |
9085 | { | |
9086 | if (dep->regindex < 6) | |
9087 | { | |
9088 | specs[count++] = tmpl; | |
9089 | } | |
9090 | } | |
9091 | else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR) | |
9092 | { | |
9093 | if (dep->regindex < 32 | |
9094 | || dep->regindex == 35 | |
9095 | || dep->regindex == 36 | |
9096 | || (!rsrc_write && dep->regindex == PSR_CPL)) | |
9097 | { | |
9098 | specs[count++] = tmpl; | |
9099 | } | |
9100 | } | |
9101 | else if (idesc->operands[!rsrc_write] == IA64_OPND_PSR_L) | |
9102 | { | |
9103 | if (dep->regindex < 32 | |
9104 | || dep->regindex == 35 | |
9105 | || dep->regindex == 36 | |
9106 | || (rsrc_write && dep->regindex == PSR_CPL)) | |
9107 | { | |
9108 | specs[count++] = tmpl; | |
9109 | } | |
9110 | } | |
9111 | else | |
9112 | { | |
9113 | /* Several PSR bits have very specific dependencies. */ | |
9114 | switch (dep->regindex) | |
9115 | { | |
9116 | default: | |
9117 | specs[count++] = tmpl; | |
9118 | break; | |
9119 | case PSR_IC: | |
9120 | if (rsrc_write) | |
9121 | { | |
9122 | specs[count++] = tmpl; | |
9123 | } | |
9124 | else | |
9125 | { | |
9126 | /* Only certain CR accesses use PSR.ic */ | |
9127 | if (idesc->operands[0] == IA64_OPND_CR3 | |
9128 | || idesc->operands[1] == IA64_OPND_CR3) | |
9129 | { | |
91d6fa6a | 9130 | int reg_index = |
542d6675 KH |
9131 | ((idesc->operands[0] == IA64_OPND_CR3) |
9132 | ? 0 : 1); | |
9133 | int regno = | |
91d6fa6a | 9134 | CURR_SLOT.opnd[reg_index].X_add_number - REG_CR; |
542d6675 KH |
9135 | |
9136 | switch (regno) | |
9137 | { | |
9138 | default: | |
9139 | break; | |
9140 | case CR_ITIR: | |
9141 | case CR_IFS: | |
9142 | case CR_IIM: | |
9143 | case CR_IIP: | |
9144 | case CR_IPSR: | |
9145 | case CR_ISR: | |
9146 | case CR_IFA: | |
9147 | case CR_IHA: | |
1ca35711 L |
9148 | case CR_IIB0: |
9149 | case CR_IIB1: | |
542d6675 KH |
9150 | case CR_IIPA: |
9151 | specs[count++] = tmpl; | |
9152 | break; | |
9153 | } | |
9154 | } | |
9155 | } | |
9156 | break; | |
9157 | case PSR_CPL: | |
9158 | if (rsrc_write) | |
9159 | { | |
9160 | specs[count++] = tmpl; | |
9161 | } | |
9162 | else | |
9163 | { | |
9164 | /* Only some AR accesses use cpl */ | |
9165 | if (idesc->operands[0] == IA64_OPND_AR3 | |
9166 | || idesc->operands[1] == IA64_OPND_AR3) | |
9167 | { | |
91d6fa6a | 9168 | int reg_index = |
542d6675 KH |
9169 | ((idesc->operands[0] == IA64_OPND_AR3) |
9170 | ? 0 : 1); | |
9171 | int regno = | |
91d6fa6a | 9172 | CURR_SLOT.opnd[reg_index].X_add_number - REG_AR; |
542d6675 KH |
9173 | |
9174 | if (regno == AR_ITC | |
4f8631b1 | 9175 | || regno == AR_RUC |
91d6fa6a | 9176 | || (reg_index == 0 |
4f8631b1 | 9177 | && (regno == AR_RSC |
542d6675 KH |
9178 | || (regno >= AR_K0 |
9179 | && regno <= AR_K7)))) | |
9180 | { | |
9181 | specs[count++] = tmpl; | |
9182 | } | |
9183 | } | |
9184 | else | |
9185 | { | |
9186 | specs[count++] = tmpl; | |
9187 | } | |
9188 | break; | |
9189 | } | |
9190 | } | |
9191 | } | |
9192 | } | |
800eeca4 | 9193 | else if (note == 7) |
542d6675 KH |
9194 | { |
9195 | valueT mask = 0; | |
9196 | if (idesc->operands[0] == IA64_OPND_IMMU24) | |
9197 | { | |
9198 | mask = CURR_SLOT.opnd[0].X_add_number; | |
9199 | } | |
9200 | else | |
9201 | { | |
9202 | UNHANDLED; | |
9203 | } | |
9204 | if (mask & ((valueT) 1 << dep->regindex)) | |
9205 | { | |
9206 | specs[count++] = tmpl; | |
9207 | } | |
9208 | } | |
800eeca4 | 9209 | else if (note == 8) |
542d6675 KH |
9210 | { |
9211 | int min = dep->regindex == PSR_DFL ? 2 : 32; | |
9212 | int max = dep->regindex == PSR_DFL ? 31 : 127; | |
9213 | /* dfh is read on FR32-127; dfl is read on FR2-31 */ | |
9214 | for (i = 0; i < NELEMS (idesc->operands); i++) | |
9215 | { | |
9216 | if (idesc->operands[i] == IA64_OPND_F1 | |
9217 | || idesc->operands[i] == IA64_OPND_F2 | |
9218 | || idesc->operands[i] == IA64_OPND_F3 | |
9219 | || idesc->operands[i] == IA64_OPND_F4) | |
9220 | { | |
9221 | int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR; | |
9222 | if (reg >= min && reg <= max) | |
9223 | { | |
9224 | specs[count++] = tmpl; | |
9225 | } | |
9226 | } | |
9227 | } | |
9228 | } | |
800eeca4 | 9229 | else if (note == 9) |
542d6675 KH |
9230 | { |
9231 | int min = dep->regindex == PSR_MFL ? 2 : 32; | |
9232 | int max = dep->regindex == PSR_MFL ? 31 : 127; | |
9233 | /* mfh is read on writes to FR32-127; mfl is read on writes to | |
9234 | FR2-31 */ | |
9235 | for (i = 0; i < idesc->num_outputs; i++) | |
9236 | { | |
9237 | if (idesc->operands[i] == IA64_OPND_F1) | |
9238 | { | |
9239 | int reg = CURR_SLOT.opnd[i].X_add_number - REG_FR; | |
9240 | if (reg >= min && reg <= max) | |
9241 | { | |
9242 | specs[count++] = tmpl; | |
9243 | } | |
9244 | } | |
9245 | } | |
9246 | } | |
800eeca4 | 9247 | else if (note == 10) |
542d6675 KH |
9248 | { |
9249 | for (i = 0; i < NELEMS (idesc->operands); i++) | |
9250 | { | |
9251 | if (idesc->operands[i] == IA64_OPND_R1 | |
9252 | || idesc->operands[i] == IA64_OPND_R2 | |
9253 | || idesc->operands[i] == IA64_OPND_R3) | |
9254 | { | |
9255 | int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR; | |
9256 | if (regno >= 16 && regno <= 31) | |
9257 | { | |
9258 | specs[count++] = tmpl; | |
9259 | } | |
9260 | } | |
9261 | } | |
9262 | } | |
800eeca4 | 9263 | else |
542d6675 KH |
9264 | { |
9265 | UNHANDLED; | |
9266 | } | |
800eeca4 JW |
9267 | break; |
9268 | ||
9269 | case IA64_RS_AR_FPSR: | |
9270 | if (idesc->operands[!rsrc_write] == IA64_OPND_AR3) | |
542d6675 KH |
9271 | { |
9272 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR; | |
9273 | if (regno == AR_FPSR) | |
9274 | { | |
9275 | specs[count++] = tmpl; | |
9276 | } | |
9277 | } | |
800eeca4 | 9278 | else |
542d6675 KH |
9279 | { |
9280 | specs[count++] = tmpl; | |
9281 | } | |
800eeca4 JW |
9282 | break; |
9283 | ||
197865e8 | 9284 | case IA64_RS_ARX: |
800eeca4 JW |
9285 | /* Handle all AR[REG] resources */ |
9286 | if (note == 0 || note == 1) | |
542d6675 KH |
9287 | { |
9288 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_AR; | |
9289 | if (idesc->operands[!rsrc_write] == IA64_OPND_AR3 | |
9290 | && regno == dep->regindex) | |
9291 | { | |
9292 | specs[count++] = tmpl; | |
9293 | } | |
9294 | /* other AR[REG] resources may be affected by AR accesses */ | |
9295 | else if (idesc->operands[0] == IA64_OPND_AR3) | |
9296 | { | |
9297 | /* AR[] writes */ | |
9298 | regno = CURR_SLOT.opnd[0].X_add_number - REG_AR; | |
9299 | switch (dep->regindex) | |
9300 | { | |
9301 | default: | |
9302 | break; | |
9303 | case AR_BSP: | |
9304 | case AR_RNAT: | |
9305 | if (regno == AR_BSPSTORE) | |
9306 | { | |
9307 | specs[count++] = tmpl; | |
9308 | } | |
9309 | case AR_RSC: | |
9310 | if (!rsrc_write && | |
9311 | (regno == AR_BSPSTORE | |
9312 | || regno == AR_RNAT)) | |
9313 | { | |
9314 | specs[count++] = tmpl; | |
9315 | } | |
9316 | break; | |
9317 | } | |
9318 | } | |
9319 | else if (idesc->operands[1] == IA64_OPND_AR3) | |
9320 | { | |
9321 | /* AR[] reads */ | |
9322 | regno = CURR_SLOT.opnd[1].X_add_number - REG_AR; | |
9323 | switch (dep->regindex) | |
9324 | { | |
9325 | default: | |
9326 | break; | |
9327 | case AR_RSC: | |
9328 | if (regno == AR_BSPSTORE || regno == AR_RNAT) | |
9329 | { | |
9330 | specs[count++] = tmpl; | |
9331 | } | |
9332 | break; | |
9333 | } | |
9334 | } | |
9335 | else | |
9336 | { | |
9337 | specs[count++] = tmpl; | |
9338 | } | |
9339 | } | |
800eeca4 | 9340 | else |
542d6675 KH |
9341 | { |
9342 | UNHANDLED; | |
9343 | } | |
800eeca4 JW |
9344 | break; |
9345 | ||
9346 | case IA64_RS_CRX: | |
7f3dfb9c L |
9347 | /* Handle all CR[REG] resources. |
9348 | ??? FIXME: The rule 17 isn't really handled correctly. */ | |
9349 | if (note == 0 || note == 1 || note == 17) | |
542d6675 KH |
9350 | { |
9351 | if (idesc->operands[!rsrc_write] == IA64_OPND_CR3) | |
9352 | { | |
9353 | int regno = CURR_SLOT.opnd[!rsrc_write].X_add_number - REG_CR; | |
9354 | if (regno == dep->regindex) | |
9355 | { | |
9356 | specs[count++] = tmpl; | |
9357 | } | |
9358 | else if (!rsrc_write) | |
9359 | { | |
9360 | /* Reads from CR[IVR] affect other resources. */ | |
9361 | if (regno == CR_IVR) | |
9362 | { | |
9363 | if ((dep->regindex >= CR_IRR0 | |
9364 | && dep->regindex <= CR_IRR3) | |
9365 | || dep->regindex == CR_TPR) | |
9366 | { | |
9367 | specs[count++] = tmpl; | |
9368 | } | |
9369 | } | |
9370 | } | |
9371 | } | |
9372 | else | |
9373 | { | |
9374 | specs[count++] = tmpl; | |
9375 | } | |
9376 | } | |
800eeca4 | 9377 | else |
542d6675 KH |
9378 | { |
9379 | UNHANDLED; | |
9380 | } | |
800eeca4 JW |
9381 | break; |
9382 | ||
9383 | case IA64_RS_INSERVICE: | |
9384 | /* look for write of EOI (67) or read of IVR (65) */ | |
9385 | if ((idesc->operands[0] == IA64_OPND_CR3 | |
542d6675 KH |
9386 | && CURR_SLOT.opnd[0].X_add_number - REG_CR == CR_EOI) |
9387 | || (idesc->operands[1] == IA64_OPND_CR3 | |
9388 | && CURR_SLOT.opnd[1].X_add_number - REG_CR == CR_IVR)) | |
9389 | { | |
9390 | specs[count++] = tmpl; | |
9391 | } | |
800eeca4 JW |
9392 | break; |
9393 | ||
9394 | case IA64_RS_GR0: | |
9395 | if (note == 1) | |
542d6675 KH |
9396 | { |
9397 | specs[count++] = tmpl; | |
9398 | } | |
800eeca4 | 9399 | else |
542d6675 KH |
9400 | { |
9401 | UNHANDLED; | |
9402 | } | |
800eeca4 JW |
9403 | break; |
9404 | ||
9405 | case IA64_RS_CFM: | |
9406 | if (note != 2) | |
542d6675 KH |
9407 | { |
9408 | specs[count++] = tmpl; | |
9409 | } | |
800eeca4 | 9410 | else |
542d6675 KH |
9411 | { |
9412 | /* Check if any of the registers accessed are in the rotating region. | |
9413 | mov to/from pr accesses CFM only when qp_regno is in the rotating | |
9414 | region */ | |
9415 | for (i = 0; i < NELEMS (idesc->operands); i++) | |
9416 | { | |
9417 | if (idesc->operands[i] == IA64_OPND_R1 | |
9418 | || idesc->operands[i] == IA64_OPND_R2 | |
9419 | || idesc->operands[i] == IA64_OPND_R3) | |
9420 | { | |
9421 | int num = CURR_SLOT.opnd[i].X_add_number - REG_GR; | |
9422 | /* Assumes that md.rot.num_regs is always valid */ | |
9423 | if (md.rot.num_regs > 0 | |
9424 | && num > 31 | |
9425 | && num < 31 + md.rot.num_regs) | |
9426 | { | |
9427 | specs[count] = tmpl; | |
9428 | specs[count++].specific = 0; | |
9429 | } | |
9430 | } | |
9431 | else if (idesc->operands[i] == IA64_OPND_F1 | |
9432 | || idesc->operands[i] == IA64_OPND_F2 | |
9433 | || idesc->operands[i] == IA64_OPND_F3 | |
9434 | || idesc->operands[i] == IA64_OPND_F4) | |
9435 | { | |
9436 | int num = CURR_SLOT.opnd[i].X_add_number - REG_FR; | |
9437 | if (num > 31) | |
9438 | { | |
9439 | specs[count] = tmpl; | |
9440 | specs[count++].specific = 0; | |
9441 | } | |
9442 | } | |
9443 | else if (idesc->operands[i] == IA64_OPND_P1 | |
9444 | || idesc->operands[i] == IA64_OPND_P2) | |
9445 | { | |
9446 | int num = CURR_SLOT.opnd[i].X_add_number - REG_P; | |
9447 | if (num > 15) | |
9448 | { | |
9449 | specs[count] = tmpl; | |
9450 | specs[count++].specific = 0; | |
9451 | } | |
9452 | } | |
9453 | } | |
9454 | if (CURR_SLOT.qp_regno > 15) | |
9455 | { | |
9456 | specs[count] = tmpl; | |
9457 | specs[count++].specific = 0; | |
9458 | } | |
9459 | } | |
800eeca4 JW |
9460 | break; |
9461 | ||
139368c9 JW |
9462 | /* This is the same as IA64_RS_PRr, except simplified to account for |
9463 | the fact that there is only one register. */ | |
800eeca4 JW |
9464 | case IA64_RS_PR63: |
9465 | if (note == 0) | |
542d6675 KH |
9466 | { |
9467 | specs[count++] = tmpl; | |
9468 | } | |
139368c9 | 9469 | else if (note == 7) |
40449e9f KH |
9470 | { |
9471 | valueT mask = 0; | |
9472 | if (idesc->operands[2] == IA64_OPND_IMM17) | |
9473 | mask = CURR_SLOT.opnd[2].X_add_number; | |
9474 | if (mask & ((valueT) 1 << 63)) | |
139368c9 | 9475 | specs[count++] = tmpl; |
40449e9f | 9476 | } |
800eeca4 | 9477 | else if (note == 11) |
542d6675 KH |
9478 | { |
9479 | if ((idesc->operands[0] == IA64_OPND_P1 | |
9480 | && CURR_SLOT.opnd[0].X_add_number - REG_P == 63) | |
9481 | || (idesc->operands[1] == IA64_OPND_P2 | |
9482 | && CURR_SLOT.opnd[1].X_add_number - REG_P == 63)) | |
9483 | { | |
9484 | specs[count++] = tmpl; | |
9485 | } | |
9486 | } | |
800eeca4 | 9487 | else if (note == 12) |
542d6675 KH |
9488 | { |
9489 | if (CURR_SLOT.qp_regno == 63) | |
9490 | { | |
9491 | specs[count++] = tmpl; | |
9492 | } | |
9493 | } | |
800eeca4 | 9494 | else if (note == 1) |
542d6675 KH |
9495 | { |
9496 | if (rsrc_write) | |
9497 | { | |
40449e9f KH |
9498 | int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P; |
9499 | int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P; | |
07726851 KH |
9500 | int or_andcm = strstr (idesc->name, "or.andcm") != NULL; |
9501 | int and_orcm = strstr (idesc->name, "and.orcm") != NULL; | |
7484b8e6 | 9502 | |
4a4f25cf | 9503 | if (p1 == 63 |
7484b8e6 TW |
9504 | && (idesc->operands[0] == IA64_OPND_P1 |
9505 | || idesc->operands[0] == IA64_OPND_P2)) | |
9506 | { | |
40449e9f | 9507 | specs[count] = tmpl; |
4a4f25cf | 9508 | specs[count++].cmp_type = |
7484b8e6 TW |
9509 | (or_andcm ? CMP_OR : (and_orcm ? CMP_AND : CMP_NONE)); |
9510 | } | |
9511 | if (p2 == 63 | |
9512 | && (idesc->operands[1] == IA64_OPND_P1 | |
9513 | || idesc->operands[1] == IA64_OPND_P2)) | |
9514 | { | |
40449e9f | 9515 | specs[count] = tmpl; |
4a4f25cf | 9516 | specs[count++].cmp_type = |
7484b8e6 TW |
9517 | (or_andcm ? CMP_AND : (and_orcm ? CMP_OR : CMP_NONE)); |
9518 | } | |
542d6675 KH |
9519 | } |
9520 | else | |
9521 | { | |
9522 | if (CURR_SLOT.qp_regno == 63) | |
9523 | { | |
9524 | specs[count++] = tmpl; | |
9525 | } | |
9526 | } | |
9527 | } | |
800eeca4 | 9528 | else |
542d6675 KH |
9529 | { |
9530 | UNHANDLED; | |
9531 | } | |
800eeca4 JW |
9532 | break; |
9533 | ||
9534 | case IA64_RS_RSE: | |
9535 | /* FIXME we can identify some individual RSE written resources, but RSE | |
542d6675 KH |
9536 | read resources have not yet been completely identified, so for now |
9537 | treat RSE as a single resource */ | |
800eeca4 | 9538 | if (strncmp (idesc->name, "mov", 3) == 0) |
542d6675 KH |
9539 | { |
9540 | if (rsrc_write) | |
9541 | { | |
9542 | if (idesc->operands[0] == IA64_OPND_AR3 | |
9543 | && CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE) | |
9544 | { | |
a66d2bb7 | 9545 | specs[count++] = tmpl; |
542d6675 KH |
9546 | } |
9547 | } | |
9548 | else | |
9549 | { | |
9550 | if (idesc->operands[0] == IA64_OPND_AR3) | |
9551 | { | |
9552 | if (CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_BSPSTORE | |
9553 | || CURR_SLOT.opnd[0].X_add_number - REG_AR == AR_RNAT) | |
9554 | { | |
9555 | specs[count++] = tmpl; | |
9556 | } | |
9557 | } | |
9558 | else if (idesc->operands[1] == IA64_OPND_AR3) | |
9559 | { | |
9560 | if (CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSP | |
9561 | || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_BSPSTORE | |
9562 | || CURR_SLOT.opnd[1].X_add_number - REG_AR == AR_RNAT) | |
9563 | { | |
9564 | specs[count++] = tmpl; | |
9565 | } | |
9566 | } | |
9567 | } | |
9568 | } | |
197865e8 | 9569 | else |
542d6675 KH |
9570 | { |
9571 | specs[count++] = tmpl; | |
9572 | } | |
800eeca4 JW |
9573 | break; |
9574 | ||
9575 | case IA64_RS_ANY: | |
9576 | /* FIXME -- do any of these need to be non-specific? */ | |
9577 | specs[count++] = tmpl; | |
9578 | break; | |
9579 | ||
9580 | default: | |
9581 | as_bad (_("Unrecognized dependency specifier %d\n"), dep->specifier); | |
9582 | break; | |
9583 | } | |
9584 | ||
9585 | return count; | |
9586 | } | |
9587 | ||
9588 | /* Clear branch flags on marked resources. This breaks the link between the | |
542d6675 KH |
9589 | QP of the marking instruction and a subsequent branch on the same QP. */ |
9590 | ||
800eeca4 | 9591 | static void |
5a49b8ac | 9592 | clear_qp_branch_flag (valueT mask) |
800eeca4 JW |
9593 | { |
9594 | int i; | |
542d6675 | 9595 | for (i = 0; i < regdepslen; i++) |
800eeca4 | 9596 | { |
197865e8 | 9597 | valueT bit = ((valueT) 1 << regdeps[i].qp_regno); |
800eeca4 | 9598 | if ((bit & mask) != 0) |
542d6675 KH |
9599 | { |
9600 | regdeps[i].link_to_qp_branch = 0; | |
9601 | } | |
800eeca4 JW |
9602 | } |
9603 | } | |
9604 | ||
5e2f6673 L |
9605 | /* MASK contains 2 and only 2 PRs which are mutually exclusive. Remove |
9606 | any mutexes which contain one of the PRs and create new ones when | |
9607 | needed. */ | |
9608 | ||
9609 | static int | |
9610 | update_qp_mutex (valueT mask) | |
9611 | { | |
9612 | int i; | |
9613 | int add = 0; | |
9614 | ||
9615 | i = 0; | |
9616 | while (i < qp_mutexeslen) | |
9617 | { | |
9618 | if ((qp_mutexes[i].prmask & mask) != 0) | |
9619 | { | |
9620 | /* If it destroys and creates the same mutex, do nothing. */ | |
9621 | if (qp_mutexes[i].prmask == mask | |
9622 | && qp_mutexes[i].path == md.path) | |
9623 | { | |
9624 | i++; | |
9625 | add = -1; | |
9626 | } | |
9627 | else | |
9628 | { | |
9629 | int keep = 0; | |
9630 | ||
9631 | if (md.debug_dv) | |
9632 | { | |
9633 | fprintf (stderr, " Clearing mutex relation"); | |
9634 | print_prmask (qp_mutexes[i].prmask); | |
9635 | fprintf (stderr, "\n"); | |
9636 | } | |
3739860c | 9637 | |
5e2f6673 L |
9638 | /* Deal with the old mutex with more than 3+ PRs only if |
9639 | the new mutex on the same execution path with it. | |
9640 | ||
9641 | FIXME: The 3+ mutex support is incomplete. | |
9642 | dot_pred_rel () may be a better place to fix it. */ | |
9643 | if (qp_mutexes[i].path == md.path) | |
9644 | { | |
9645 | /* If it is a proper subset of the mutex, create a | |
9646 | new mutex. */ | |
9647 | if (add == 0 | |
9648 | && (qp_mutexes[i].prmask & mask) == mask) | |
9649 | add = 1; | |
3739860c | 9650 | |
5e2f6673 L |
9651 | qp_mutexes[i].prmask &= ~mask; |
9652 | if (qp_mutexes[i].prmask & (qp_mutexes[i].prmask - 1)) | |
9653 | { | |
9654 | /* Modify the mutex if there are more than one | |
9655 | PR left. */ | |
9656 | keep = 1; | |
9657 | i++; | |
9658 | } | |
9659 | } | |
3739860c | 9660 | |
5e2f6673 L |
9661 | if (keep == 0) |
9662 | /* Remove the mutex. */ | |
9663 | qp_mutexes[i] = qp_mutexes[--qp_mutexeslen]; | |
9664 | } | |
9665 | } | |
9666 | else | |
9667 | ++i; | |
9668 | } | |
9669 | ||
9670 | if (add == 1) | |
9671 | add_qp_mutex (mask); | |
9672 | ||
9673 | return add; | |
9674 | } | |
9675 | ||
197865e8 | 9676 | /* Remove any mutexes which contain any of the PRs indicated in the mask. |
800eeca4 | 9677 | |
542d6675 KH |
9678 | Any changes to a PR clears the mutex relations which include that PR. */ |
9679 | ||
800eeca4 | 9680 | static void |
5a49b8ac | 9681 | clear_qp_mutex (valueT mask) |
800eeca4 JW |
9682 | { |
9683 | int i; | |
9684 | ||
9685 | i = 0; | |
9686 | while (i < qp_mutexeslen) | |
9687 | { | |
9688 | if ((qp_mutexes[i].prmask & mask) != 0) | |
542d6675 KH |
9689 | { |
9690 | if (md.debug_dv) | |
9691 | { | |
9692 | fprintf (stderr, " Clearing mutex relation"); | |
9693 | print_prmask (qp_mutexes[i].prmask); | |
9694 | fprintf (stderr, "\n"); | |
9695 | } | |
9696 | qp_mutexes[i] = qp_mutexes[--qp_mutexeslen]; | |
9697 | } | |
800eeca4 | 9698 | else |
542d6675 | 9699 | ++i; |
800eeca4 JW |
9700 | } |
9701 | } | |
9702 | ||
9703 | /* Clear implies relations which contain PRs in the given masks. | |
9704 | P1_MASK indicates the source of the implies relation, while P2_MASK | |
542d6675 KH |
9705 | indicates the implied PR. */ |
9706 | ||
800eeca4 | 9707 | static void |
5a49b8ac | 9708 | clear_qp_implies (valueT p1_mask, valueT p2_mask) |
800eeca4 JW |
9709 | { |
9710 | int i; | |
9711 | ||
9712 | i = 0; | |
9713 | while (i < qp_implieslen) | |
9714 | { | |
197865e8 | 9715 | if ((((valueT) 1 << qp_implies[i].p1) & p1_mask) != 0 |
542d6675 KH |
9716 | || (((valueT) 1 << qp_implies[i].p2) & p2_mask) != 0) |
9717 | { | |
9718 | if (md.debug_dv) | |
9719 | fprintf (stderr, "Clearing implied relation PR%d->PR%d\n", | |
9720 | qp_implies[i].p1, qp_implies[i].p2); | |
9721 | qp_implies[i] = qp_implies[--qp_implieslen]; | |
9722 | } | |
197865e8 | 9723 | else |
542d6675 | 9724 | ++i; |
800eeca4 JW |
9725 | } |
9726 | } | |
9727 | ||
542d6675 KH |
9728 | /* Add the PRs specified to the list of implied relations. */ |
9729 | ||
800eeca4 | 9730 | static void |
5a49b8ac | 9731 | add_qp_imply (int p1, int p2) |
800eeca4 JW |
9732 | { |
9733 | valueT mask; | |
9734 | valueT bit; | |
9735 | int i; | |
9736 | ||
542d6675 | 9737 | /* p0 is not meaningful here. */ |
800eeca4 JW |
9738 | if (p1 == 0 || p2 == 0) |
9739 | abort (); | |
9740 | ||
9741 | if (p1 == p2) | |
9742 | return; | |
9743 | ||
542d6675 KH |
9744 | /* If it exists already, ignore it. */ |
9745 | for (i = 0; i < qp_implieslen; i++) | |
800eeca4 | 9746 | { |
197865e8 | 9747 | if (qp_implies[i].p1 == p1 |
542d6675 KH |
9748 | && qp_implies[i].p2 == p2 |
9749 | && qp_implies[i].path == md.path | |
9750 | && !qp_implies[i].p2_branched) | |
9751 | return; | |
800eeca4 JW |
9752 | } |
9753 | ||
9754 | if (qp_implieslen == qp_impliestotlen) | |
9755 | { | |
9756 | qp_impliestotlen += 20; | |
9757 | qp_implies = (struct qp_imply *) | |
542d6675 KH |
9758 | xrealloc ((void *) qp_implies, |
9759 | qp_impliestotlen * sizeof (struct qp_imply)); | |
800eeca4 JW |
9760 | } |
9761 | if (md.debug_dv) | |
9762 | fprintf (stderr, " Registering PR%d implies PR%d\n", p1, p2); | |
9763 | qp_implies[qp_implieslen].p1 = p1; | |
9764 | qp_implies[qp_implieslen].p2 = p2; | |
9765 | qp_implies[qp_implieslen].path = md.path; | |
9766 | qp_implies[qp_implieslen++].p2_branched = 0; | |
9767 | ||
9768 | /* Add in the implied transitive relations; for everything that p2 implies, | |
9769 | make p1 imply that, too; for everything that implies p1, make it imply p2 | |
197865e8 | 9770 | as well. */ |
542d6675 | 9771 | for (i = 0; i < qp_implieslen; i++) |
800eeca4 JW |
9772 | { |
9773 | if (qp_implies[i].p1 == p2) | |
542d6675 | 9774 | add_qp_imply (p1, qp_implies[i].p2); |
800eeca4 | 9775 | if (qp_implies[i].p2 == p1) |
542d6675 | 9776 | add_qp_imply (qp_implies[i].p1, p2); |
800eeca4 JW |
9777 | } |
9778 | /* Add in mutex relations implied by this implies relation; for each mutex | |
197865e8 KH |
9779 | relation containing p2, duplicate it and replace p2 with p1. */ |
9780 | bit = (valueT) 1 << p1; | |
9781 | mask = (valueT) 1 << p2; | |
542d6675 | 9782 | for (i = 0; i < qp_mutexeslen; i++) |
800eeca4 JW |
9783 | { |
9784 | if (qp_mutexes[i].prmask & mask) | |
542d6675 | 9785 | add_qp_mutex ((qp_mutexes[i].prmask & ~mask) | bit); |
800eeca4 JW |
9786 | } |
9787 | } | |
9788 | ||
800eeca4 JW |
9789 | /* Add the PRs specified in the mask to the mutex list; this means that only |
9790 | one of the PRs can be true at any time. PR0 should never be included in | |
9791 | the mask. */ | |
542d6675 | 9792 | |
800eeca4 | 9793 | static void |
5a49b8ac | 9794 | add_qp_mutex (valueT mask) |
800eeca4 JW |
9795 | { |
9796 | if (mask & 0x1) | |
9797 | abort (); | |
9798 | ||
9799 | if (qp_mutexeslen == qp_mutexestotlen) | |
9800 | { | |
9801 | qp_mutexestotlen += 20; | |
9802 | qp_mutexes = (struct qpmutex *) | |
542d6675 KH |
9803 | xrealloc ((void *) qp_mutexes, |
9804 | qp_mutexestotlen * sizeof (struct qpmutex)); | |
800eeca4 JW |
9805 | } |
9806 | if (md.debug_dv) | |
9807 | { | |
9808 | fprintf (stderr, " Registering mutex on"); | |
9809 | print_prmask (mask); | |
9810 | fprintf (stderr, "\n"); | |
9811 | } | |
9812 | qp_mutexes[qp_mutexeslen].path = md.path; | |
9813 | qp_mutexes[qp_mutexeslen++].prmask = mask; | |
9814 | } | |
9815 | ||
cb5301b6 | 9816 | static int |
5a49b8ac | 9817 | has_suffix_p (const char *name, const char *suffix) |
cb5301b6 RH |
9818 | { |
9819 | size_t namelen = strlen (name); | |
9820 | size_t sufflen = strlen (suffix); | |
9821 | ||
9822 | if (namelen <= sufflen) | |
9823 | return 0; | |
9824 | return strcmp (name + namelen - sufflen, suffix) == 0; | |
9825 | } | |
9826 | ||
800eeca4 | 9827 | static void |
5a49b8ac | 9828 | clear_register_values (void) |
800eeca4 JW |
9829 | { |
9830 | int i; | |
9831 | if (md.debug_dv) | |
9832 | fprintf (stderr, " Clearing register values\n"); | |
542d6675 | 9833 | for (i = 1; i < NELEMS (gr_values); i++) |
800eeca4 JW |
9834 | gr_values[i].known = 0; |
9835 | } | |
9836 | ||
9837 | /* Keep track of register values/changes which affect DV tracking. | |
9838 | ||
9839 | optimization note: should add a flag to classes of insns where otherwise we | |
542d6675 | 9840 | have to examine a group of strings to identify them. */ |
800eeca4 | 9841 | |
800eeca4 | 9842 | static void |
5a49b8ac | 9843 | note_register_values (struct ia64_opcode *idesc) |
800eeca4 JW |
9844 | { |
9845 | valueT qp_changemask = 0; | |
9846 | int i; | |
9847 | ||
542d6675 KH |
9848 | /* Invalidate values for registers being written to. */ |
9849 | for (i = 0; i < idesc->num_outputs; i++) | |
800eeca4 | 9850 | { |
197865e8 | 9851 | if (idesc->operands[i] == IA64_OPND_R1 |
542d6675 KH |
9852 | || idesc->operands[i] == IA64_OPND_R2 |
9853 | || idesc->operands[i] == IA64_OPND_R3) | |
9854 | { | |
9855 | int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR; | |
9856 | if (regno > 0 && regno < NELEMS (gr_values)) | |
9857 | gr_values[regno].known = 0; | |
9858 | } | |
50b81f19 JW |
9859 | else if (idesc->operands[i] == IA64_OPND_R3_2) |
9860 | { | |
9861 | int regno = CURR_SLOT.opnd[i].X_add_number - REG_GR; | |
9862 | if (regno > 0 && regno < 4) | |
9863 | gr_values[regno].known = 0; | |
9864 | } | |
197865e8 | 9865 | else if (idesc->operands[i] == IA64_OPND_P1 |
542d6675 KH |
9866 | || idesc->operands[i] == IA64_OPND_P2) |
9867 | { | |
9868 | int regno = CURR_SLOT.opnd[i].X_add_number - REG_P; | |
9869 | qp_changemask |= (valueT) 1 << regno; | |
9870 | } | |
800eeca4 | 9871 | else if (idesc->operands[i] == IA64_OPND_PR) |
542d6675 KH |
9872 | { |
9873 | if (idesc->operands[2] & (valueT) 0x10000) | |
9874 | qp_changemask = ~(valueT) 0x1FFFF | idesc->operands[2]; | |
9875 | else | |
9876 | qp_changemask = idesc->operands[2]; | |
9877 | break; | |
9878 | } | |
800eeca4 | 9879 | else if (idesc->operands[i] == IA64_OPND_PR_ROT) |
542d6675 KH |
9880 | { |
9881 | if (idesc->operands[1] & ((valueT) 1 << 43)) | |
6344efa4 | 9882 | qp_changemask = -((valueT) 1 << 44) | idesc->operands[1]; |
542d6675 KH |
9883 | else |
9884 | qp_changemask = idesc->operands[1]; | |
9885 | qp_changemask &= ~(valueT) 0xFFFF; | |
9886 | break; | |
9887 | } | |
9888 | } | |
9889 | ||
9890 | /* Always clear qp branch flags on any PR change. */ | |
9891 | /* FIXME there may be exceptions for certain compares. */ | |
800eeca4 JW |
9892 | clear_qp_branch_flag (qp_changemask); |
9893 | ||
542d6675 | 9894 | /* Invalidate rotating registers on insns which affect RRBs in CFM. */ |
800eeca4 JW |
9895 | if (idesc->flags & IA64_OPCODE_MOD_RRBS) |
9896 | { | |
197865e8 | 9897 | qp_changemask |= ~(valueT) 0xFFFF; |
800eeca4 | 9898 | if (strcmp (idesc->name, "clrrrb.pr") != 0) |
542d6675 KH |
9899 | { |
9900 | for (i = 32; i < 32 + md.rot.num_regs; i++) | |
9901 | gr_values[i].known = 0; | |
9902 | } | |
800eeca4 JW |
9903 | clear_qp_mutex (qp_changemask); |
9904 | clear_qp_implies (qp_changemask, qp_changemask); | |
9905 | } | |
542d6675 KH |
9906 | /* After a call, all register values are undefined, except those marked |
9907 | as "safe". */ | |
800eeca4 | 9908 | else if (strncmp (idesc->name, "br.call", 6) == 0 |
542d6675 | 9909 | || strncmp (idesc->name, "brl.call", 7) == 0) |
800eeca4 | 9910 | { |
56d27c17 | 9911 | /* FIXME keep GR values which are marked as "safe_across_calls" */ |
800eeca4 JW |
9912 | clear_register_values (); |
9913 | clear_qp_mutex (~qp_safe_across_calls); | |
9914 | clear_qp_implies (~qp_safe_across_calls, ~qp_safe_across_calls); | |
9915 | clear_qp_branch_flag (~qp_safe_across_calls); | |
9916 | } | |
e9718fe1 | 9917 | else if (is_interruption_or_rfi (idesc) |
542d6675 | 9918 | || is_taken_branch (idesc)) |
e9718fe1 TW |
9919 | { |
9920 | clear_register_values (); | |
197865e8 KH |
9921 | clear_qp_mutex (~(valueT) 0); |
9922 | clear_qp_implies (~(valueT) 0, ~(valueT) 0); | |
e9718fe1 | 9923 | } |
542d6675 | 9924 | /* Look for mutex and implies relations. */ |
197865e8 | 9925 | else if ((idesc->operands[0] == IA64_OPND_P1 |
542d6675 KH |
9926 | || idesc->operands[0] == IA64_OPND_P2) |
9927 | && (idesc->operands[1] == IA64_OPND_P1 | |
9928 | || idesc->operands[1] == IA64_OPND_P2)) | |
800eeca4 JW |
9929 | { |
9930 | int p1 = CURR_SLOT.opnd[0].X_add_number - REG_P; | |
197865e8 | 9931 | int p2 = CURR_SLOT.opnd[1].X_add_number - REG_P; |
5e2f6673 L |
9932 | valueT p1mask = (p1 != 0) ? (valueT) 1 << p1 : 0; |
9933 | valueT p2mask = (p2 != 0) ? (valueT) 1 << p2 : 0; | |
800eeca4 | 9934 | |
5e2f6673 L |
9935 | /* If both PRs are PR0, we can't really do anything. */ |
9936 | if (p1 == 0 && p2 == 0) | |
542d6675 KH |
9937 | { |
9938 | if (md.debug_dv) | |
9939 | fprintf (stderr, " Ignoring PRs due to inclusion of p0\n"); | |
9940 | } | |
800eeca4 | 9941 | /* In general, clear mutexes and implies which include P1 or P2, |
542d6675 | 9942 | with the following exceptions. */ |
cb5301b6 RH |
9943 | else if (has_suffix_p (idesc->name, ".or.andcm") |
9944 | || has_suffix_p (idesc->name, ".and.orcm")) | |
542d6675 | 9945 | { |
542d6675 KH |
9946 | clear_qp_implies (p2mask, p1mask); |
9947 | } | |
cb5301b6 RH |
9948 | else if (has_suffix_p (idesc->name, ".andcm") |
9949 | || has_suffix_p (idesc->name, ".and")) | |
542d6675 KH |
9950 | { |
9951 | clear_qp_implies (0, p1mask | p2mask); | |
9952 | } | |
cb5301b6 RH |
9953 | else if (has_suffix_p (idesc->name, ".orcm") |
9954 | || has_suffix_p (idesc->name, ".or")) | |
542d6675 KH |
9955 | { |
9956 | clear_qp_mutex (p1mask | p2mask); | |
9957 | clear_qp_implies (p1mask | p2mask, 0); | |
9958 | } | |
800eeca4 | 9959 | else |
542d6675 | 9960 | { |
5e2f6673 L |
9961 | int added = 0; |
9962 | ||
542d6675 | 9963 | clear_qp_implies (p1mask | p2mask, p1mask | p2mask); |
5e2f6673 L |
9964 | |
9965 | /* If one of the PRs is PR0, we call clear_qp_mutex. */ | |
9966 | if (p1 == 0 || p2 == 0) | |
9967 | clear_qp_mutex (p1mask | p2mask); | |
9968 | else | |
9969 | added = update_qp_mutex (p1mask | p2mask); | |
9970 | ||
9971 | if (CURR_SLOT.qp_regno == 0 | |
9972 | || has_suffix_p (idesc->name, ".unc")) | |
542d6675 | 9973 | { |
5e2f6673 L |
9974 | if (added == 0 && p1 && p2) |
9975 | add_qp_mutex (p1mask | p2mask); | |
542d6675 KH |
9976 | if (CURR_SLOT.qp_regno != 0) |
9977 | { | |
5e2f6673 L |
9978 | if (p1) |
9979 | add_qp_imply (p1, CURR_SLOT.qp_regno); | |
9980 | if (p2) | |
9981 | add_qp_imply (p2, CURR_SLOT.qp_regno); | |
542d6675 KH |
9982 | } |
9983 | } | |
542d6675 KH |
9984 | } |
9985 | } | |
9986 | /* Look for mov imm insns into GRs. */ | |
800eeca4 | 9987 | else if (idesc->operands[0] == IA64_OPND_R1 |
542d6675 KH |
9988 | && (idesc->operands[1] == IA64_OPND_IMM22 |
9989 | || idesc->operands[1] == IA64_OPND_IMMU64) | |
a66d2bb7 | 9990 | && CURR_SLOT.opnd[1].X_op == O_constant |
542d6675 KH |
9991 | && (strcmp (idesc->name, "mov") == 0 |
9992 | || strcmp (idesc->name, "movl") == 0)) | |
800eeca4 JW |
9993 | { |
9994 | int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR; | |
542d6675 KH |
9995 | if (regno > 0 && regno < NELEMS (gr_values)) |
9996 | { | |
9997 | gr_values[regno].known = 1; | |
9998 | gr_values[regno].value = CURR_SLOT.opnd[1].X_add_number; | |
9999 | gr_values[regno].path = md.path; | |
10000 | if (md.debug_dv) | |
2434f565 JW |
10001 | { |
10002 | fprintf (stderr, " Know gr%d = ", regno); | |
10003 | fprintf_vma (stderr, gr_values[regno].value); | |
10004 | fputs ("\n", stderr); | |
10005 | } | |
542d6675 | 10006 | } |
800eeca4 | 10007 | } |
a66d2bb7 JB |
10008 | /* Look for dep.z imm insns. */ |
10009 | else if (idesc->operands[0] == IA64_OPND_R1 | |
10010 | && idesc->operands[1] == IA64_OPND_IMM8 | |
10011 | && strcmp (idesc->name, "dep.z") == 0) | |
10012 | { | |
10013 | int regno = CURR_SLOT.opnd[0].X_add_number - REG_GR; | |
10014 | if (regno > 0 && regno < NELEMS (gr_values)) | |
10015 | { | |
10016 | valueT value = CURR_SLOT.opnd[1].X_add_number; | |
10017 | ||
10018 | if (CURR_SLOT.opnd[3].X_add_number < 64) | |
10019 | value &= ((valueT)1 << CURR_SLOT.opnd[3].X_add_number) - 1; | |
10020 | value <<= CURR_SLOT.opnd[2].X_add_number; | |
10021 | gr_values[regno].known = 1; | |
10022 | gr_values[regno].value = value; | |
10023 | gr_values[regno].path = md.path; | |
10024 | if (md.debug_dv) | |
10025 | { | |
10026 | fprintf (stderr, " Know gr%d = ", regno); | |
10027 | fprintf_vma (stderr, gr_values[regno].value); | |
10028 | fputs ("\n", stderr); | |
10029 | } | |
10030 | } | |
10031 | } | |
197865e8 | 10032 | else |
800eeca4 JW |
10033 | { |
10034 | clear_qp_mutex (qp_changemask); | |
10035 | clear_qp_implies (qp_changemask, qp_changemask); | |
10036 | } | |
10037 | } | |
10038 | ||
542d6675 KH |
10039 | /* Return whether the given predicate registers are currently mutex. */ |
10040 | ||
800eeca4 | 10041 | static int |
5a49b8ac | 10042 | qp_mutex (int p1, int p2, int path) |
800eeca4 JW |
10043 | { |
10044 | int i; | |
10045 | valueT mask; | |
10046 | ||
10047 | if (p1 != p2) | |
10048 | { | |
542d6675 KH |
10049 | mask = ((valueT) 1 << p1) | (valueT) 1 << p2; |
10050 | for (i = 0; i < qp_mutexeslen; i++) | |
10051 | { | |
10052 | if (qp_mutexes[i].path >= path | |
10053 | && (qp_mutexes[i].prmask & mask) == mask) | |
10054 | return 1; | |
10055 | } | |
800eeca4 JW |
10056 | } |
10057 | return 0; | |
10058 | } | |
10059 | ||
10060 | /* Return whether the given resource is in the given insn's list of chks | |
10061 | Return 1 if the conflict is absolutely determined, 2 if it's a potential | |
542d6675 KH |
10062 | conflict. */ |
10063 | ||
800eeca4 | 10064 | static int |
5a49b8ac AM |
10065 | resources_match (struct rsrc *rs, |
10066 | struct ia64_opcode *idesc, | |
10067 | int note, | |
10068 | int qp_regno, | |
10069 | int path) | |
800eeca4 JW |
10070 | { |
10071 | struct rsrc specs[MAX_SPECS]; | |
10072 | int count; | |
10073 | ||
10074 | /* If the marked resource's qp_regno and the given qp_regno are mutex, | |
10075 | we don't need to check. One exception is note 11, which indicates that | |
10076 | target predicates are written regardless of PR[qp]. */ | |
197865e8 | 10077 | if (qp_mutex (rs->qp_regno, qp_regno, path) |
800eeca4 JW |
10078 | && note != 11) |
10079 | return 0; | |
10080 | ||
10081 | count = specify_resource (rs->dependency, idesc, DV_CHK, specs, note, path); | |
10082 | while (count-- > 0) | |
10083 | { | |
10084 | /* UNAT checking is a bit more specific than other resources */ | |
10085 | if (rs->dependency->specifier == IA64_RS_AR_UNAT | |
542d6675 KH |
10086 | && specs[count].mem_offset.hint |
10087 | && rs->mem_offset.hint) | |
10088 | { | |
10089 | if (rs->mem_offset.base == specs[count].mem_offset.base) | |
10090 | { | |
10091 | if (((rs->mem_offset.offset >> 3) & 0x3F) == | |
10092 | ((specs[count].mem_offset.offset >> 3) & 0x3F)) | |
10093 | return 1; | |
10094 | else | |
10095 | continue; | |
10096 | } | |
10097 | } | |
800eeca4 | 10098 | |
7484b8e6 | 10099 | /* Skip apparent PR write conflicts where both writes are an AND or both |
4a4f25cf | 10100 | writes are an OR. */ |
7484b8e6 | 10101 | if (rs->dependency->specifier == IA64_RS_PR |
afa680f8 | 10102 | || rs->dependency->specifier == IA64_RS_PRr |
7484b8e6 TW |
10103 | || rs->dependency->specifier == IA64_RS_PR63) |
10104 | { | |
10105 | if (specs[count].cmp_type != CMP_NONE | |
10106 | && specs[count].cmp_type == rs->cmp_type) | |
10107 | { | |
10108 | if (md.debug_dv) | |
10109 | fprintf (stderr, " %s on parallel compare allowed (PR%d)\n", | |
10110 | dv_mode[rs->dependency->mode], | |
afa680f8 | 10111 | rs->dependency->specifier != IA64_RS_PR63 ? |
7484b8e6 TW |
10112 | specs[count].index : 63); |
10113 | continue; | |
10114 | } | |
10115 | if (md.debug_dv) | |
4a4f25cf | 10116 | fprintf (stderr, |
7484b8e6 TW |
10117 | " %s on parallel compare conflict %s vs %s on PR%d\n", |
10118 | dv_mode[rs->dependency->mode], | |
4a4f25cf | 10119 | dv_cmp_type[rs->cmp_type], |
7484b8e6 | 10120 | dv_cmp_type[specs[count].cmp_type], |
afa680f8 | 10121 | rs->dependency->specifier != IA64_RS_PR63 ? |
7484b8e6 | 10122 | specs[count].index : 63); |
4a4f25cf | 10123 | |
7484b8e6 TW |
10124 | } |
10125 | ||
800eeca4 | 10126 | /* If either resource is not specific, conservatively assume a conflict |
197865e8 | 10127 | */ |
800eeca4 | 10128 | if (!specs[count].specific || !rs->specific) |
542d6675 | 10129 | return 2; |
800eeca4 | 10130 | else if (specs[count].index == rs->index) |
542d6675 | 10131 | return 1; |
800eeca4 | 10132 | } |
800eeca4 JW |
10133 | |
10134 | return 0; | |
10135 | } | |
10136 | ||
10137 | /* Indicate an instruction group break; if INSERT_STOP is non-zero, then | |
10138 | insert a stop to create the break. Update all resource dependencies | |
10139 | appropriately. If QP_REGNO is non-zero, only apply the break to resources | |
10140 | which use the same QP_REGNO and have the link_to_qp_branch flag set. | |
10141 | If SAVE_CURRENT is non-zero, don't affect resources marked by the current | |
542d6675 | 10142 | instruction. */ |
800eeca4 JW |
10143 | |
10144 | static void | |
5a49b8ac | 10145 | insn_group_break (int insert_stop, int qp_regno, int save_current) |
800eeca4 JW |
10146 | { |
10147 | int i; | |
10148 | ||
10149 | if (insert_stop && md.num_slots_in_use > 0) | |
10150 | PREV_SLOT.end_of_insn_group = 1; | |
10151 | ||
10152 | if (md.debug_dv) | |
10153 | { | |
197865e8 | 10154 | fprintf (stderr, " Insn group break%s", |
542d6675 | 10155 | (insert_stop ? " (w/stop)" : "")); |
800eeca4 | 10156 | if (qp_regno != 0) |
542d6675 | 10157 | fprintf (stderr, " effective for QP=%d", qp_regno); |
800eeca4 JW |
10158 | fprintf (stderr, "\n"); |
10159 | } | |
10160 | ||
10161 | i = 0; | |
10162 | while (i < regdepslen) | |
10163 | { | |
10164 | const struct ia64_dependency *dep = regdeps[i].dependency; | |
10165 | ||
10166 | if (qp_regno != 0 | |
542d6675 KH |
10167 | && regdeps[i].qp_regno != qp_regno) |
10168 | { | |
10169 | ++i; | |
10170 | continue; | |
10171 | } | |
800eeca4 JW |
10172 | |
10173 | if (save_current | |
542d6675 KH |
10174 | && CURR_SLOT.src_file == regdeps[i].file |
10175 | && CURR_SLOT.src_line == regdeps[i].line) | |
10176 | { | |
10177 | ++i; | |
10178 | continue; | |
10179 | } | |
800eeca4 JW |
10180 | |
10181 | /* clear dependencies which are automatically cleared by a stop, or | |
542d6675 | 10182 | those that have reached the appropriate state of insn serialization */ |
800eeca4 | 10183 | if (dep->semantics == IA64_DVS_IMPLIED |
542d6675 KH |
10184 | || dep->semantics == IA64_DVS_IMPLIEDF |
10185 | || regdeps[i].insn_srlz == STATE_SRLZ) | |
10186 | { | |
10187 | print_dependency ("Removing", i); | |
10188 | regdeps[i] = regdeps[--regdepslen]; | |
10189 | } | |
800eeca4 | 10190 | else |
542d6675 KH |
10191 | { |
10192 | if (dep->semantics == IA64_DVS_DATA | |
10193 | || dep->semantics == IA64_DVS_INSTR | |
800eeca4 | 10194 | || dep->semantics == IA64_DVS_SPECIFIC) |
542d6675 KH |
10195 | { |
10196 | if (regdeps[i].insn_srlz == STATE_NONE) | |
10197 | regdeps[i].insn_srlz = STATE_STOP; | |
10198 | if (regdeps[i].data_srlz == STATE_NONE) | |
10199 | regdeps[i].data_srlz = STATE_STOP; | |
10200 | } | |
10201 | ++i; | |
10202 | } | |
800eeca4 JW |
10203 | } |
10204 | } | |
10205 | ||
542d6675 KH |
10206 | /* Add the given resource usage spec to the list of active dependencies. */ |
10207 | ||
197865e8 | 10208 | static void |
5a49b8ac AM |
10209 | mark_resource (struct ia64_opcode *idesc ATTRIBUTE_UNUSED, |
10210 | const struct ia64_dependency *dep ATTRIBUTE_UNUSED, | |
10211 | struct rsrc *spec, | |
10212 | int depind, | |
10213 | int path) | |
800eeca4 JW |
10214 | { |
10215 | if (regdepslen == regdepstotlen) | |
10216 | { | |
10217 | regdepstotlen += 20; | |
10218 | regdeps = (struct rsrc *) | |
542d6675 | 10219 | xrealloc ((void *) regdeps, |
bc805888 | 10220 | regdepstotlen * sizeof (struct rsrc)); |
800eeca4 JW |
10221 | } |
10222 | ||
10223 | regdeps[regdepslen] = *spec; | |
10224 | regdeps[regdepslen].depind = depind; | |
10225 | regdeps[regdepslen].path = path; | |
10226 | regdeps[regdepslen].file = CURR_SLOT.src_file; | |
10227 | regdeps[regdepslen].line = CURR_SLOT.src_line; | |
10228 | ||
10229 | print_dependency ("Adding", regdepslen); | |
10230 | ||
10231 | ++regdepslen; | |
10232 | } | |
10233 | ||
10234 | static void | |
5a49b8ac | 10235 | print_dependency (const char *action, int depind) |
800eeca4 JW |
10236 | { |
10237 | if (md.debug_dv) | |
10238 | { | |
197865e8 | 10239 | fprintf (stderr, " %s %s '%s'", |
542d6675 KH |
10240 | action, dv_mode[(regdeps[depind].dependency)->mode], |
10241 | (regdeps[depind].dependency)->name); | |
a66d2bb7 | 10242 | if (regdeps[depind].specific && regdeps[depind].index >= 0) |
542d6675 | 10243 | fprintf (stderr, " (%d)", regdeps[depind].index); |
800eeca4 | 10244 | if (regdeps[depind].mem_offset.hint) |
2434f565 JW |
10245 | { |
10246 | fputs (" ", stderr); | |
10247 | fprintf_vma (stderr, regdeps[depind].mem_offset.base); | |
10248 | fputs ("+", stderr); | |
10249 | fprintf_vma (stderr, regdeps[depind].mem_offset.offset); | |
10250 | } | |
800eeca4 JW |
10251 | fprintf (stderr, "\n"); |
10252 | } | |
10253 | } | |
10254 | ||
10255 | static void | |
5a49b8ac | 10256 | instruction_serialization (void) |
800eeca4 JW |
10257 | { |
10258 | int i; | |
10259 | if (md.debug_dv) | |
10260 | fprintf (stderr, " Instruction serialization\n"); | |
542d6675 | 10261 | for (i = 0; i < regdepslen; i++) |
800eeca4 JW |
10262 | if (regdeps[i].insn_srlz == STATE_STOP) |
10263 | regdeps[i].insn_srlz = STATE_SRLZ; | |
10264 | } | |
10265 | ||
10266 | static void | |
5a49b8ac | 10267 | data_serialization (void) |
800eeca4 JW |
10268 | { |
10269 | int i = 0; | |
10270 | if (md.debug_dv) | |
10271 | fprintf (stderr, " Data serialization\n"); | |
10272 | while (i < regdepslen) | |
10273 | { | |
10274 | if (regdeps[i].data_srlz == STATE_STOP | |
542d6675 KH |
10275 | /* Note: as of 991210, all "other" dependencies are cleared by a |
10276 | data serialization. This might change with new tables */ | |
10277 | || (regdeps[i].dependency)->semantics == IA64_DVS_OTHER) | |
10278 | { | |
10279 | print_dependency ("Removing", i); | |
10280 | regdeps[i] = regdeps[--regdepslen]; | |
10281 | } | |
800eeca4 | 10282 | else |
542d6675 | 10283 | ++i; |
800eeca4 JW |
10284 | } |
10285 | } | |
10286 | ||
542d6675 KH |
10287 | /* Insert stops and serializations as needed to avoid DVs. */ |
10288 | ||
800eeca4 | 10289 | static void |
5a49b8ac | 10290 | remove_marked_resource (struct rsrc *rs) |
800eeca4 JW |
10291 | { |
10292 | switch (rs->dependency->semantics) | |
10293 | { | |
10294 | case IA64_DVS_SPECIFIC: | |
10295 | if (md.debug_dv) | |
10296 | fprintf (stderr, "Implementation-specific, assume worst case...\n"); | |
197865e8 | 10297 | /* ...fall through... */ |
800eeca4 JW |
10298 | case IA64_DVS_INSTR: |
10299 | if (md.debug_dv) | |
542d6675 | 10300 | fprintf (stderr, "Inserting instr serialization\n"); |
800eeca4 | 10301 | if (rs->insn_srlz < STATE_STOP) |
542d6675 | 10302 | insn_group_break (1, 0, 0); |
800eeca4 | 10303 | if (rs->insn_srlz < STATE_SRLZ) |
542d6675 | 10304 | { |
888a75be | 10305 | struct slot oldslot = CURR_SLOT; |
542d6675 | 10306 | /* Manually jam a srlz.i insn into the stream */ |
888a75be | 10307 | memset (&CURR_SLOT, 0, sizeof (CURR_SLOT)); |
744b6414 | 10308 | CURR_SLOT.user_template = -1; |
542d6675 KH |
10309 | CURR_SLOT.idesc = ia64_find_opcode ("srlz.i"); |
10310 | instruction_serialization (); | |
10311 | md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS; | |
10312 | if (++md.num_slots_in_use >= NUM_SLOTS) | |
10313 | emit_one_bundle (); | |
888a75be | 10314 | CURR_SLOT = oldslot; |
542d6675 | 10315 | } |
800eeca4 JW |
10316 | insn_group_break (1, 0, 0); |
10317 | break; | |
10318 | case IA64_DVS_OTHER: /* as of rev2 (991220) of the DV tables, all | |
542d6675 KH |
10319 | "other" types of DV are eliminated |
10320 | by a data serialization */ | |
800eeca4 JW |
10321 | case IA64_DVS_DATA: |
10322 | if (md.debug_dv) | |
542d6675 | 10323 | fprintf (stderr, "Inserting data serialization\n"); |
800eeca4 | 10324 | if (rs->data_srlz < STATE_STOP) |
542d6675 | 10325 | insn_group_break (1, 0, 0); |
800eeca4 | 10326 | { |
888a75be | 10327 | struct slot oldslot = CURR_SLOT; |
542d6675 | 10328 | /* Manually jam a srlz.d insn into the stream */ |
888a75be | 10329 | memset (&CURR_SLOT, 0, sizeof (CURR_SLOT)); |
744b6414 | 10330 | CURR_SLOT.user_template = -1; |
542d6675 KH |
10331 | CURR_SLOT.idesc = ia64_find_opcode ("srlz.d"); |
10332 | data_serialization (); | |
10333 | md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS; | |
10334 | if (++md.num_slots_in_use >= NUM_SLOTS) | |
10335 | emit_one_bundle (); | |
888a75be | 10336 | CURR_SLOT = oldslot; |
800eeca4 JW |
10337 | } |
10338 | break; | |
10339 | case IA64_DVS_IMPLIED: | |
10340 | case IA64_DVS_IMPLIEDF: | |
10341 | if (md.debug_dv) | |
542d6675 | 10342 | fprintf (stderr, "Inserting stop\n"); |
800eeca4 JW |
10343 | insn_group_break (1, 0, 0); |
10344 | break; | |
10345 | default: | |
10346 | break; | |
10347 | } | |
10348 | } | |
10349 | ||
10350 | /* Check the resources used by the given opcode against the current dependency | |
197865e8 | 10351 | list. |
800eeca4 JW |
10352 | |
10353 | The check is run once for each execution path encountered. In this case, | |
10354 | a unique execution path is the sequence of instructions following a code | |
10355 | entry point, e.g. the following has three execution paths, one starting | |
10356 | at L0, one at L1, and one at L2. | |
197865e8 | 10357 | |
800eeca4 JW |
10358 | L0: nop |
10359 | L1: add | |
10360 | L2: add | |
197865e8 | 10361 | br.ret |
800eeca4 | 10362 | */ |
542d6675 | 10363 | |
800eeca4 | 10364 | static void |
5a49b8ac | 10365 | check_dependencies (struct ia64_opcode *idesc) |
800eeca4 JW |
10366 | { |
10367 | const struct ia64_opcode_dependency *opdeps = idesc->dependencies; | |
10368 | int path; | |
10369 | int i; | |
10370 | ||
10371 | /* Note that the number of marked resources may change within the | |
197865e8 | 10372 | loop if in auto mode. */ |
800eeca4 JW |
10373 | i = 0; |
10374 | while (i < regdepslen) | |
10375 | { | |
10376 | struct rsrc *rs = ®deps[i]; | |
10377 | const struct ia64_dependency *dep = rs->dependency; | |
10378 | int chkind; | |
10379 | int note; | |
10380 | int start_over = 0; | |
10381 | ||
10382 | if (dep->semantics == IA64_DVS_NONE | |
542d6675 KH |
10383 | || (chkind = depends_on (rs->depind, idesc)) == -1) |
10384 | { | |
10385 | ++i; | |
10386 | continue; | |
10387 | } | |
10388 | ||
10389 | note = NOTE (opdeps->chks[chkind]); | |
10390 | ||
10391 | /* Check this resource against each execution path seen thus far. */ | |
10392 | for (path = 0; path <= md.path; path++) | |
10393 | { | |
10394 | int matchtype; | |
10395 | ||
10396 | /* If the dependency wasn't on the path being checked, ignore it. */ | |
10397 | if (rs->path < path) | |
10398 | continue; | |
10399 | ||
10400 | /* If the QP for this insn implies a QP which has branched, don't | |
10401 | bother checking. Ed. NOTE: I don't think this check is terribly | |
10402 | useful; what's the point of generating code which will only be | |
10403 | reached if its QP is zero? | |
10404 | This code was specifically inserted to handle the following code, | |
10405 | based on notes from Intel's DV checking code, where p1 implies p2. | |
10406 | ||
10407 | mov r4 = 2 | |
10408 | (p2) br.cond L | |
10409 | (p1) mov r4 = 7 | |
10410 | */ | |
10411 | if (CURR_SLOT.qp_regno != 0) | |
10412 | { | |
10413 | int skip = 0; | |
10414 | int implies; | |
10415 | for (implies = 0; implies < qp_implieslen; implies++) | |
10416 | { | |
10417 | if (qp_implies[implies].path >= path | |
10418 | && qp_implies[implies].p1 == CURR_SLOT.qp_regno | |
10419 | && qp_implies[implies].p2_branched) | |
10420 | { | |
10421 | skip = 1; | |
10422 | break; | |
10423 | } | |
10424 | } | |
10425 | if (skip) | |
10426 | continue; | |
10427 | } | |
10428 | ||
10429 | if ((matchtype = resources_match (rs, idesc, note, | |
10430 | CURR_SLOT.qp_regno, path)) != 0) | |
10431 | { | |
10432 | char msg[1024]; | |
10433 | char pathmsg[256] = ""; | |
10434 | char indexmsg[256] = ""; | |
10435 | int certain = (matchtype == 1 && CURR_SLOT.qp_regno == 0); | |
10436 | ||
10437 | if (path != 0) | |
f9f21a03 L |
10438 | snprintf (pathmsg, sizeof (pathmsg), |
10439 | " when entry is at label '%s'", | |
542d6675 | 10440 | md.entry_labels[path - 1]); |
a66d2bb7 | 10441 | if (matchtype == 1 && rs->index >= 0) |
f9f21a03 L |
10442 | snprintf (indexmsg, sizeof (indexmsg), |
10443 | ", specific resource number is %d", | |
542d6675 | 10444 | rs->index); |
f9f21a03 L |
10445 | snprintf (msg, sizeof (msg), |
10446 | "Use of '%s' %s %s dependency '%s' (%s)%s%s", | |
542d6675 KH |
10447 | idesc->name, |
10448 | (certain ? "violates" : "may violate"), | |
10449 | dv_mode[dep->mode], dep->name, | |
10450 | dv_sem[dep->semantics], | |
10451 | pathmsg, indexmsg); | |
10452 | ||
10453 | if (md.explicit_mode) | |
10454 | { | |
10455 | as_warn ("%s", msg); | |
10456 | if (path < md.path) | |
ad4b42b4 | 10457 | as_warn (_("Only the first path encountering the conflict is reported")); |
542d6675 | 10458 | as_warn_where (rs->file, rs->line, |
ad4b42b4 | 10459 | _("This is the location of the conflicting usage")); |
542d6675 KH |
10460 | /* Don't bother checking other paths, to avoid duplicating |
10461 | the same warning */ | |
10462 | break; | |
10463 | } | |
10464 | else | |
10465 | { | |
10466 | if (md.debug_dv) | |
10467 | fprintf (stderr, "%s @ %s:%d\n", msg, rs->file, rs->line); | |
10468 | ||
10469 | remove_marked_resource (rs); | |
10470 | ||
10471 | /* since the set of dependencies has changed, start over */ | |
10472 | /* FIXME -- since we're removing dvs as we go, we | |
10473 | probably don't really need to start over... */ | |
10474 | start_over = 1; | |
10475 | break; | |
10476 | } | |
10477 | } | |
10478 | } | |
800eeca4 | 10479 | if (start_over) |
542d6675 | 10480 | i = 0; |
800eeca4 | 10481 | else |
542d6675 | 10482 | ++i; |
800eeca4 JW |
10483 | } |
10484 | } | |
10485 | ||
542d6675 KH |
10486 | /* Register new dependencies based on the given opcode. */ |
10487 | ||
800eeca4 | 10488 | static void |
5a49b8ac | 10489 | mark_resources (struct ia64_opcode *idesc) |
800eeca4 JW |
10490 | { |
10491 | int i; | |
10492 | const struct ia64_opcode_dependency *opdeps = idesc->dependencies; | |
10493 | int add_only_qp_reads = 0; | |
10494 | ||
10495 | /* A conditional branch only uses its resources if it is taken; if it is | |
10496 | taken, we stop following that path. The other branch types effectively | |
10497 | *always* write their resources. If it's not taken, register only QP | |
197865e8 | 10498 | reads. */ |
800eeca4 JW |
10499 | if (is_conditional_branch (idesc) || is_interruption_or_rfi (idesc)) |
10500 | { | |
10501 | add_only_qp_reads = 1; | |
10502 | } | |
10503 | ||
10504 | if (md.debug_dv) | |
10505 | fprintf (stderr, "Registering '%s' resource usage\n", idesc->name); | |
10506 | ||
542d6675 | 10507 | for (i = 0; i < opdeps->nregs; i++) |
800eeca4 JW |
10508 | { |
10509 | const struct ia64_dependency *dep; | |
10510 | struct rsrc specs[MAX_SPECS]; | |
10511 | int note; | |
10512 | int path; | |
10513 | int count; | |
197865e8 | 10514 | |
800eeca4 | 10515 | dep = ia64_find_dependency (opdeps->regs[i]); |
542d6675 | 10516 | note = NOTE (opdeps->regs[i]); |
800eeca4 JW |
10517 | |
10518 | if (add_only_qp_reads | |
542d6675 KH |
10519 | && !(dep->mode == IA64_DV_WAR |
10520 | && (dep->specifier == IA64_RS_PR | |
139368c9 | 10521 | || dep->specifier == IA64_RS_PRr |
542d6675 KH |
10522 | || dep->specifier == IA64_RS_PR63))) |
10523 | continue; | |
800eeca4 JW |
10524 | |
10525 | count = specify_resource (dep, idesc, DV_REG, specs, note, md.path); | |
10526 | ||
800eeca4 | 10527 | while (count-- > 0) |
542d6675 KH |
10528 | { |
10529 | mark_resource (idesc, dep, &specs[count], | |
10530 | DEP (opdeps->regs[i]), md.path); | |
10531 | } | |
800eeca4 JW |
10532 | |
10533 | /* The execution path may affect register values, which may in turn | |
542d6675 | 10534 | affect which indirect-access resources are accessed. */ |
800eeca4 | 10535 | switch (dep->specifier) |
542d6675 KH |
10536 | { |
10537 | default: | |
10538 | break; | |
10539 | case IA64_RS_CPUID: | |
10540 | case IA64_RS_DBR: | |
10541 | case IA64_RS_IBR: | |
800eeca4 | 10542 | case IA64_RS_MSR: |
542d6675 KH |
10543 | case IA64_RS_PKR: |
10544 | case IA64_RS_PMC: | |
10545 | case IA64_RS_PMD: | |
10546 | case IA64_RS_RR: | |
10547 | for (path = 0; path < md.path; path++) | |
10548 | { | |
10549 | count = specify_resource (dep, idesc, DV_REG, specs, note, path); | |
10550 | while (count-- > 0) | |
10551 | mark_resource (idesc, dep, &specs[count], | |
10552 | DEP (opdeps->regs[i]), path); | |
10553 | } | |
10554 | break; | |
10555 | } | |
10556 | } | |
10557 | } | |
10558 | ||
10559 | /* Remove dependencies when they no longer apply. */ | |
10560 | ||
800eeca4 | 10561 | static void |
5a49b8ac | 10562 | update_dependencies (struct ia64_opcode *idesc) |
800eeca4 JW |
10563 | { |
10564 | int i; | |
10565 | ||
10566 | if (strcmp (idesc->name, "srlz.i") == 0) | |
10567 | { | |
10568 | instruction_serialization (); | |
10569 | } | |
10570 | else if (strcmp (idesc->name, "srlz.d") == 0) | |
10571 | { | |
10572 | data_serialization (); | |
10573 | } | |
10574 | else if (is_interruption_or_rfi (idesc) | |
542d6675 | 10575 | || is_taken_branch (idesc)) |
800eeca4 | 10576 | { |
542d6675 KH |
10577 | /* Although technically the taken branch doesn't clear dependencies |
10578 | which require a srlz.[id], we don't follow the branch; the next | |
10579 | instruction is assumed to start with a clean slate. */ | |
800eeca4 | 10580 | regdepslen = 0; |
800eeca4 JW |
10581 | md.path = 0; |
10582 | } | |
10583 | else if (is_conditional_branch (idesc) | |
542d6675 | 10584 | && CURR_SLOT.qp_regno != 0) |
800eeca4 JW |
10585 | { |
10586 | int is_call = strstr (idesc->name, ".call") != NULL; | |
10587 | ||
542d6675 KH |
10588 | for (i = 0; i < qp_implieslen; i++) |
10589 | { | |
10590 | /* If the conditional branch's predicate is implied by the predicate | |
10591 | in an existing dependency, remove that dependency. */ | |
10592 | if (qp_implies[i].p2 == CURR_SLOT.qp_regno) | |
10593 | { | |
10594 | int depind = 0; | |
10595 | /* Note that this implied predicate takes a branch so that if | |
10596 | a later insn generates a DV but its predicate implies this | |
10597 | one, we can avoid the false DV warning. */ | |
10598 | qp_implies[i].p2_branched = 1; | |
10599 | while (depind < regdepslen) | |
10600 | { | |
10601 | if (regdeps[depind].qp_regno == qp_implies[i].p1) | |
10602 | { | |
10603 | print_dependency ("Removing", depind); | |
10604 | regdeps[depind] = regdeps[--regdepslen]; | |
10605 | } | |
10606 | else | |
10607 | ++depind; | |
10608 | } | |
10609 | } | |
10610 | } | |
800eeca4 | 10611 | /* Any marked resources which have this same predicate should be |
542d6675 KH |
10612 | cleared, provided that the QP hasn't been modified between the |
10613 | marking instruction and the branch. */ | |
800eeca4 | 10614 | if (is_call) |
542d6675 KH |
10615 | { |
10616 | insn_group_break (0, CURR_SLOT.qp_regno, 1); | |
10617 | } | |
800eeca4 | 10618 | else |
542d6675 KH |
10619 | { |
10620 | i = 0; | |
10621 | while (i < regdepslen) | |
10622 | { | |
10623 | if (regdeps[i].qp_regno == CURR_SLOT.qp_regno | |
10624 | && regdeps[i].link_to_qp_branch | |
10625 | && (regdeps[i].file != CURR_SLOT.src_file | |
10626 | || regdeps[i].line != CURR_SLOT.src_line)) | |
10627 | { | |
10628 | /* Treat like a taken branch */ | |
10629 | print_dependency ("Removing", i); | |
10630 | regdeps[i] = regdeps[--regdepslen]; | |
10631 | } | |
10632 | else | |
10633 | ++i; | |
10634 | } | |
10635 | } | |
800eeca4 JW |
10636 | } |
10637 | } | |
10638 | ||
10639 | /* Examine the current instruction for dependency violations. */ | |
542d6675 | 10640 | |
800eeca4 | 10641 | static int |
5a49b8ac | 10642 | check_dv (struct ia64_opcode *idesc) |
800eeca4 JW |
10643 | { |
10644 | if (md.debug_dv) | |
10645 | { | |
197865e8 | 10646 | fprintf (stderr, "Checking %s for violations (line %d, %d/%d)\n", |
542d6675 KH |
10647 | idesc->name, CURR_SLOT.src_line, |
10648 | idesc->dependencies->nchks, | |
10649 | idesc->dependencies->nregs); | |
800eeca4 JW |
10650 | } |
10651 | ||
197865e8 | 10652 | /* Look through the list of currently marked resources; if the current |
800eeca4 | 10653 | instruction has the dependency in its chks list which uses that resource, |
542d6675 | 10654 | check against the specific resources used. */ |
800eeca4 JW |
10655 | check_dependencies (idesc); |
10656 | ||
542d6675 KH |
10657 | /* Look up the instruction's regdeps (RAW writes, WAW writes, and WAR reads), |
10658 | then add them to the list of marked resources. */ | |
800eeca4 JW |
10659 | mark_resources (idesc); |
10660 | ||
10661 | /* There are several types of dependency semantics, and each has its own | |
197865e8 KH |
10662 | requirements for being cleared |
10663 | ||
800eeca4 JW |
10664 | Instruction serialization (insns separated by interruption, rfi, or |
10665 | writer + srlz.i + reader, all in separate groups) clears DVS_INSTR. | |
10666 | ||
10667 | Data serialization (instruction serialization, or writer + srlz.d + | |
10668 | reader, where writer and srlz.d are in separate groups) clears | |
10669 | DVS_DATA. (This also clears DVS_OTHER, but that is not guaranteed to | |
10670 | always be the case). | |
10671 | ||
10672 | Instruction group break (groups separated by stop, taken branch, | |
10673 | interruption or rfi) clears DVS_IMPLIED and DVS_IMPLIEDF. | |
10674 | */ | |
10675 | update_dependencies (idesc); | |
10676 | ||
10677 | /* Sometimes, knowing a register value allows us to avoid giving a false DV | |
197865e8 | 10678 | warning. Keep track of as many as possible that are useful. */ |
800eeca4 JW |
10679 | note_register_values (idesc); |
10680 | ||
197865e8 | 10681 | /* We don't need or want this anymore. */ |
800eeca4 JW |
10682 | md.mem_offset.hint = 0; |
10683 | ||
10684 | return 0; | |
10685 | } | |
10686 | ||
10687 | /* Translate one line of assembly. Pseudo ops and labels do not show | |
10688 | here. */ | |
10689 | void | |
5a49b8ac | 10690 | md_assemble (char *str) |
800eeca4 JW |
10691 | { |
10692 | char *saved_input_line_pointer, *mnemonic; | |
10693 | const struct pseudo_opcode *pdesc; | |
10694 | struct ia64_opcode *idesc; | |
10695 | unsigned char qp_regno; | |
10696 | unsigned int flags; | |
10697 | int ch; | |
10698 | ||
10699 | saved_input_line_pointer = input_line_pointer; | |
10700 | input_line_pointer = str; | |
10701 | ||
542d6675 | 10702 | /* extract the opcode (mnemonic): */ |
800eeca4 | 10703 | |
d02603dc | 10704 | ch = get_symbol_name (&mnemonic); |
800eeca4 JW |
10705 | pdesc = (struct pseudo_opcode *) hash_find (md.pseudo_hash, mnemonic); |
10706 | if (pdesc) | |
10707 | { | |
d02603dc | 10708 | (void) restore_line_pointer (ch); |
800eeca4 JW |
10709 | (*pdesc->handler) (pdesc->arg); |
10710 | goto done; | |
10711 | } | |
10712 | ||
542d6675 | 10713 | /* Find the instruction descriptor matching the arguments. */ |
800eeca4 JW |
10714 | |
10715 | idesc = ia64_find_opcode (mnemonic); | |
d02603dc | 10716 | (void) restore_line_pointer (ch); |
800eeca4 JW |
10717 | if (!idesc) |
10718 | { | |
ad4b42b4 | 10719 | as_bad (_("Unknown opcode `%s'"), mnemonic); |
800eeca4 JW |
10720 | goto done; |
10721 | } | |
10722 | ||
10723 | idesc = parse_operands (idesc); | |
10724 | if (!idesc) | |
10725 | goto done; | |
10726 | ||
542d6675 | 10727 | /* Handle the dynamic ops we can handle now: */ |
800eeca4 JW |
10728 | if (idesc->type == IA64_TYPE_DYN) |
10729 | { | |
10730 | if (strcmp (idesc->name, "add") == 0) | |
10731 | { | |
10732 | if (CURR_SLOT.opnd[2].X_op == O_register | |
10733 | && CURR_SLOT.opnd[2].X_add_number < 4) | |
10734 | mnemonic = "addl"; | |
10735 | else | |
10736 | mnemonic = "adds"; | |
3d56ab85 | 10737 | ia64_free_opcode (idesc); |
800eeca4 | 10738 | idesc = ia64_find_opcode (mnemonic); |
800eeca4 JW |
10739 | } |
10740 | else if (strcmp (idesc->name, "mov") == 0) | |
10741 | { | |
10742 | enum ia64_opnd opnd1, opnd2; | |
10743 | int rop; | |
10744 | ||
10745 | opnd1 = idesc->operands[0]; | |
10746 | opnd2 = idesc->operands[1]; | |
10747 | if (opnd1 == IA64_OPND_AR3) | |
10748 | rop = 0; | |
10749 | else if (opnd2 == IA64_OPND_AR3) | |
10750 | rop = 1; | |
10751 | else | |
10752 | abort (); | |
652ca075 L |
10753 | if (CURR_SLOT.opnd[rop].X_op == O_register) |
10754 | { | |
10755 | if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number)) | |
10756 | mnemonic = "mov.i"; | |
97762d08 | 10757 | else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number)) |
652ca075 | 10758 | mnemonic = "mov.m"; |
97762d08 JB |
10759 | else |
10760 | rop = -1; | |
652ca075 | 10761 | } |
800eeca4 | 10762 | else |
652ca075 | 10763 | abort (); |
97762d08 JB |
10764 | if (rop >= 0) |
10765 | { | |
10766 | ia64_free_opcode (idesc); | |
10767 | idesc = ia64_find_opcode (mnemonic); | |
10768 | while (idesc != NULL | |
10769 | && (idesc->operands[0] != opnd1 | |
10770 | || idesc->operands[1] != opnd2)) | |
10771 | idesc = get_next_opcode (idesc); | |
10772 | } | |
800eeca4 JW |
10773 | } |
10774 | } | |
652ca075 L |
10775 | else if (strcmp (idesc->name, "mov.i") == 0 |
10776 | || strcmp (idesc->name, "mov.m") == 0) | |
10777 | { | |
10778 | enum ia64_opnd opnd1, opnd2; | |
10779 | int rop; | |
3739860c | 10780 | |
652ca075 L |
10781 | opnd1 = idesc->operands[0]; |
10782 | opnd2 = idesc->operands[1]; | |
10783 | if (opnd1 == IA64_OPND_AR3) | |
10784 | rop = 0; | |
10785 | else if (opnd2 == IA64_OPND_AR3) | |
10786 | rop = 1; | |
10787 | else | |
10788 | abort (); | |
10789 | if (CURR_SLOT.opnd[rop].X_op == O_register) | |
10790 | { | |
10791 | char unit = 'a'; | |
10792 | if (ar_is_only_in_integer_unit (CURR_SLOT.opnd[rop].X_add_number)) | |
10793 | unit = 'i'; | |
10794 | else if (ar_is_only_in_memory_unit (CURR_SLOT.opnd[rop].X_add_number)) | |
10795 | unit = 'm'; | |
10796 | if (unit != 'a' && unit != idesc->name [4]) | |
ad4b42b4 | 10797 | as_bad (_("AR %d can only be accessed by %c-unit"), |
652ca075 L |
10798 | (int) (CURR_SLOT.opnd[rop].X_add_number - REG_AR), |
10799 | TOUPPER (unit)); | |
10800 | } | |
10801 | } | |
91d777ee L |
10802 | else if (strcmp (idesc->name, "hint.b") == 0) |
10803 | { | |
10804 | switch (md.hint_b) | |
10805 | { | |
10806 | case hint_b_ok: | |
10807 | break; | |
10808 | case hint_b_warning: | |
ad4b42b4 | 10809 | as_warn (_("hint.b may be treated as nop")); |
91d777ee L |
10810 | break; |
10811 | case hint_b_error: | |
ad4b42b4 | 10812 | as_bad (_("hint.b shouldn't be used")); |
91d777ee L |
10813 | break; |
10814 | } | |
10815 | } | |
800eeca4 JW |
10816 | |
10817 | qp_regno = 0; | |
10818 | if (md.qp.X_op == O_register) | |
f1bcba5b JW |
10819 | { |
10820 | qp_regno = md.qp.X_add_number - REG_P; | |
10821 | md.qp.X_op = O_absent; | |
10822 | } | |
800eeca4 JW |
10823 | |
10824 | flags = idesc->flags; | |
10825 | ||
10826 | if ((flags & IA64_OPCODE_FIRST) != 0) | |
9545c4ce L |
10827 | { |
10828 | /* The alignment frag has to end with a stop bit only if the | |
10829 | next instruction after the alignment directive has to be | |
10830 | the first instruction in an instruction group. */ | |
10831 | if (align_frag) | |
10832 | { | |
10833 | while (align_frag->fr_type != rs_align_code) | |
10834 | { | |
10835 | align_frag = align_frag->fr_next; | |
bae25f19 L |
10836 | if (!align_frag) |
10837 | break; | |
9545c4ce | 10838 | } |
bae25f19 L |
10839 | /* align_frag can be NULL if there are directives in |
10840 | between. */ | |
10841 | if (align_frag && align_frag->fr_next == frag_now) | |
9545c4ce L |
10842 | align_frag->tc_frag_data = 1; |
10843 | } | |
10844 | ||
10845 | insn_group_break (1, 0, 0); | |
10846 | } | |
10847 | align_frag = NULL; | |
800eeca4 JW |
10848 | |
10849 | if ((flags & IA64_OPCODE_NO_PRED) != 0 && qp_regno != 0) | |
10850 | { | |
ad4b42b4 | 10851 | as_bad (_("`%s' cannot be predicated"), idesc->name); |
800eeca4 JW |
10852 | goto done; |
10853 | } | |
10854 | ||
542d6675 | 10855 | /* Build the instruction. */ |
800eeca4 JW |
10856 | CURR_SLOT.qp_regno = qp_regno; |
10857 | CURR_SLOT.idesc = idesc; | |
10858 | as_where (&CURR_SLOT.src_file, &CURR_SLOT.src_line); | |
4dc7ead9 | 10859 | dwarf2_where (&CURR_SLOT.debug_line); |
661ba50f | 10860 | dwarf2_consume_line_info (); |
800eeca4 | 10861 | |
ba825241 | 10862 | /* Add unwind entries, if there are any. */ |
e0c9811a | 10863 | if (unwind.current_entry) |
800eeca4 | 10864 | { |
e0c9811a JW |
10865 | CURR_SLOT.unwind_record = unwind.current_entry; |
10866 | unwind.current_entry = NULL; | |
800eeca4 | 10867 | } |
ba825241 JB |
10868 | if (unwind.pending_saves) |
10869 | { | |
10870 | if (unwind.pending_saves->next) | |
10871 | { | |
10872 | /* Attach the next pending save to the next slot so that its | |
10873 | slot number will get set correctly. */ | |
10874 | add_unwind_entry (unwind.pending_saves->next, NOT_A_CHAR); | |
10875 | unwind.pending_saves = &unwind.pending_saves->next->r.record.p; | |
10876 | } | |
10877 | else | |
10878 | unwind.pending_saves = NULL; | |
10879 | } | |
5656b6b8 | 10880 | if (unwind.proc_pending.sym && S_IS_DEFINED (unwind.proc_pending.sym)) |
75e09913 | 10881 | unwind.insn = 1; |
800eeca4 | 10882 | |
542d6675 | 10883 | /* Check for dependency violations. */ |
800eeca4 | 10884 | if (md.detect_dv) |
542d6675 | 10885 | check_dv (idesc); |
800eeca4 JW |
10886 | |
10887 | md.curr_slot = (md.curr_slot + 1) % NUM_SLOTS; | |
10888 | if (++md.num_slots_in_use >= NUM_SLOTS) | |
10889 | emit_one_bundle (); | |
10890 | ||
10891 | if ((flags & IA64_OPCODE_LAST) != 0) | |
10892 | insn_group_break (1, 0, 0); | |
10893 | ||
10894 | md.last_text_seg = now_seg; | |
10895 | ||
10896 | done: | |
10897 | input_line_pointer = saved_input_line_pointer; | |
10898 | } | |
10899 | ||
10900 | /* Called when symbol NAME cannot be found in the symbol table. | |
10901 | Should be used for dynamic valued symbols only. */ | |
542d6675 KH |
10902 | |
10903 | symbolS * | |
5a49b8ac | 10904 | md_undefined_symbol (char *name ATTRIBUTE_UNUSED) |
800eeca4 JW |
10905 | { |
10906 | return 0; | |
10907 | } | |
10908 | ||
10909 | /* Called for any expression that can not be recognized. When the | |
10910 | function is called, `input_line_pointer' will point to the start of | |
10911 | the expression. */ | |
542d6675 | 10912 | |
800eeca4 | 10913 | void |
5a49b8ac | 10914 | md_operand (expressionS *e) |
800eeca4 | 10915 | { |
800eeca4 JW |
10916 | switch (*input_line_pointer) |
10917 | { | |
800eeca4 JW |
10918 | case '[': |
10919 | ++input_line_pointer; | |
60d11e55 | 10920 | expression_and_evaluate (e); |
800eeca4 JW |
10921 | if (*input_line_pointer != ']') |
10922 | { | |
ad4b42b4 | 10923 | as_bad (_("Closing bracket missing")); |
800eeca4 JW |
10924 | goto err; |
10925 | } | |
10926 | else | |
10927 | { | |
6a2375c6 JB |
10928 | if (e->X_op != O_register |
10929 | || e->X_add_number < REG_GR | |
10930 | || e->X_add_number > REG_GR + 127) | |
10931 | { | |
ad4b42b4 | 10932 | as_bad (_("Index must be a general register")); |
6a2375c6 JB |
10933 | e->X_add_number = REG_GR; |
10934 | } | |
800eeca4 JW |
10935 | |
10936 | ++input_line_pointer; | |
10937 | e->X_op = O_index; | |
10938 | } | |
10939 | break; | |
10940 | ||
10941 | default: | |
10942 | break; | |
10943 | } | |
10944 | return; | |
10945 | ||
10946 | err: | |
10947 | ignore_rest_of_line (); | |
10948 | } | |
10949 | ||
10950 | /* Return 1 if it's OK to adjust a reloc by replacing the symbol with | |
10951 | a section symbol plus some offset. For relocs involving @fptr(), | |
10952 | directives we don't want such adjustments since we need to have the | |
10953 | original symbol's name in the reloc. */ | |
10954 | int | |
5a49b8ac | 10955 | ia64_fix_adjustable (fixS *fix) |
800eeca4 JW |
10956 | { |
10957 | /* Prevent all adjustments to global symbols */ | |
e97b3f28 | 10958 | if (S_IS_EXTERNAL (fix->fx_addsy) || S_IS_WEAK (fix->fx_addsy)) |
800eeca4 JW |
10959 | return 0; |
10960 | ||
10961 | switch (fix->fx_r_type) | |
10962 | { | |
10963 | case BFD_RELOC_IA64_FPTR64I: | |
10964 | case BFD_RELOC_IA64_FPTR32MSB: | |
10965 | case BFD_RELOC_IA64_FPTR32LSB: | |
10966 | case BFD_RELOC_IA64_FPTR64MSB: | |
10967 | case BFD_RELOC_IA64_FPTR64LSB: | |
10968 | case BFD_RELOC_IA64_LTOFF_FPTR22: | |
10969 | case BFD_RELOC_IA64_LTOFF_FPTR64I: | |
10970 | return 0; | |
10971 | default: | |
10972 | break; | |
10973 | } | |
10974 | ||
10975 | return 1; | |
10976 | } | |
10977 | ||
10978 | int | |
5a49b8ac | 10979 | ia64_force_relocation (fixS *fix) |
800eeca4 JW |
10980 | { |
10981 | switch (fix->fx_r_type) | |
10982 | { | |
10983 | case BFD_RELOC_IA64_FPTR64I: | |
10984 | case BFD_RELOC_IA64_FPTR32MSB: | |
10985 | case BFD_RELOC_IA64_FPTR32LSB: | |
10986 | case BFD_RELOC_IA64_FPTR64MSB: | |
10987 | case BFD_RELOC_IA64_FPTR64LSB: | |
10988 | ||
10989 | case BFD_RELOC_IA64_LTOFF22: | |
10990 | case BFD_RELOC_IA64_LTOFF64I: | |
10991 | case BFD_RELOC_IA64_LTOFF_FPTR22: | |
10992 | case BFD_RELOC_IA64_LTOFF_FPTR64I: | |
10993 | case BFD_RELOC_IA64_PLTOFF22: | |
10994 | case BFD_RELOC_IA64_PLTOFF64I: | |
10995 | case BFD_RELOC_IA64_PLTOFF64MSB: | |
10996 | case BFD_RELOC_IA64_PLTOFF64LSB: | |
fa2c7eff RH |
10997 | |
10998 | case BFD_RELOC_IA64_LTOFF22X: | |
10999 | case BFD_RELOC_IA64_LDXMOV: | |
800eeca4 JW |
11000 | return 1; |
11001 | ||
11002 | default: | |
a161fe53 | 11003 | break; |
800eeca4 | 11004 | } |
a161fe53 | 11005 | |
ae6063d4 | 11006 | return generic_force_reloc (fix); |
800eeca4 JW |
11007 | } |
11008 | ||
11009 | /* Decide from what point a pc-relative relocation is relative to, | |
11010 | relative to the pc-relative fixup. Er, relatively speaking. */ | |
11011 | long | |
5a49b8ac | 11012 | ia64_pcrel_from_section (fixS *fix, segT sec) |
800eeca4 JW |
11013 | { |
11014 | unsigned long off = fix->fx_frag->fr_address + fix->fx_where; | |
197865e8 | 11015 | |
800eeca4 JW |
11016 | if (bfd_get_section_flags (stdoutput, sec) & SEC_CODE) |
11017 | off &= ~0xfUL; | |
11018 | ||
11019 | return off; | |
11020 | } | |
11021 | ||
6174d9c8 RH |
11022 | |
11023 | /* Used to emit section-relative relocs for the dwarf2 debug data. */ | |
11024 | void | |
11025 | ia64_dwarf2_emit_offset (symbolS *symbol, unsigned int size) | |
11026 | { | |
91d6fa6a | 11027 | expressionS exp; |
6174d9c8 | 11028 | |
91d6fa6a NC |
11029 | exp.X_op = O_pseudo_fixup; |
11030 | exp.X_op_symbol = pseudo_func[FUNC_SEC_RELATIVE].u.sym; | |
11031 | exp.X_add_number = 0; | |
11032 | exp.X_add_symbol = symbol; | |
11033 | emit_expr (&exp, size); | |
6174d9c8 RH |
11034 | } |
11035 | ||
800eeca4 JW |
11036 | /* This is called whenever some data item (not an instruction) needs a |
11037 | fixup. We pick the right reloc code depending on the byteorder | |
11038 | currently in effect. */ | |
11039 | void | |
62ebcb5c AM |
11040 | ia64_cons_fix_new (fragS *f, int where, int nbytes, expressionS *exp, |
11041 | bfd_reloc_code_real_type code) | |
800eeca4 | 11042 | { |
800eeca4 JW |
11043 | fixS *fix; |
11044 | ||
11045 | switch (nbytes) | |
11046 | { | |
11047 | /* There are no reloc for 8 and 16 bit quantities, but we allow | |
11048 | them here since they will work fine as long as the expression | |
11049 | is fully defined at the end of the pass over the source file. */ | |
11050 | case 1: code = BFD_RELOC_8; break; | |
11051 | case 2: code = BFD_RELOC_16; break; | |
11052 | case 4: | |
11053 | if (target_big_endian) | |
11054 | code = BFD_RELOC_IA64_DIR32MSB; | |
11055 | else | |
11056 | code = BFD_RELOC_IA64_DIR32LSB; | |
11057 | break; | |
11058 | ||
11059 | case 8: | |
40449e9f | 11060 | /* In 32-bit mode, data8 could mean function descriptors too. */ |
5f44c186 | 11061 | if (exp->X_op == O_pseudo_fixup |
40449e9f KH |
11062 | && exp->X_op_symbol |
11063 | && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC | |
11064 | && !(md.flags & EF_IA_64_ABI64)) | |
11065 | { | |
11066 | if (target_big_endian) | |
11067 | code = BFD_RELOC_IA64_IPLTMSB; | |
11068 | else | |
11069 | code = BFD_RELOC_IA64_IPLTLSB; | |
11070 | exp->X_op = O_symbol; | |
11071 | break; | |
11072 | } | |
11073 | else | |
11074 | { | |
11075 | if (target_big_endian) | |
11076 | code = BFD_RELOC_IA64_DIR64MSB; | |
11077 | else | |
11078 | code = BFD_RELOC_IA64_DIR64LSB; | |
11079 | break; | |
11080 | } | |
800eeca4 | 11081 | |
3969b680 RH |
11082 | case 16: |
11083 | if (exp->X_op == O_pseudo_fixup | |
11084 | && exp->X_op_symbol | |
11085 | && S_GET_VALUE (exp->X_op_symbol) == FUNC_IPLT_RELOC) | |
11086 | { | |
11087 | if (target_big_endian) | |
11088 | code = BFD_RELOC_IA64_IPLTMSB; | |
11089 | else | |
11090 | code = BFD_RELOC_IA64_IPLTLSB; | |
3969b680 RH |
11091 | exp->X_op = O_symbol; |
11092 | break; | |
11093 | } | |
11094 | /* FALLTHRU */ | |
11095 | ||
800eeca4 | 11096 | default: |
ad4b42b4 | 11097 | as_bad (_("Unsupported fixup size %d"), nbytes); |
800eeca4 JW |
11098 | ignore_rest_of_line (); |
11099 | return; | |
11100 | } | |
6174d9c8 | 11101 | |
800eeca4 JW |
11102 | if (exp->X_op == O_pseudo_fixup) |
11103 | { | |
800eeca4 JW |
11104 | exp->X_op = O_symbol; |
11105 | code = ia64_gen_real_reloc_type (exp->X_op_symbol, code); | |
6174d9c8 | 11106 | /* ??? If code unchanged, unsupported. */ |
800eeca4 | 11107 | } |
3969b680 | 11108 | |
800eeca4 JW |
11109 | fix = fix_new_exp (f, where, nbytes, exp, 0, code); |
11110 | /* We need to store the byte order in effect in case we're going | |
11111 | to fix an 8 or 16 bit relocation (for which there no real | |
55cf6793 | 11112 | relocs available). See md_apply_fix(). */ |
800eeca4 JW |
11113 | fix->tc_fix_data.bigendian = target_big_endian; |
11114 | } | |
11115 | ||
11116 | /* Return the actual relocation we wish to associate with the pseudo | |
11117 | reloc described by SYM and R_TYPE. SYM should be one of the | |
197865e8 | 11118 | symbols in the pseudo_func array, or NULL. */ |
800eeca4 JW |
11119 | |
11120 | static bfd_reloc_code_real_type | |
5a49b8ac | 11121 | ia64_gen_real_reloc_type (struct symbol *sym, bfd_reloc_code_real_type r_type) |
800eeca4 | 11122 | { |
d3ce72d0 | 11123 | bfd_reloc_code_real_type newr = 0; |
0ca3e455 | 11124 | const char *type = NULL, *suffix = ""; |
800eeca4 JW |
11125 | |
11126 | if (sym == NULL) | |
11127 | { | |
11128 | return r_type; | |
11129 | } | |
11130 | ||
11131 | switch (S_GET_VALUE (sym)) | |
11132 | { | |
11133 | case FUNC_FPTR_RELATIVE: | |
11134 | switch (r_type) | |
11135 | { | |
d3ce72d0 NC |
11136 | case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_FPTR64I; break; |
11137 | case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_FPTR32MSB; break; | |
11138 | case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_FPTR32LSB; break; | |
11139 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_FPTR64MSB; break; | |
11140 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_FPTR64LSB; break; | |
0ca3e455 | 11141 | default: type = "FPTR"; break; |
800eeca4 JW |
11142 | } |
11143 | break; | |
11144 | ||
11145 | case FUNC_GP_RELATIVE: | |
11146 | switch (r_type) | |
11147 | { | |
d3ce72d0 NC |
11148 | case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_GPREL22; break; |
11149 | case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_GPREL64I; break; | |
11150 | case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_GPREL32MSB; break; | |
11151 | case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_GPREL32LSB; break; | |
11152 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_GPREL64MSB; break; | |
11153 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_GPREL64LSB; break; | |
0ca3e455 | 11154 | default: type = "GPREL"; break; |
800eeca4 JW |
11155 | } |
11156 | break; | |
11157 | ||
11158 | case FUNC_LT_RELATIVE: | |
11159 | switch (r_type) | |
11160 | { | |
d3ce72d0 NC |
11161 | case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_LTOFF22; break; |
11162 | case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_LTOFF64I; break; | |
0ca3e455 | 11163 | default: type = "LTOFF"; break; |
800eeca4 JW |
11164 | } |
11165 | break; | |
11166 | ||
fa2c7eff RH |
11167 | case FUNC_LT_RELATIVE_X: |
11168 | switch (r_type) | |
11169 | { | |
d3ce72d0 | 11170 | case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_LTOFF22X; break; |
0ca3e455 | 11171 | default: type = "LTOFF"; suffix = "X"; break; |
fa2c7eff RH |
11172 | } |
11173 | break; | |
11174 | ||
c67e42c9 RH |
11175 | case FUNC_PC_RELATIVE: |
11176 | switch (r_type) | |
11177 | { | |
d3ce72d0 NC |
11178 | case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_PCREL22; break; |
11179 | case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_PCREL64I; break; | |
11180 | case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_PCREL32MSB; break; | |
11181 | case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_PCREL32LSB; break; | |
11182 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_PCREL64MSB; break; | |
11183 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_PCREL64LSB; break; | |
0ca3e455 | 11184 | default: type = "PCREL"; break; |
c67e42c9 RH |
11185 | } |
11186 | break; | |
11187 | ||
800eeca4 JW |
11188 | case FUNC_PLT_RELATIVE: |
11189 | switch (r_type) | |
11190 | { | |
d3ce72d0 NC |
11191 | case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_PLTOFF22; break; |
11192 | case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_PLTOFF64I; break; | |
11193 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_PLTOFF64MSB;break; | |
11194 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_PLTOFF64LSB;break; | |
0ca3e455 | 11195 | default: type = "PLTOFF"; break; |
800eeca4 JW |
11196 | } |
11197 | break; | |
11198 | ||
11199 | case FUNC_SEC_RELATIVE: | |
11200 | switch (r_type) | |
11201 | { | |
d3ce72d0 NC |
11202 | case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_SECREL32MSB;break; |
11203 | case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_SECREL32LSB;break; | |
11204 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_SECREL64MSB;break; | |
11205 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_SECREL64LSB;break; | |
0ca3e455 | 11206 | default: type = "SECREL"; break; |
800eeca4 JW |
11207 | } |
11208 | break; | |
11209 | ||
11210 | case FUNC_SEG_RELATIVE: | |
11211 | switch (r_type) | |
11212 | { | |
d3ce72d0 NC |
11213 | case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_SEGREL32MSB;break; |
11214 | case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_SEGREL32LSB;break; | |
11215 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_SEGREL64MSB;break; | |
11216 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_SEGREL64LSB;break; | |
0ca3e455 | 11217 | default: type = "SEGREL"; break; |
800eeca4 JW |
11218 | } |
11219 | break; | |
11220 | ||
11221 | case FUNC_LTV_RELATIVE: | |
11222 | switch (r_type) | |
11223 | { | |
d3ce72d0 NC |
11224 | case BFD_RELOC_IA64_DIR32MSB: newr = BFD_RELOC_IA64_LTV32MSB; break; |
11225 | case BFD_RELOC_IA64_DIR32LSB: newr = BFD_RELOC_IA64_LTV32LSB; break; | |
11226 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_LTV64MSB; break; | |
11227 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_LTV64LSB; break; | |
0ca3e455 | 11228 | default: type = "LTV"; break; |
800eeca4 JW |
11229 | } |
11230 | break; | |
11231 | ||
11232 | case FUNC_LT_FPTR_RELATIVE: | |
11233 | switch (r_type) | |
11234 | { | |
11235 | case BFD_RELOC_IA64_IMM22: | |
d3ce72d0 | 11236 | newr = BFD_RELOC_IA64_LTOFF_FPTR22; break; |
800eeca4 | 11237 | case BFD_RELOC_IA64_IMM64: |
d3ce72d0 | 11238 | newr = BFD_RELOC_IA64_LTOFF_FPTR64I; break; |
0ca3e455 | 11239 | case BFD_RELOC_IA64_DIR32MSB: |
d3ce72d0 | 11240 | newr = BFD_RELOC_IA64_LTOFF_FPTR32MSB; break; |
0ca3e455 | 11241 | case BFD_RELOC_IA64_DIR32LSB: |
d3ce72d0 | 11242 | newr = BFD_RELOC_IA64_LTOFF_FPTR32LSB; break; |
0ca3e455 | 11243 | case BFD_RELOC_IA64_DIR64MSB: |
d3ce72d0 | 11244 | newr = BFD_RELOC_IA64_LTOFF_FPTR64MSB; break; |
0ca3e455 | 11245 | case BFD_RELOC_IA64_DIR64LSB: |
d3ce72d0 | 11246 | newr = BFD_RELOC_IA64_LTOFF_FPTR64LSB; break; |
800eeca4 | 11247 | default: |
0ca3e455 | 11248 | type = "LTOFF_FPTR"; break; |
800eeca4 JW |
11249 | } |
11250 | break; | |
3969b680 | 11251 | |
13ae64f3 JJ |
11252 | case FUNC_TP_RELATIVE: |
11253 | switch (r_type) | |
11254 | { | |
d3ce72d0 NC |
11255 | case BFD_RELOC_IA64_IMM14: newr = BFD_RELOC_IA64_TPREL14; break; |
11256 | case BFD_RELOC_IA64_IMM22: newr = BFD_RELOC_IA64_TPREL22; break; | |
11257 | case BFD_RELOC_IA64_IMM64: newr = BFD_RELOC_IA64_TPREL64I; break; | |
11258 | case BFD_RELOC_IA64_DIR64MSB: newr = BFD_RELOC_IA64_TPREL64MSB; break; | |
11259 | case BFD_RELOC_IA64_DIR64LSB: newr = BFD_RELOC_IA64_TPREL64LSB; break; | |
0ca3e455 | 11260 | default: type = "TPREL"; break; |
13ae64f3 JJ |
11261 | } |
11262 | break; | |
11263 | ||
11264 | case FUNC_LT_TP_RELATIVE: | |
11265 | switch (r_type) | |
11266 | { | |
11267 | case BFD_RELOC_IA64_IMM22: | |
d3ce72d0 | 11268 | newr = BFD_RELOC_IA64_LTOFF_TPREL22; break; |
13ae64f3 | 11269 | default: |
0ca3e455 JB |
11270 | type = "LTOFF_TPREL"; break; |
11271 | } | |
11272 | break; | |
11273 | ||
11274 | case FUNC_DTP_MODULE: | |
11275 | switch (r_type) | |
11276 | { | |
11277 | case BFD_RELOC_IA64_DIR64MSB: | |
d3ce72d0 | 11278 | newr = BFD_RELOC_IA64_DTPMOD64MSB; break; |
0ca3e455 | 11279 | case BFD_RELOC_IA64_DIR64LSB: |
d3ce72d0 | 11280 | newr = BFD_RELOC_IA64_DTPMOD64LSB; break; |
0ca3e455 JB |
11281 | default: |
11282 | type = "DTPMOD"; break; | |
13ae64f3 JJ |
11283 | } |
11284 | break; | |
11285 | ||
11286 | case FUNC_LT_DTP_MODULE: | |
11287 | switch (r_type) | |
11288 | { | |
11289 | case BFD_RELOC_IA64_IMM22: | |
d3ce72d0 | 11290 | newr = BFD_RELOC_IA64_LTOFF_DTPMOD22; break; |
13ae64f3 | 11291 | default: |
0ca3e455 | 11292 | type = "LTOFF_DTPMOD"; break; |
13ae64f3 JJ |
11293 | } |
11294 | break; | |
11295 | ||
11296 | case FUNC_DTP_RELATIVE: | |
11297 | switch (r_type) | |
11298 | { | |
0ca3e455 | 11299 | case BFD_RELOC_IA64_DIR32MSB: |
d3ce72d0 | 11300 | newr = BFD_RELOC_IA64_DTPREL32MSB; break; |
0ca3e455 | 11301 | case BFD_RELOC_IA64_DIR32LSB: |
d3ce72d0 | 11302 | newr = BFD_RELOC_IA64_DTPREL32LSB; break; |
6174d9c8 | 11303 | case BFD_RELOC_IA64_DIR64MSB: |
d3ce72d0 | 11304 | newr = BFD_RELOC_IA64_DTPREL64MSB; break; |
6174d9c8 | 11305 | case BFD_RELOC_IA64_DIR64LSB: |
d3ce72d0 | 11306 | newr = BFD_RELOC_IA64_DTPREL64LSB; break; |
13ae64f3 | 11307 | case BFD_RELOC_IA64_IMM14: |
d3ce72d0 | 11308 | newr = BFD_RELOC_IA64_DTPREL14; break; |
13ae64f3 | 11309 | case BFD_RELOC_IA64_IMM22: |
d3ce72d0 | 11310 | newr = BFD_RELOC_IA64_DTPREL22; break; |
13ae64f3 | 11311 | case BFD_RELOC_IA64_IMM64: |
d3ce72d0 | 11312 | newr = BFD_RELOC_IA64_DTPREL64I; break; |
13ae64f3 | 11313 | default: |
0ca3e455 | 11314 | type = "DTPREL"; break; |
13ae64f3 JJ |
11315 | } |
11316 | break; | |
11317 | ||
11318 | case FUNC_LT_DTP_RELATIVE: | |
11319 | switch (r_type) | |
11320 | { | |
11321 | case BFD_RELOC_IA64_IMM22: | |
d3ce72d0 | 11322 | newr = BFD_RELOC_IA64_LTOFF_DTPREL22; break; |
13ae64f3 | 11323 | default: |
0ca3e455 | 11324 | type = "LTOFF_DTPREL"; break; |
13ae64f3 JJ |
11325 | } |
11326 | break; | |
11327 | ||
40449e9f | 11328 | case FUNC_IPLT_RELOC: |
0ca3e455 JB |
11329 | switch (r_type) |
11330 | { | |
11331 | case BFD_RELOC_IA64_IPLTMSB: return r_type; | |
11332 | case BFD_RELOC_IA64_IPLTLSB: return r_type; | |
11333 | default: type = "IPLT"; break; | |
11334 | } | |
40449e9f | 11335 | break; |
1cd8ff38 | 11336 | |
9d0e8497 TG |
11337 | #ifdef TE_VMS |
11338 | case FUNC_SLOTCOUNT_RELOC: | |
11339 | return DUMMY_RELOC_IA64_SLOTCOUNT; | |
11340 | #endif | |
11341 | ||
800eeca4 JW |
11342 | default: |
11343 | abort (); | |
11344 | } | |
6174d9c8 | 11345 | |
d3ce72d0 NC |
11346 | if (newr) |
11347 | return newr; | |
800eeca4 | 11348 | else |
0ca3e455 JB |
11349 | { |
11350 | int width; | |
11351 | ||
11352 | if (!type) | |
11353 | abort (); | |
11354 | switch (r_type) | |
11355 | { | |
11356 | case BFD_RELOC_IA64_DIR32MSB: width = 32; suffix = "MSB"; break; | |
11357 | case BFD_RELOC_IA64_DIR32LSB: width = 32; suffix = "LSB"; break; | |
11358 | case BFD_RELOC_IA64_DIR64MSB: width = 64; suffix = "MSB"; break; | |
11359 | case BFD_RELOC_IA64_DIR64LSB: width = 64; suffix = "LSB"; break; | |
30ad6cb9 | 11360 | case BFD_RELOC_UNUSED: width = 13; break; |
0ca3e455 JB |
11361 | case BFD_RELOC_IA64_IMM14: width = 14; break; |
11362 | case BFD_RELOC_IA64_IMM22: width = 22; break; | |
11363 | case BFD_RELOC_IA64_IMM64: width = 64; suffix = "I"; break; | |
11364 | default: abort (); | |
11365 | } | |
11366 | ||
11367 | /* This should be an error, but since previously there wasn't any | |
ad4b42b4 NC |
11368 | diagnostic here, don't make it fail because of this for now. */ |
11369 | as_warn (_("Cannot express %s%d%s relocation"), type, width, suffix); | |
0ca3e455 JB |
11370 | return r_type; |
11371 | } | |
800eeca4 JW |
11372 | } |
11373 | ||
11374 | /* Here is where generate the appropriate reloc for pseudo relocation | |
11375 | functions. */ | |
11376 | void | |
5a49b8ac | 11377 | ia64_validate_fix (fixS *fix) |
800eeca4 JW |
11378 | { |
11379 | switch (fix->fx_r_type) | |
11380 | { | |
11381 | case BFD_RELOC_IA64_FPTR64I: | |
11382 | case BFD_RELOC_IA64_FPTR32MSB: | |
11383 | case BFD_RELOC_IA64_FPTR64LSB: | |
11384 | case BFD_RELOC_IA64_LTOFF_FPTR22: | |
11385 | case BFD_RELOC_IA64_LTOFF_FPTR64I: | |
11386 | if (fix->fx_offset != 0) | |
11387 | as_bad_where (fix->fx_file, fix->fx_line, | |
ad4b42b4 | 11388 | _("No addend allowed in @fptr() relocation")); |
800eeca4 JW |
11389 | break; |
11390 | default: | |
11391 | break; | |
11392 | } | |
800eeca4 JW |
11393 | } |
11394 | ||
11395 | static void | |
5a49b8ac | 11396 | fix_insn (fixS *fix, const struct ia64_operand *odesc, valueT value) |
800eeca4 JW |
11397 | { |
11398 | bfd_vma insn[3], t0, t1, control_bits; | |
11399 | const char *err; | |
11400 | char *fixpos; | |
11401 | long slot; | |
11402 | ||
11403 | slot = fix->fx_where & 0x3; | |
11404 | fixpos = fix->fx_frag->fr_literal + (fix->fx_where - slot); | |
11405 | ||
c67e42c9 | 11406 | /* Bundles are always in little-endian byte order */ |
800eeca4 JW |
11407 | t0 = bfd_getl64 (fixpos); |
11408 | t1 = bfd_getl64 (fixpos + 8); | |
11409 | control_bits = t0 & 0x1f; | |
11410 | insn[0] = (t0 >> 5) & 0x1ffffffffffLL; | |
11411 | insn[1] = ((t0 >> 46) & 0x3ffff) | ((t1 & 0x7fffff) << 18); | |
11412 | insn[2] = (t1 >> 23) & 0x1ffffffffffLL; | |
11413 | ||
c67e42c9 RH |
11414 | err = NULL; |
11415 | if (odesc - elf64_ia64_operands == IA64_OPND_IMMU64) | |
800eeca4 | 11416 | { |
c67e42c9 RH |
11417 | insn[1] = (value >> 22) & 0x1ffffffffffLL; |
11418 | insn[2] |= (((value & 0x7f) << 13) | |
11419 | | (((value >> 7) & 0x1ff) << 27) | |
11420 | | (((value >> 16) & 0x1f) << 22) | |
11421 | | (((value >> 21) & 0x1) << 21) | |
11422 | | (((value >> 63) & 0x1) << 36)); | |
800eeca4 | 11423 | } |
c67e42c9 RH |
11424 | else if (odesc - elf64_ia64_operands == IA64_OPND_IMMU62) |
11425 | { | |
11426 | if (value & ~0x3fffffffffffffffULL) | |
20203fb9 | 11427 | err = _("integer operand out of range"); |
c67e42c9 RH |
11428 | insn[1] = (value >> 21) & 0x1ffffffffffLL; |
11429 | insn[2] |= (((value & 0xfffff) << 6) | (((value >> 20) & 0x1) << 36)); | |
11430 | } | |
11431 | else if (odesc - elf64_ia64_operands == IA64_OPND_TGT64) | |
11432 | { | |
11433 | value >>= 4; | |
11434 | insn[1] = ((value >> 20) & 0x7fffffffffLL) << 2; | |
11435 | insn[2] |= ((((value >> 59) & 0x1) << 36) | |
11436 | | (((value >> 0) & 0xfffff) << 13)); | |
11437 | } | |
11438 | else | |
11439 | err = (*odesc->insert) (odesc, value, insn + slot); | |
11440 | ||
11441 | if (err) | |
83cf10fd | 11442 | as_bad_where (fix->fx_file, fix->fx_line, "%s", err); |
800eeca4 JW |
11443 | |
11444 | t0 = control_bits | (insn[0] << 5) | (insn[1] << 46); | |
11445 | t1 = ((insn[1] >> 18) & 0x7fffff) | (insn[2] << 23); | |
44f5c83a JW |
11446 | number_to_chars_littleendian (fixpos + 0, t0, 8); |
11447 | number_to_chars_littleendian (fixpos + 8, t1, 8); | |
800eeca4 JW |
11448 | } |
11449 | ||
11450 | /* Attempt to simplify or even eliminate a fixup. The return value is | |
11451 | ignored; perhaps it was once meaningful, but now it is historical. | |
11452 | To indicate that a fixup has been eliminated, set FIXP->FX_DONE. | |
11453 | ||
11454 | If fixp->fx_addsy is non-NULL, we'll have to generate a reloc entry | |
197865e8 | 11455 | (if possible). */ |
94f592af NC |
11456 | |
11457 | void | |
5a49b8ac | 11458 | md_apply_fix (fixS *fix, valueT *valP, segT seg ATTRIBUTE_UNUSED) |
800eeca4 JW |
11459 | { |
11460 | char *fixpos; | |
40449e9f | 11461 | valueT value = *valP; |
800eeca4 JW |
11462 | |
11463 | fixpos = fix->fx_frag->fr_literal + fix->fx_where; | |
11464 | ||
11465 | if (fix->fx_pcrel) | |
11466 | { | |
7b347e43 JB |
11467 | switch (fix->fx_r_type) |
11468 | { | |
11469 | case BFD_RELOC_IA64_PCREL21B: break; | |
11470 | case BFD_RELOC_IA64_PCREL21BI: break; | |
11471 | case BFD_RELOC_IA64_PCREL21F: break; | |
11472 | case BFD_RELOC_IA64_PCREL21M: break; | |
11473 | case BFD_RELOC_IA64_PCREL60B: break; | |
11474 | case BFD_RELOC_IA64_PCREL22: break; | |
11475 | case BFD_RELOC_IA64_PCREL64I: break; | |
11476 | case BFD_RELOC_IA64_PCREL32MSB: break; | |
11477 | case BFD_RELOC_IA64_PCREL32LSB: break; | |
11478 | case BFD_RELOC_IA64_PCREL64MSB: break; | |
11479 | case BFD_RELOC_IA64_PCREL64LSB: break; | |
11480 | default: | |
11481 | fix->fx_r_type = ia64_gen_real_reloc_type (pseudo_func[FUNC_PC_RELATIVE].u.sym, | |
11482 | fix->fx_r_type); | |
11483 | break; | |
11484 | } | |
800eeca4 JW |
11485 | } |
11486 | if (fix->fx_addsy) | |
11487 | { | |
592588f3 | 11488 | switch ((unsigned) fix->fx_r_type) |
800eeca4 | 11489 | { |
00f7efb6 | 11490 | case BFD_RELOC_UNUSED: |
fa1cb89c JW |
11491 | /* This must be a TAG13 or TAG13b operand. There are no external |
11492 | relocs defined for them, so we must give an error. */ | |
800eeca4 | 11493 | as_bad_where (fix->fx_file, fix->fx_line, |
ad4b42b4 | 11494 | _("%s must have a constant value"), |
800eeca4 | 11495 | elf64_ia64_operands[fix->tc_fix_data.opnd].desc); |
fa1cb89c | 11496 | fix->fx_done = 1; |
94f592af | 11497 | return; |
00f7efb6 JJ |
11498 | |
11499 | case BFD_RELOC_IA64_TPREL14: | |
11500 | case BFD_RELOC_IA64_TPREL22: | |
11501 | case BFD_RELOC_IA64_TPREL64I: | |
11502 | case BFD_RELOC_IA64_LTOFF_TPREL22: | |
11503 | case BFD_RELOC_IA64_LTOFF_DTPMOD22: | |
11504 | case BFD_RELOC_IA64_DTPREL14: | |
11505 | case BFD_RELOC_IA64_DTPREL22: | |
11506 | case BFD_RELOC_IA64_DTPREL64I: | |
11507 | case BFD_RELOC_IA64_LTOFF_DTPREL22: | |
11508 | S_SET_THREAD_LOCAL (fix->fx_addsy); | |
11509 | break; | |
7925dd68 | 11510 | |
9d0e8497 TG |
11511 | #ifdef TE_VMS |
11512 | case DUMMY_RELOC_IA64_SLOTCOUNT: | |
11513 | as_bad_where (fix->fx_file, fix->fx_line, | |
11514 | _("cannot resolve @slotcount parameter")); | |
11515 | fix->fx_done = 1; | |
11516 | return; | |
11517 | #endif | |
11518 | ||
7925dd68 JJ |
11519 | default: |
11520 | break; | |
800eeca4 | 11521 | } |
800eeca4 JW |
11522 | } |
11523 | else if (fix->tc_fix_data.opnd == IA64_OPND_NIL) | |
11524 | { | |
9d0e8497 TG |
11525 | #ifdef TE_VMS |
11526 | if (fix->fx_r_type == DUMMY_RELOC_IA64_SLOTCOUNT) | |
11527 | { | |
11528 | /* For @slotcount, convert an addresses difference to a slots | |
11529 | difference. */ | |
11530 | valueT v; | |
11531 | ||
11532 | v = (value >> 4) * 3; | |
11533 | switch (value & 0x0f) | |
11534 | { | |
11535 | case 0: | |
11536 | case 1: | |
11537 | case 2: | |
11538 | v += value & 0x0f; | |
11539 | break; | |
11540 | case 0x0f: | |
11541 | v += 2; | |
11542 | break; | |
11543 | case 0x0e: | |
11544 | v += 1; | |
11545 | break; | |
11546 | default: | |
11547 | as_bad (_("invalid @slotcount value")); | |
11548 | } | |
11549 | value = v; | |
11550 | } | |
11551 | #endif | |
11552 | ||
800eeca4 JW |
11553 | if (fix->tc_fix_data.bigendian) |
11554 | number_to_chars_bigendian (fixpos, value, fix->fx_size); | |
11555 | else | |
11556 | number_to_chars_littleendian (fixpos, value, fix->fx_size); | |
11557 | fix->fx_done = 1; | |
800eeca4 JW |
11558 | } |
11559 | else | |
11560 | { | |
11561 | fix_insn (fix, elf64_ia64_operands + fix->tc_fix_data.opnd, value); | |
11562 | fix->fx_done = 1; | |
800eeca4 | 11563 | } |
800eeca4 JW |
11564 | } |
11565 | ||
11566 | /* Generate the BFD reloc to be stuck in the object file from the | |
11567 | fixup used internally in the assembler. */ | |
542d6675 KH |
11568 | |
11569 | arelent * | |
5a49b8ac | 11570 | tc_gen_reloc (asection *sec ATTRIBUTE_UNUSED, fixS *fixp) |
800eeca4 JW |
11571 | { |
11572 | arelent *reloc; | |
11573 | ||
11574 | reloc = xmalloc (sizeof (*reloc)); | |
11575 | reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); | |
11576 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); | |
11577 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; | |
11578 | reloc->addend = fixp->fx_offset; | |
11579 | reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); | |
11580 | ||
11581 | if (!reloc->howto) | |
11582 | { | |
11583 | as_bad_where (fixp->fx_file, fixp->fx_line, | |
ad4b42b4 | 11584 | _("Cannot represent %s relocation in object file"), |
800eeca4 | 11585 | bfd_get_reloc_code_name (fixp->fx_r_type)); |
cf738528 AS |
11586 | free (reloc); |
11587 | return NULL; | |
800eeca4 JW |
11588 | } |
11589 | return reloc; | |
11590 | } | |
11591 | ||
11592 | /* Turn a string in input_line_pointer into a floating point constant | |
bc0d738a NC |
11593 | of type TYPE, and store the appropriate bytes in *LIT. The number |
11594 | of LITTLENUMS emitted is stored in *SIZE. An error message is | |
800eeca4 JW |
11595 | returned, or NULL on OK. */ |
11596 | ||
11597 | #define MAX_LITTLENUMS 5 | |
11598 | ||
542d6675 | 11599 | char * |
499ac353 | 11600 | md_atof (int type, char *lit, int *size) |
800eeca4 JW |
11601 | { |
11602 | LITTLENUM_TYPE words[MAX_LITTLENUMS]; | |
800eeca4 JW |
11603 | char *t; |
11604 | int prec; | |
11605 | ||
11606 | switch (type) | |
11607 | { | |
11608 | /* IEEE floats */ | |
11609 | case 'f': | |
11610 | case 'F': | |
11611 | case 's': | |
11612 | case 'S': | |
11613 | prec = 2; | |
11614 | break; | |
11615 | ||
11616 | case 'd': | |
11617 | case 'D': | |
11618 | case 'r': | |
11619 | case 'R': | |
11620 | prec = 4; | |
11621 | break; | |
11622 | ||
11623 | case 'x': | |
11624 | case 'X': | |
11625 | case 'p': | |
11626 | case 'P': | |
11627 | prec = 5; | |
11628 | break; | |
11629 | ||
11630 | default: | |
11631 | *size = 0; | |
499ac353 | 11632 | return _("Unrecognized or unsupported floating point constant"); |
800eeca4 JW |
11633 | } |
11634 | t = atof_ieee (input_line_pointer, type, words); | |
11635 | if (t) | |
11636 | input_line_pointer = t; | |
800eeca4 | 11637 | |
10a98291 L |
11638 | (*ia64_float_to_chars) (lit, words, prec); |
11639 | ||
165a7f90 L |
11640 | if (type == 'X') |
11641 | { | |
11642 | /* It is 10 byte floating point with 6 byte padding. */ | |
10a98291 | 11643 | memset (&lit [10], 0, 6); |
165a7f90 L |
11644 | *size = 8 * sizeof (LITTLENUM_TYPE); |
11645 | } | |
10a98291 L |
11646 | else |
11647 | *size = prec * sizeof (LITTLENUM_TYPE); | |
11648 | ||
499ac353 | 11649 | return NULL; |
800eeca4 JW |
11650 | } |
11651 | ||
800eeca4 JW |
11652 | /* Handle ia64 specific semantics of the align directive. */ |
11653 | ||
0a9ef439 | 11654 | void |
5a49b8ac AM |
11655 | ia64_md_do_align (int n ATTRIBUTE_UNUSED, |
11656 | const char *fill ATTRIBUTE_UNUSED, | |
11657 | int len ATTRIBUTE_UNUSED, | |
11658 | int max ATTRIBUTE_UNUSED) | |
800eeca4 | 11659 | { |
0a9ef439 | 11660 | if (subseg_text_p (now_seg)) |
800eeca4 | 11661 | ia64_flush_insns (); |
0a9ef439 | 11662 | } |
800eeca4 | 11663 | |
0a9ef439 RH |
11664 | /* This is called from HANDLE_ALIGN in write.c. Fill in the contents |
11665 | of an rs_align_code fragment. */ | |
800eeca4 | 11666 | |
0a9ef439 | 11667 | void |
5a49b8ac | 11668 | ia64_handle_align (fragS *fragp) |
0a9ef439 | 11669 | { |
0a9ef439 RH |
11670 | int bytes; |
11671 | char *p; | |
91d6fa6a | 11672 | const unsigned char *nop_type; |
0a9ef439 RH |
11673 | |
11674 | if (fragp->fr_type != rs_align_code) | |
11675 | return; | |
11676 | ||
9545c4ce | 11677 | /* Check if this frag has to end with a stop bit. */ |
91d6fa6a | 11678 | nop_type = fragp->tc_frag_data ? le_nop_stop : le_nop; |
9545c4ce | 11679 | |
0a9ef439 RH |
11680 | bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix; |
11681 | p = fragp->fr_literal + fragp->fr_fix; | |
11682 | ||
3739860c | 11683 | /* If no paddings are needed, we check if we need a stop bit. */ |
d9201763 L |
11684 | if (!bytes && fragp->tc_frag_data) |
11685 | { | |
11686 | if (fragp->fr_fix < 16) | |
bae25f19 L |
11687 | #if 1 |
11688 | /* FIXME: It won't work with | |
11689 | .align 16 | |
11690 | alloc r32=ar.pfs,1,2,4,0 | |
11691 | */ | |
11692 | ; | |
11693 | #else | |
d9201763 L |
11694 | as_bad_where (fragp->fr_file, fragp->fr_line, |
11695 | _("Can't add stop bit to mark end of instruction group")); | |
bae25f19 | 11696 | #endif |
d9201763 L |
11697 | else |
11698 | /* Bundles are always in little-endian byte order. Make sure | |
11699 | the previous bundle has the stop bit. */ | |
11700 | *(p - 16) |= 1; | |
11701 | } | |
11702 | ||
0a9ef439 RH |
11703 | /* Make sure we are on a 16-byte boundary, in case someone has been |
11704 | putting data into a text section. */ | |
11705 | if (bytes & 15) | |
11706 | { | |
11707 | int fix = bytes & 15; | |
11708 | memset (p, 0, fix); | |
11709 | p += fix; | |
11710 | bytes -= fix; | |
11711 | fragp->fr_fix += fix; | |
800eeca4 JW |
11712 | } |
11713 | ||
012a452b | 11714 | /* Instruction bundles are always little-endian. */ |
91d6fa6a | 11715 | memcpy (p, nop_type, 16); |
0a9ef439 | 11716 | fragp->fr_var = 16; |
800eeca4 | 11717 | } |
10a98291 L |
11718 | |
11719 | static void | |
11720 | ia64_float_to_chars_bigendian (char *lit, LITTLENUM_TYPE *words, | |
11721 | int prec) | |
11722 | { | |
11723 | while (prec--) | |
11724 | { | |
11725 | number_to_chars_bigendian (lit, (long) (*words++), | |
11726 | sizeof (LITTLENUM_TYPE)); | |
11727 | lit += sizeof (LITTLENUM_TYPE); | |
11728 | } | |
11729 | } | |
11730 | ||
11731 | static void | |
11732 | ia64_float_to_chars_littleendian (char *lit, LITTLENUM_TYPE *words, | |
11733 | int prec) | |
11734 | { | |
11735 | while (prec--) | |
11736 | { | |
11737 | number_to_chars_littleendian (lit, (long) (words[prec]), | |
11738 | sizeof (LITTLENUM_TYPE)); | |
11739 | lit += sizeof (LITTLENUM_TYPE); | |
11740 | } | |
11741 | } | |
11742 | ||
11743 | void | |
5a49b8ac | 11744 | ia64_elf_section_change_hook (void) |
10a98291 | 11745 | { |
38ce5b11 L |
11746 | if (elf_section_type (now_seg) == SHT_IA_64_UNWIND |
11747 | && elf_linked_to_section (now_seg) == NULL) | |
11748 | elf_linked_to_section (now_seg) = text_section; | |
10a98291 L |
11749 | dot_byteorder (-1); |
11750 | } | |
a645d1eb L |
11751 | |
11752 | /* Check if a label should be made global. */ | |
11753 | void | |
11754 | ia64_check_label (symbolS *label) | |
11755 | { | |
11756 | if (*input_line_pointer == ':') | |
11757 | { | |
11758 | S_SET_EXTERNAL (label); | |
11759 | input_line_pointer++; | |
11760 | } | |
11761 | } | |
35f5df7f L |
11762 | |
11763 | /* Used to remember where .alias and .secalias directives are seen. We | |
11764 | will rename symbol and section names when we are about to output | |
11765 | the relocatable file. */ | |
11766 | struct alias | |
11767 | { | |
11768 | char *file; /* The file where the directive is seen. */ | |
11769 | unsigned int line; /* The line number the directive is at. */ | |
708587a4 | 11770 | const char *name; /* The original name of the symbol. */ |
35f5df7f L |
11771 | }; |
11772 | ||
11773 | /* Called for .alias and .secalias directives. If SECTION is 1, it is | |
11774 | .secalias. Otherwise, it is .alias. */ | |
11775 | static void | |
11776 | dot_alias (int section) | |
11777 | { | |
11778 | char *name, *alias; | |
11779 | char delim; | |
11780 | char *end_name; | |
11781 | int len; | |
11782 | const char *error_string; | |
11783 | struct alias *h; | |
11784 | const char *a; | |
11785 | struct hash_control *ahash, *nhash; | |
11786 | const char *kind; | |
11787 | ||
d02603dc | 11788 | delim = get_symbol_name (&name); |
35f5df7f L |
11789 | end_name = input_line_pointer; |
11790 | *end_name = delim; | |
11791 | ||
11792 | if (name == end_name) | |
11793 | { | |
11794 | as_bad (_("expected symbol name")); | |
e4e8248d | 11795 | ignore_rest_of_line (); |
35f5df7f L |
11796 | return; |
11797 | } | |
11798 | ||
d02603dc | 11799 | SKIP_WHITESPACE_AFTER_NAME (); |
35f5df7f L |
11800 | |
11801 | if (*input_line_pointer != ',') | |
11802 | { | |
11803 | *end_name = 0; | |
11804 | as_bad (_("expected comma after \"%s\""), name); | |
11805 | *end_name = delim; | |
11806 | ignore_rest_of_line (); | |
11807 | return; | |
11808 | } | |
11809 | ||
11810 | input_line_pointer++; | |
11811 | *end_name = 0; | |
20b36a95 | 11812 | ia64_canonicalize_symbol_name (name); |
35f5df7f L |
11813 | |
11814 | /* We call demand_copy_C_string to check if alias string is valid. | |
11815 | There should be a closing `"' and no `\0' in the string. */ | |
11816 | alias = demand_copy_C_string (&len); | |
11817 | if (alias == NULL) | |
11818 | { | |
11819 | ignore_rest_of_line (); | |
11820 | return; | |
11821 | } | |
11822 | ||
11823 | /* Make a copy of name string. */ | |
11824 | len = strlen (name) + 1; | |
11825 | obstack_grow (¬es, name, len); | |
11826 | name = obstack_finish (¬es); | |
11827 | ||
11828 | if (section) | |
11829 | { | |
11830 | kind = "section"; | |
11831 | ahash = secalias_hash; | |
11832 | nhash = secalias_name_hash; | |
11833 | } | |
11834 | else | |
11835 | { | |
11836 | kind = "symbol"; | |
11837 | ahash = alias_hash; | |
11838 | nhash = alias_name_hash; | |
11839 | } | |
11840 | ||
11841 | /* Check if alias has been used before. */ | |
11842 | h = (struct alias *) hash_find (ahash, alias); | |
11843 | if (h) | |
11844 | { | |
11845 | if (strcmp (h->name, name)) | |
11846 | as_bad (_("`%s' is already the alias of %s `%s'"), | |
11847 | alias, kind, h->name); | |
11848 | goto out; | |
11849 | } | |
11850 | ||
11851 | /* Check if name already has an alias. */ | |
11852 | a = (const char *) hash_find (nhash, name); | |
11853 | if (a) | |
11854 | { | |
11855 | if (strcmp (a, alias)) | |
11856 | as_bad (_("%s `%s' already has an alias `%s'"), kind, name, a); | |
11857 | goto out; | |
11858 | } | |
11859 | ||
11860 | h = (struct alias *) xmalloc (sizeof (struct alias)); | |
11861 | as_where (&h->file, &h->line); | |
11862 | h->name = name; | |
3739860c | 11863 | |
5a49b8ac | 11864 | error_string = hash_jam (ahash, alias, (void *) h); |
35f5df7f L |
11865 | if (error_string) |
11866 | { | |
11867 | as_fatal (_("inserting \"%s\" into %s alias hash table failed: %s"), | |
11868 | alias, kind, error_string); | |
11869 | goto out; | |
11870 | } | |
11871 | ||
5a49b8ac | 11872 | error_string = hash_jam (nhash, name, (void *) alias); |
35f5df7f L |
11873 | if (error_string) |
11874 | { | |
11875 | as_fatal (_("inserting \"%s\" into %s name hash table failed: %s"), | |
11876 | alias, kind, error_string); | |
11877 | out: | |
11878 | obstack_free (¬es, name); | |
11879 | obstack_free (¬es, alias); | |
11880 | } | |
11881 | ||
11882 | demand_empty_rest_of_line (); | |
11883 | } | |
11884 | ||
11885 | /* It renames the original symbol name to its alias. */ | |
11886 | static void | |
5a49b8ac | 11887 | do_alias (const char *alias, void *value) |
35f5df7f L |
11888 | { |
11889 | struct alias *h = (struct alias *) value; | |
11890 | symbolS *sym = symbol_find (h->name); | |
11891 | ||
11892 | if (sym == NULL) | |
01e1a5bc NC |
11893 | { |
11894 | #ifdef TE_VMS | |
11895 | /* Uses .alias extensively to alias CRTL functions to same with | |
11896 | decc$ prefix. Sometimes function gets optimized away and a | |
11897 | warning results, which should be suppressed. */ | |
11898 | if (strncmp (alias, "decc$", 5) != 0) | |
11899 | #endif | |
11900 | as_warn_where (h->file, h->line, | |
11901 | _("symbol `%s' aliased to `%s' is not used"), | |
11902 | h->name, alias); | |
11903 | } | |
35f5df7f L |
11904 | else |
11905 | S_SET_NAME (sym, (char *) alias); | |
11906 | } | |
11907 | ||
11908 | /* Called from write_object_file. */ | |
11909 | void | |
11910 | ia64_adjust_symtab (void) | |
11911 | { | |
11912 | hash_traverse (alias_hash, do_alias); | |
11913 | } | |
11914 | ||
11915 | /* It renames the original section name to its alias. */ | |
11916 | static void | |
5a49b8ac | 11917 | do_secalias (const char *alias, void *value) |
35f5df7f L |
11918 | { |
11919 | struct alias *h = (struct alias *) value; | |
11920 | segT sec = bfd_get_section_by_name (stdoutput, h->name); | |
11921 | ||
11922 | if (sec == NULL) | |
11923 | as_warn_where (h->file, h->line, | |
11924 | _("section `%s' aliased to `%s' is not used"), | |
11925 | h->name, alias); | |
11926 | else | |
11927 | sec->name = alias; | |
11928 | } | |
11929 | ||
11930 | /* Called from write_object_file. */ | |
11931 | void | |
11932 | ia64_frob_file (void) | |
11933 | { | |
11934 | hash_traverse (secalias_hash, do_secalias); | |
11935 | } | |
01e1a5bc NC |
11936 | |
11937 | #ifdef TE_VMS | |
11938 | #define NT_VMS_MHD 1 | |
11939 | #define NT_VMS_LNM 2 | |
11940 | ||
11941 | /* Integrity VMS 8.x identifies it's ELF modules with a standard ELF | |
11942 | .note section. */ | |
11943 | ||
11944 | /* Manufacture a VMS-like time string. */ | |
11945 | static void | |
11946 | get_vms_time (char *Now) | |
11947 | { | |
11948 | char *pnt; | |
11949 | time_t timeb; | |
11950 | ||
11951 | time (&timeb); | |
11952 | pnt = ctime (&timeb); | |
11953 | pnt[3] = 0; | |
11954 | pnt[7] = 0; | |
11955 | pnt[10] = 0; | |
11956 | pnt[16] = 0; | |
11957 | pnt[24] = 0; | |
11958 | sprintf (Now, "%2s-%3s-%s %s", pnt + 8, pnt + 4, pnt + 20, pnt + 11); | |
11959 | } | |
11960 | ||
11961 | void | |
11962 | ia64_vms_note (void) | |
11963 | { | |
11964 | char *p; | |
11965 | asection *seg = now_seg; | |
11966 | subsegT subseg = now_subseg; | |
01e1a5bc | 11967 | asection *secp = NULL; |
a0840211 | 11968 | char *bname; |
01e1a5bc NC |
11969 | char buf [256]; |
11970 | symbolS *sym; | |
11971 | ||
11972 | /* Create the .note section. */ | |
11973 | ||
11974 | secp = subseg_new (".note", 0); | |
11975 | bfd_set_section_flags (stdoutput, | |
11976 | secp, | |
11977 | SEC_HAS_CONTENTS | SEC_READONLY); | |
11978 | ||
37a1f277 | 11979 | /* Module header note (MHD). */ |
a0840211 | 11980 | bname = xstrdup (lbasename (out_file_name)); |
01e1a5bc NC |
11981 | if ((p = strrchr (bname, '.'))) |
11982 | *p = '\0'; | |
3739860c | 11983 | |
37a1f277 TG |
11984 | /* VMS note header is 24 bytes long. */ |
11985 | p = frag_more (8 + 8 + 8); | |
11986 | number_to_chars_littleendian (p + 0, 8, 8); | |
11987 | number_to_chars_littleendian (p + 8, 40 + strlen (bname), 8); | |
11988 | number_to_chars_littleendian (p + 16, NT_VMS_MHD, 8); | |
01e1a5bc NC |
11989 | |
11990 | p = frag_more (8); | |
11991 | strcpy (p, "IPF/VMS"); | |
11992 | ||
37a1f277 TG |
11993 | p = frag_more (17 + 17 + strlen (bname) + 1 + 5); |
11994 | get_vms_time (p); | |
11995 | strcpy (p + 17, "24-FEB-2005 15:00"); | |
11996 | p += 17 + 17; | |
01e1a5bc | 11997 | strcpy (p, bname); |
37a1f277 | 11998 | p += strlen (bname) + 1; |
a0840211 | 11999 | free (bname); |
01e1a5bc NC |
12000 | strcpy (p, "V1.0"); |
12001 | ||
12002 | frag_align (3, 0, 0); | |
12003 | ||
12004 | /* Language processor name note. */ | |
12005 | sprintf (buf, "GNU assembler version %s (%s) using BFD version %s", | |
12006 | VERSION, TARGET_ALIAS, BFD_VERSION_STRING); | |
12007 | ||
37a1f277 TG |
12008 | p = frag_more (8 + 8 + 8); |
12009 | number_to_chars_littleendian (p + 0, 8, 8); | |
12010 | number_to_chars_littleendian (p + 8, strlen (buf) + 1, 8); | |
12011 | number_to_chars_littleendian (p + 16, NT_VMS_LNM, 8); | |
01e1a5bc NC |
12012 | |
12013 | p = frag_more (8); | |
12014 | strcpy (p, "IPF/VMS"); | |
12015 | ||
12016 | p = frag_more (strlen (buf) + 1); | |
12017 | strcpy (p, buf); | |
12018 | ||
12019 | frag_align (3, 0, 0); | |
12020 | ||
12021 | secp = subseg_new (".vms_display_name_info", 0); | |
12022 | bfd_set_section_flags (stdoutput, | |
12023 | secp, | |
12024 | SEC_HAS_CONTENTS | SEC_READONLY); | |
12025 | ||
12026 | /* This symbol should be passed on the command line and be variable | |
12027 | according to language. */ | |
12028 | sym = symbol_new ("__gnat_vms_display_name@gnat_demangler_rtl", | |
12029 | absolute_section, 0, &zero_address_frag); | |
12030 | symbol_table_insert (sym); | |
12031 | symbol_get_bfdsym (sym)->flags |= BSF_DEBUGGING | BSF_DYNAMIC; | |
12032 | ||
12033 | p = frag_more (4); | |
12034 | /* Format 3 of VMS demangler Spec. */ | |
12035 | number_to_chars_littleendian (p, 3, 4); | |
12036 | ||
12037 | p = frag_more (4); | |
12038 | /* Place holder for symbol table index of above symbol. */ | |
12039 | number_to_chars_littleendian (p, -1, 4); | |
12040 | ||
12041 | frag_align (3, 0, 0); | |
12042 | ||
12043 | /* We probably can't restore the current segment, for there likely | |
12044 | isn't one yet... */ | |
12045 | if (seg && subseg) | |
12046 | subseg_set (seg, subseg); | |
12047 | } | |
12048 | ||
12049 | #endif /* TE_VMS */ |