1 /* tc-alpha.c - Processor-specific code for the DEC Alpha AXP CPU.
2 Copyright (C) 1989, 93-98, 1999, 2000 Free Software Foundation, Inc.
3 Contributed by Carnegie Mellon University, 1993.
4 Written by Alessandro Forin, based on earlier gas-1.38 target CPU files.
5 Modified by Ken Raeburn for gas-2.x and ECOFF support.
6 Modified by Richard Henderson for ELF support.
7 Modified by Klaus K"ampf for EVAX (OpenVMS/Alpha) support.
9 This file is part of GAS, the GNU Assembler.
11 GAS is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2, or (at your option)
16 GAS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with GAS; see the file COPYING. If not, write to the Free
23 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 * Mach Operating System
28 * Copyright (c) 1993 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie the
49 * rights to redistribute these changes.
54 #include "struc-symbol.h"
57 #include "opcode/alpha.h"
60 #include "elf/alpha.h"
61 #include "dwarf2dbg.h"
69 #define TOKENIZE_ERROR -1
70 #define TOKENIZE_ERROR_REPORT -2
72 #define MAX_INSN_FIXUPS 2
73 #define MAX_INSN_ARGS 5
78 bfd_reloc_code_real_type reloc;
85 struct alpha_fixup fixups[MAX_INSN_FIXUPS];
86 unsigned sequence[MAX_INSN_FIXUPS];
107 void (*emit) PARAMS ((const expressionS *, int, const PTR));
109 enum alpha_macro_arg argsets[16];
112 /* Extra expression types. */
114 #define O_pregister O_md1 /* O_register, in parentheses */
115 #define O_cpregister O_md2 /* + a leading comma */
118 /* Note, the alpha_reloc_op table below depends on the ordering
119 of O_literal .. O_gprelow. */
120 #define O_literal O_md3 /* !literal relocation */
121 #define O_lituse_base O_md4 /* !lituse_base relocation */
122 #define O_lituse_bytoff O_md5 /* !lituse_bytoff relocation */
123 #define O_lituse_jsr O_md6 /* !lituse_jsr relocation */
124 #define O_gpdisp O_md7 /* !gpdisp relocation */
125 #define O_gprelhigh O_md8 /* !gprelhigh relocation */
126 #define O_gprellow O_md9 /* !gprellow relocation */
128 #define USER_RELOC_P(R) ((R) >= O_literal && (R) <= O_gprellow)
131 /* Macros for extracting the type and number of encoded register tokens */
133 #define is_ir_num(x) (((x) & 32) == 0)
134 #define is_fpr_num(x) (((x) & 32) != 0)
135 #define regno(x) ((x) & 31)
137 /* Something odd inherited from the old assembler */
139 #define note_gpreg(R) (alpha_gprmask |= (1 << (R)))
140 #define note_fpreg(R) (alpha_fprmask |= (1 << (R)))
142 /* Predicates for 16- and 32-bit ranges */
143 /* XXX: The non-shift version appears to trigger a compiler bug when
144 cross-assembling from x86 w/ gcc 2.7.2. */
147 #define range_signed_16(x) \
148 (((offsetT) (x) >> 15) == 0 || ((offsetT) (x) >> 15) == -1)
149 #define range_signed_32(x) \
150 (((offsetT) (x) >> 31) == 0 || ((offsetT) (x) >> 31) == -1)
152 #define range_signed_16(x) ((offsetT) (x) >= -(offsetT)0x8000 && \
153 (offsetT) (x) <= (offsetT)0x7FFF)
154 #define range_signed_32(x) ((offsetT) (x) >= -(offsetT)0x80000000 && \
155 (offsetT) (x) <= (offsetT)0x7FFFFFFF)
158 /* Macros for sign extending from 16- and 32-bits. */
159 /* XXX: The cast macros will work on all the systems that I care about,
160 but really a predicate should be found to use the non-cast forms. */
163 #define sign_extend_16(x) ((short) (x))
164 #define sign_extend_32(x) ((int) (x))
166 #define sign_extend_16(x) ((offsetT) (((x) & 0xFFFF) ^ 0x8000) - 0x8000)
167 #define sign_extend_32(x) ((offsetT) (((x) & 0xFFFFFFFF) \
168 ^ 0x80000000) - 0x80000000)
171 /* Macros to build tokens */
173 #define set_tok_reg(t, r) (memset(&(t), 0, sizeof (t)), \
174 (t).X_op = O_register, \
175 (t).X_add_number = (r))
176 #define set_tok_preg(t, r) (memset(&(t), 0, sizeof (t)), \
177 (t).X_op = O_pregister, \
178 (t).X_add_number = (r))
179 #define set_tok_cpreg(t, r) (memset(&(t), 0, sizeof (t)), \
180 (t).X_op = O_cpregister, \
181 (t).X_add_number = (r))
182 #define set_tok_freg(t, r) (memset(&(t), 0, sizeof (t)), \
183 (t).X_op = O_register, \
184 (t).X_add_number = (r)+32)
185 #define set_tok_sym(t, s, a) (memset(&(t), 0, sizeof (t)), \
186 (t).X_op = O_symbol, \
187 (t).X_add_symbol = (s), \
188 (t).X_add_number = (a))
189 #define set_tok_const(t, n) (memset(&(t), 0, sizeof (t)), \
190 (t).X_op = O_constant, \
191 (t).X_add_number = (n))
194 /* Prototypes for all local functions */
196 static int tokenize_arguments PARAMS ((char *, expressionS *, int));
197 static const struct alpha_opcode *find_opcode_match
198 PARAMS ((const struct alpha_opcode *, const expressionS *, int *, int *));
199 static const struct alpha_macro *find_macro_match
200 PARAMS ((const struct alpha_macro *, const expressionS *, int *));
201 static unsigned insert_operand
202 PARAMS ((unsigned, const struct alpha_operand *, offsetT, char *, unsigned));
203 static void assemble_insn
204 PARAMS ((const struct alpha_opcode *, const expressionS *, int,
205 struct alpha_insn *));
206 static void emit_insn PARAMS ((struct alpha_insn *));
207 static void assemble_tokens_to_insn
208 PARAMS ((const char *, const expressionS *, int, struct alpha_insn *));
209 static void assemble_tokens
210 PARAMS ((const char *, const expressionS *, int, int));
212 static int load_expression
213 PARAMS ((int, const expressionS *, int *, expressionS *,
214 const expressionS *));
216 static void emit_ldgp PARAMS ((const expressionS *, int, const PTR));
217 static void emit_division PARAMS ((const expressionS *, int, const PTR));
218 static void emit_lda PARAMS ((const expressionS *, int, const PTR));
219 static void emit_ldah PARAMS ((const expressionS *, int, const PTR));
220 static void emit_ir_load PARAMS ((const expressionS *, int, const PTR));
221 static void emit_loadstore PARAMS ((const expressionS *, int, const PTR));
222 static void emit_jsrjmp PARAMS ((const expressionS *, int, const PTR));
223 static void emit_ldX PARAMS ((const expressionS *, int, const PTR));
224 static void emit_ldXu PARAMS ((const expressionS *, int, const PTR));
225 static void emit_uldX PARAMS ((const expressionS *, int, const PTR));
226 static void emit_uldXu PARAMS ((const expressionS *, int, const PTR));
227 static void emit_ldil PARAMS ((const expressionS *, int, const PTR));
228 static void emit_stX PARAMS ((const expressionS *, int, const PTR));
229 static void emit_ustX PARAMS ((const expressionS *, int, const PTR));
230 static void emit_sextX PARAMS ((const expressionS *, int, const PTR));
231 static void emit_retjcr PARAMS ((const expressionS *, int, const PTR));
233 static void s_alpha_text PARAMS ((int));
234 static void s_alpha_data PARAMS ((int));
236 static void s_alpha_comm PARAMS ((int));
237 static void s_alpha_rdata PARAMS ((int));
240 static void s_alpha_sdata PARAMS ((int));
243 static void s_alpha_section PARAMS ((int));
244 static void s_alpha_ent PARAMS ((int));
245 static void s_alpha_end PARAMS ((int));
246 static void s_alpha_mask PARAMS ((int));
247 static void s_alpha_frame PARAMS ((int));
248 static void s_alpha_prologue PARAMS ((int));
249 static void s_alpha_file PARAMS ((int));
250 static void s_alpha_loc PARAMS ((int));
251 static void s_alpha_stab PARAMS ((int));
252 static void s_alpha_coff_wrapper PARAMS ((int));
255 static void s_alpha_section PARAMS ((int));
257 static void s_alpha_gprel32 PARAMS ((int));
258 static void s_alpha_float_cons PARAMS ((int));
259 static void s_alpha_proc PARAMS ((int));
260 static void s_alpha_set PARAMS ((int));
261 static void s_alpha_base PARAMS ((int));
262 static void s_alpha_align PARAMS ((int));
263 static void s_alpha_stringer PARAMS ((int));
264 static void s_alpha_space PARAMS ((int));
266 static void create_literal_section PARAMS ((const char *, segT *, symbolS **));
268 static void select_gp_value PARAMS ((void));
270 static void alpha_align PARAMS ((int, char *, symbolS *, int));
273 static void alpha_adjust_symtab_relocs PARAMS ((bfd *, asection *, PTR));
277 /* Generic assembler global variables which must be defined by all
280 /* Characters which always start a comment. */
281 const char comment_chars[] = "#";
283 /* Characters which start a comment at the beginning of a line. */
284 const char line_comment_chars[] = "#";
286 /* Characters which may be used to separate multiple commands on a
288 const char line_separator_chars[] = ";";
290 /* Characters which are used to indicate an exponent in a floating
292 const char EXP_CHARS[] = "eE";
294 /* Characters which mean that a number is a floating point constant,
297 const char FLT_CHARS[] = "dD";
299 /* XXX: Do all of these really get used on the alpha?? */
300 char FLT_CHARS[] = "rRsSfFdDxXpP";
304 const char *md_shortopts = "Fm:g+1h:HG:";
306 const char *md_shortopts = "Fm:gG:";
309 struct option md_longopts[] = {
310 #define OPTION_32ADDR (OPTION_MD_BASE)
311 { "32addr", no_argument, NULL, OPTION_32ADDR },
312 #define OPTION_RELAX (OPTION_32ADDR+1)
313 { "relax", no_argument, NULL, OPTION_RELAX },
315 #define OPTION_MDEBUG (OPTION_RELAX+1)
316 #define OPTION_NO_MDEBUG (OPTION_MDEBUG+1)
317 { "mdebug", no_argument, NULL, OPTION_MDEBUG },
318 { "no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG },
320 { NULL, no_argument, NULL, 0 }
323 size_t md_longopts_size = sizeof (md_longopts);
328 #define AXP_REG_R16 16
329 #define AXP_REG_R17 17
331 #define AXP_REG_T9 22
333 #define AXP_REG_T10 23
335 #define AXP_REG_T11 24
337 #define AXP_REG_T12 25
338 #define AXP_REG_AI 25
340 #define AXP_REG_FP 29
343 #define AXP_REG_GP AXP_REG_PV
344 #endif /* OBJ_EVAX */
346 /* The cpu for which we are generating code */
347 static unsigned alpha_target = AXP_OPCODE_BASE;
348 static const char *alpha_target_name = "<all>";
350 /* The hash table of instruction opcodes */
351 static struct hash_control *alpha_opcode_hash;
353 /* The hash table of macro opcodes */
354 static struct hash_control *alpha_macro_hash;
357 /* The $gp relocation symbol */
358 static symbolS *alpha_gp_symbol;
360 /* XXX: what is this, and why is it exported? */
361 valueT alpha_gp_value;
364 /* The current $gp register */
365 static int alpha_gp_register = AXP_REG_GP;
367 /* A table of the register symbols */
368 static symbolS *alpha_register_table[64];
370 /* Constant sections, or sections of constants */
372 static segT alpha_lita_section;
373 static segT alpha_lit4_section;
376 static segT alpha_link_section;
377 static segT alpha_ctors_section;
378 static segT alpha_dtors_section;
380 static segT alpha_lit8_section;
382 /* Symbols referring to said sections. */
384 static symbolS *alpha_lita_symbol;
385 static symbolS *alpha_lit4_symbol;
388 static symbolS *alpha_link_symbol;
389 static symbolS *alpha_ctors_symbol;
390 static symbolS *alpha_dtors_symbol;
392 static symbolS *alpha_lit8_symbol;
394 /* Literal for .litX+0x8000 within .lita */
396 static offsetT alpha_lit4_literal;
397 static offsetT alpha_lit8_literal;
401 /* The active .ent symbol. */
402 static symbolS *alpha_cur_ent_sym;
405 /* Is the assembler not allowed to use $at? */
406 static int alpha_noat_on = 0;
408 /* Are macros enabled? */
409 static int alpha_macros_on = 1;
411 /* Are floats disabled? */
412 static int alpha_nofloats_on = 0;
414 /* Are addresses 32 bit? */
415 static int alpha_addr32_on = 0;
417 /* Symbol labelling the current insn. When the Alpha gas sees
420 and the section happens to not be on an eight byte boundary, it
421 will align both the symbol and the .quad to an eight byte boundary. */
422 static symbolS *alpha_insn_label;
424 /* Whether we should automatically align data generation pseudo-ops.
425 .align 0 will turn this off. */
426 static int alpha_auto_align_on = 1;
428 /* The known current alignment of the current section. */
429 static int alpha_current_align;
431 /* These are exported to ECOFF code. */
432 unsigned long alpha_gprmask, alpha_fprmask;
434 /* Whether the debugging option was seen. */
435 static int alpha_debug;
438 /* Whether we are emitting an mdebug section. */
439 int alpha_flag_mdebug = -1;
442 /* Don't fully resolve relocations, allowing code movement in the linker. */
443 static int alpha_flag_relax;
445 /* What value to give to bfd_set_gp_size. */
446 static int g_switch_value = 8;
449 /* Collect information about current procedure here. */
451 symbolS *symbol; /* proc pdesc symbol */
453 int framereg; /* register for frame pointer */
454 int framesize; /* size of frame */
464 static int alpha_flag_hash_long_names = 0; /* -+ */
465 static int alpha_flag_show_after_trunc = 0; /* -H */
467 /* If the -+ switch is given, then a hash is appended to any name that is
468 * longer than 64 characters, else longer symbol names are truncated.
474 /* A table to map the spelling of a relocation operand into an appropriate
475 bfd_reloc_code_real_type type. The table is assumed to be ordered such
476 that op-O_literal indexes into it. */
478 #define ALPHA_RELOC_TABLE(op) \
479 &alpha_reloc_op[ ((!USER_RELOC_P (op)) \
481 : (int) (op) - (int)O_literal) ]
483 #define LITUSE_BASE 1
484 #define LITUSE_BYTOFF 2
487 static const struct alpha_reloc_op_tag {
488 const char *name; /* string to lookup */
489 size_t length; /* size of the string */
490 bfd_reloc_code_real_type reloc; /* relocation before frob */
491 operatorT op; /* which operator to use */
492 int lituse; /* addened to specify lituse */
493 } alpha_reloc_op[] = {
496 "literal", /* name */
497 sizeof ("literal")-1, /* length */
498 BFD_RELOC_ALPHA_USER_LITERAL, /* reloc */
504 "lituse_base", /* name */
505 sizeof ("lituse_base")-1, /* length */
506 BFD_RELOC_ALPHA_USER_LITUSE_BASE, /* reloc */
507 O_lituse_base, /* op */
508 LITUSE_BASE, /* lituse */
512 "lituse_bytoff", /* name */
513 sizeof ("lituse_bytoff")-1, /* length */
514 BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF, /* reloc */
515 O_lituse_bytoff, /* op */
516 LITUSE_BYTOFF, /* lituse */
520 "lituse_jsr", /* name */
521 sizeof ("lituse_jsr")-1, /* length */
522 BFD_RELOC_ALPHA_USER_LITUSE_JSR, /* reloc */
523 O_lituse_jsr, /* op */
524 LITUSE_JSR, /* lituse */
529 sizeof ("gpdisp")-1, /* length */
530 BFD_RELOC_ALPHA_USER_GPDISP, /* reloc */
536 "gprelhigh", /* name */
537 sizeof ("gprelhigh")-1, /* length */
538 BFD_RELOC_ALPHA_USER_GPRELHIGH, /* reloc */
539 O_gprelhigh, /* op */
544 "gprellow", /* name */
545 sizeof ("gprellow")-1, /* length */
546 BFD_RELOC_ALPHA_USER_GPRELLOW, /* reloc */
552 static const int alpha_num_reloc_op
553 = sizeof (alpha_reloc_op) / sizeof (*alpha_reloc_op);
555 /* Maximum # digits needed to hold the largest sequence # */
556 #define ALPHA_RELOC_DIGITS 25
558 /* Whether a sequence number is valid. */
559 #define ALPHA_RELOC_SEQUENCE_OK(X) ((X) > 0 && ((unsigned) (X)) == (X))
561 /* Structure to hold explict sequence information. */
562 struct alpha_literal_tag
564 fixS *lituse; /* head of linked list of !literals */
565 segT segment; /* segment relocs are in or undefined_section*/
566 int multi_section_p; /* True if more than one section was used */
567 unsigned sequence; /* sequence # */
568 unsigned n_literals; /* # of literals */
569 unsigned n_lituses; /* # of lituses */
570 char string[1]; /* printable form of sequence to hash with */
573 /* Hash table to link up literals with the appropriate lituse */
574 static struct hash_control *alpha_literal_hash;
577 /* A table of CPU names and opcode sets. */
579 static const struct cpu_type
585 /* Ad hoc convention: cpu number gets palcode, process code doesn't.
586 This supports usage under DU 4.0b that does ".arch ev4", and
587 usage in MILO that does -m21064. Probably something more
588 specific like -m21064-pal should be used, but oh well. */
590 { "21064", AXP_OPCODE_BASE|AXP_OPCODE_EV4 },
591 { "21064a", AXP_OPCODE_BASE|AXP_OPCODE_EV4 },
592 { "21066", AXP_OPCODE_BASE|AXP_OPCODE_EV4 },
593 { "21068", AXP_OPCODE_BASE|AXP_OPCODE_EV4 },
594 { "21164", AXP_OPCODE_BASE|AXP_OPCODE_EV5 },
595 { "21164a", AXP_OPCODE_BASE|AXP_OPCODE_EV5|AXP_OPCODE_BWX },
596 { "21164pc", (AXP_OPCODE_BASE|AXP_OPCODE_EV5|AXP_OPCODE_BWX
598 { "21264", (AXP_OPCODE_BASE|AXP_OPCODE_EV6|AXP_OPCODE_BWX
599 |AXP_OPCODE_MAX|AXP_OPCODE_CIX) },
601 { "ev4", AXP_OPCODE_BASE },
602 { "ev45", AXP_OPCODE_BASE },
603 { "lca45", AXP_OPCODE_BASE },
604 { "ev5", AXP_OPCODE_BASE },
605 { "ev56", AXP_OPCODE_BASE|AXP_OPCODE_BWX },
606 { "pca56", AXP_OPCODE_BASE|AXP_OPCODE_BWX|AXP_OPCODE_MAX },
607 { "ev6", AXP_OPCODE_BASE|AXP_OPCODE_BWX|AXP_OPCODE_MAX|AXP_OPCODE_CIX },
609 { "all", AXP_OPCODE_BASE },
613 /* The macro table */
615 static const struct alpha_macro alpha_macros[] = {
616 /* Load/Store macros */
617 { "lda", emit_lda, NULL,
618 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_LITERAL, MACRO_BASE, MACRO_EOA } },
619 { "ldah", emit_ldah, NULL,
620 { MACRO_IR, MACRO_EXP, MACRO_EOA } },
622 { "ldl", emit_ir_load, "ldl",
623 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
624 { "ldl_l", emit_ir_load, "ldl_l",
625 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
626 { "ldq", emit_ir_load, "ldq",
627 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_LITERAL, MACRO_EOA } },
628 { "ldq_l", emit_ir_load, "ldq_l",
629 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
630 { "ldq_u", emit_ir_load, "ldq_u",
631 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
632 { "ldf", emit_loadstore, "ldf",
633 { MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
634 { "ldg", emit_loadstore, "ldg",
635 { MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
636 { "lds", emit_loadstore, "lds",
637 { MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
638 { "ldt", emit_loadstore, "ldt",
639 { MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
641 { "ldb", emit_ldX, (PTR)0,
642 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
643 { "ldbu", emit_ldXu, (PTR)0,
644 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
645 { "ldw", emit_ldX, (PTR)1,
646 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
647 { "ldwu", emit_ldXu, (PTR)1,
648 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
650 { "uldw", emit_uldX, (PTR)1,
651 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
652 { "uldwu", emit_uldXu, (PTR)1,
653 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
654 { "uldl", emit_uldX, (PTR)2,
655 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
656 { "uldlu", emit_uldXu, (PTR)2,
657 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
658 { "uldq", emit_uldXu, (PTR)3,
659 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
661 { "ldgp", emit_ldgp, NULL,
662 { MACRO_IR, MACRO_EXP, MACRO_PIR, MACRO_EOA } },
664 { "ldi", emit_lda, NULL,
665 { MACRO_IR, MACRO_EXP, MACRO_EOA } },
666 { "ldil", emit_ldil, NULL,
667 { MACRO_IR, MACRO_EXP, MACRO_EOA } },
668 { "ldiq", emit_lda, NULL,
669 { MACRO_IR, MACRO_EXP, MACRO_EOA } },
671 { "ldif" emit_ldiq, NULL,
672 { MACRO_FPR, MACRO_EXP, MACRO_EOA } },
673 { "ldid" emit_ldiq, NULL,
674 { MACRO_FPR, MACRO_EXP, MACRO_EOA } },
675 { "ldig" emit_ldiq, NULL,
676 { MACRO_FPR, MACRO_EXP, MACRO_EOA } },
677 { "ldis" emit_ldiq, NULL,
678 { MACRO_FPR, MACRO_EXP, MACRO_EOA } },
679 { "ldit" emit_ldiq, NULL,
680 { MACRO_FPR, MACRO_EXP, MACRO_EOA } },
683 { "stl", emit_loadstore, "stl",
684 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
685 { "stl_c", emit_loadstore, "stl_c",
686 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
687 { "stq", emit_loadstore, "stq",
688 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
689 { "stq_c", emit_loadstore, "stq_c",
690 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
691 { "stq_u", emit_loadstore, "stq_u",
692 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
693 { "stf", emit_loadstore, "stf",
694 { MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
695 { "stg", emit_loadstore, "stg",
696 { MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
697 { "sts", emit_loadstore, "sts",
698 { MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
699 { "stt", emit_loadstore, "stt",
700 { MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
702 { "stb", emit_stX, (PTR)0,
703 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
704 { "stw", emit_stX, (PTR)1,
705 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
706 { "ustw", emit_ustX, (PTR)1,
707 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
708 { "ustl", emit_ustX, (PTR)2,
709 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
710 { "ustq", emit_ustX, (PTR)3,
711 { MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
713 /* Arithmetic macros */
715 { "absl" emit_absl, 1, { IR } },
716 { "absl" emit_absl, 2, { IR, IR } },
717 { "absl" emit_absl, 2, { EXP, IR } },
718 { "absq" emit_absq, 1, { IR } },
719 { "absq" emit_absq, 2, { IR, IR } },
720 { "absq" emit_absq, 2, { EXP, IR } },
723 { "sextb", emit_sextX, (PTR)0,
724 { MACRO_IR, MACRO_IR, MACRO_EOA,
726 /* MACRO_EXP, MACRO_IR, MACRO_EOA */ } },
727 { "sextw", emit_sextX, (PTR)1,
728 { MACRO_IR, MACRO_IR, MACRO_EOA,
730 /* MACRO_EXP, MACRO_IR, MACRO_EOA */ } },
732 { "divl", emit_division, "__divl",
733 { MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
734 MACRO_IR, MACRO_IR, MACRO_EOA,
735 /* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
736 MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
737 { "divlu", emit_division, "__divlu",
738 { MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
739 MACRO_IR, MACRO_IR, MACRO_EOA,
740 /* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
741 MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
742 { "divq", emit_division, "__divq",
743 { MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
744 MACRO_IR, MACRO_IR, MACRO_EOA,
745 /* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
746 MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
747 { "divqu", emit_division, "__divqu",
748 { MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
749 MACRO_IR, MACRO_IR, MACRO_EOA,
750 /* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
751 MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
752 { "reml", emit_division, "__reml",
753 { MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
754 MACRO_IR, MACRO_IR, MACRO_EOA,
755 /* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
756 MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
757 { "remlu", emit_division, "__remlu",
758 { MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
759 MACRO_IR, MACRO_IR, MACRO_EOA,
760 /* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
761 MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
762 { "remq", emit_division, "__remq",
763 { MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
764 MACRO_IR, MACRO_IR, MACRO_EOA,
765 /* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
766 MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
767 { "remqu", emit_division, "__remqu",
768 { MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
769 MACRO_IR, MACRO_IR, MACRO_EOA,
770 /* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
771 MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
773 { "jsr", emit_jsrjmp, "jsr",
774 { MACRO_PIR, MACRO_EXP, MACRO_JSR, MACRO_EOA,
775 MACRO_PIR, MACRO_JSR, MACRO_EOA,
776 MACRO_IR, MACRO_EXP, MACRO_JSR, MACRO_EOA,
777 MACRO_EXP, MACRO_JSR, MACRO_EOA } },
778 { "jmp", emit_jsrjmp, "jmp",
779 { MACRO_PIR, MACRO_EXP, MACRO_JSR, MACRO_EOA,
780 MACRO_PIR, MACRO_JSR, MACRO_EOA,
781 MACRO_IR, MACRO_EXP, MACRO_JSR, MACRO_EOA,
782 MACRO_EXP, MACRO_JSR, MACRO_EOA } },
783 { "ret", emit_retjcr, "ret",
784 { MACRO_IR, MACRO_EXP, MACRO_EOA,
786 MACRO_PIR, MACRO_EXP, MACRO_EOA,
787 MACRO_PIR, MACRO_EOA,
788 MACRO_EXP, MACRO_EOA,
790 { "jcr", emit_retjcr, "jcr",
791 { MACRO_IR, MACRO_EXP, MACRO_EOA,
793 MACRO_PIR, MACRO_EXP, MACRO_EOA,
794 MACRO_PIR, MACRO_EOA,
795 MACRO_EXP, MACRO_EOA,
797 { "jsr_coroutine", emit_retjcr, "jcr",
798 { MACRO_IR, MACRO_EXP, MACRO_EOA,
800 MACRO_PIR, MACRO_EXP, MACRO_EOA,
801 MACRO_PIR, MACRO_EOA,
802 MACRO_EXP, MACRO_EOA,
806 static const unsigned int alpha_num_macros
807 = sizeof (alpha_macros) / sizeof (*alpha_macros);
809 /* Public interface functions */
811 /* This function is called once, at assembler startup time. It sets
812 up all the tables, etc. that the MD part of the assembler will
813 need, that can be determined before arguments are parsed. */
820 /* Verify that X_op field is wide enough. */
824 assert (e.X_op == O_max);
827 /* Create the opcode hash table */
829 alpha_opcode_hash = hash_new ();
830 for (i = 0; i < alpha_num_opcodes; )
832 const char *name, *retval, *slash;
834 name = alpha_opcodes[i].name;
835 retval = hash_insert (alpha_opcode_hash, name, (PTR)&alpha_opcodes[i]);
837 as_fatal (_("internal error: can't hash opcode `%s': %s"), name, retval);
839 /* Some opcodes include modifiers of various sorts with a "/mod"
840 syntax, like the architecture manual suggests. However, for
841 use with gcc at least, we also need access to those same opcodes
844 if ((slash = strchr (name, '/')) != NULL)
846 char *p = xmalloc (strlen (name));
847 memcpy (p, name, slash - name);
848 strcpy (p + (slash - name), slash + 1);
850 (void)hash_insert(alpha_opcode_hash, p, (PTR)&alpha_opcodes[i]);
851 /* Ignore failures -- the opcode table does duplicate some
852 variants in different forms, like "hw_stq" and "hw_st/q". */
855 while (++i < alpha_num_opcodes
856 && (alpha_opcodes[i].name == name
857 || !strcmp (alpha_opcodes[i].name, name)))
861 /* Create the macro hash table */
863 alpha_macro_hash = hash_new ();
864 for (i = 0; i < alpha_num_macros; )
866 const char *name, *retval;
868 name = alpha_macros[i].name;
869 retval = hash_insert (alpha_macro_hash, name, (PTR)&alpha_macros[i]);
871 as_fatal (_("internal error: can't hash macro `%s': %s"), name, retval);
873 while (++i < alpha_num_macros
874 && (alpha_macros[i].name == name
875 || !strcmp (alpha_macros[i].name, name)))
879 /* Construct symbols for each of the registers */
881 for (i = 0; i < 32; ++i)
884 sprintf (name, "$%d", i);
885 alpha_register_table[i] = symbol_create(name, reg_section, i,
891 sprintf (name, "$f%d", i-32);
892 alpha_register_table[i] = symbol_create(name, reg_section, i,
896 /* Create the special symbols and sections we'll be using */
898 /* So .sbss will get used for tiny objects. */
899 bfd_set_gp_size (stdoutput, g_switch_value);
902 create_literal_section (".lita", &alpha_lita_section, &alpha_lita_symbol);
904 /* For handling the GP, create a symbol that won't be output in the
905 symbol table. We'll edit it out of relocs later. */
906 alpha_gp_symbol = symbol_create ("<GP value>", alpha_lita_section, 0x8000,
911 create_literal_section (".link", &alpha_link_section, &alpha_link_symbol);
917 segT sec = subseg_new(".mdebug", (subsegT)0);
918 bfd_set_section_flags(stdoutput, sec, SEC_HAS_CONTENTS|SEC_READONLY);
919 bfd_set_section_alignment(stdoutput, sec, 3);
923 subseg_set(text_section, 0);
926 /* Create literal lookup hash table. */
927 alpha_literal_hash = hash_new();
931 /* The public interface to the instruction assembler. */
937 char opname[32]; /* current maximum is 13 */
938 expressionS tok[MAX_INSN_ARGS];
942 /* split off the opcode */
943 opnamelen = strspn (str, "abcdefghijklmnopqrstuvwxyz_/46819");
944 trunclen = (opnamelen < sizeof (opname) - 1
946 : sizeof (opname) - 1);
947 memcpy (opname, str, trunclen);
948 opname[trunclen] = '\0';
950 /* tokenize the rest of the line */
951 if ((ntok = tokenize_arguments (str + opnamelen, tok, MAX_INSN_ARGS)) < 0)
953 if (ntok != TOKENIZE_ERROR_REPORT)
954 as_bad (_("syntax error"));
960 assemble_tokens (opname, tok, ntok, alpha_macros_on);
963 /* Round up a section's size to the appropriate boundary. */
966 md_section_align (seg, size)
970 int align = bfd_get_section_alignment(stdoutput, seg);
971 valueT mask = ((valueT)1 << align) - 1;
973 return (size + mask) & ~mask;
976 /* Turn a string in input_line_pointer into a floating point constant
977 of type TYPE, and store the appropriate bytes in *LITP. The number
978 of LITTLENUMS emitted is stored in *SIZEP. An error message is
979 returned, or NULL on OK. */
981 /* Equal to MAX_PRECISION in atof-ieee.c */
982 #define MAX_LITTLENUMS 6
984 extern char *vax_md_atof PARAMS ((int, char *, int *));
987 md_atof (type, litP, sizeP)
993 LITTLENUM_TYPE words[MAX_LITTLENUMS];
994 LITTLENUM_TYPE *wordP;
1001 /* VAX md_atof doesn't like "G" for some reason. */
1005 return vax_md_atof (type, litP, sizeP);
1028 return _("Bad call to MD_ATOF()");
1030 t = atof_ieee (input_line_pointer, type, words);
1032 input_line_pointer = t;
1033 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1035 for (wordP = words + prec - 1; prec--;)
1037 md_number_to_chars (litP, (long) (*wordP--), sizeof (LITTLENUM_TYPE));
1038 litP += sizeof (LITTLENUM_TYPE);
1044 /* Take care of the target-specific command-line options. */
1047 md_parse_option (c, arg)
1054 alpha_nofloats_on = 1;
1058 alpha_addr32_on = 1;
1066 g_switch_value = atoi(arg);
1071 const struct cpu_type *p;
1072 for (p = cpu_types; p->name; ++p)
1073 if (strcmp(arg, p->name) == 0)
1075 alpha_target_name = p->name, alpha_target = p->flags;
1078 as_warn(_("Unknown CPU identifier `%s'"), arg);
1084 case '+': /* For g++. Hash any name > 63 chars long. */
1085 alpha_flag_hash_long_names = 1;
1088 case 'H': /* Show new symbol after hash truncation */
1089 alpha_flag_show_after_trunc = 1;
1092 case 'h': /* for gnu-c/vax compatibility. */
1097 alpha_flag_relax = 1;
1102 alpha_flag_mdebug = 1;
1104 case OPTION_NO_MDEBUG:
1105 alpha_flag_mdebug = 0;
1116 /* Print a description of the command-line options that we accept. */
1119 md_show_usage (stream)
1124 -32addr treat addresses as 32-bit values\n\
1125 -F lack floating point instructions support\n\
1126 -mev4 | -mev45 | -mev5 | -mev56 | -mpca56 | -mev6 | -mall\n\
1127 specify variant of Alpha architecture\n\
1128 -m21064 | -m21066 | -m21164 | -m21164a | -m21164pc | -m21264\n\
1129 these variants include PALcode opcodes\n"),
1134 -+ hash encode (don't truncate) names longer than 64 characters\n\
1135 -H show new symbol after hash truncation\n"),
1140 /* Decide from what point a pc-relative relocation is relative to,
1141 relative to the pc-relative fixup. Er, relatively speaking. */
1144 md_pcrel_from (fixP)
1147 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
1148 switch (fixP->fx_r_type)
1150 case BFD_RELOC_ALPHA_GPDISP:
1151 case BFD_RELOC_ALPHA_GPDISP_HI16:
1152 case BFD_RELOC_ALPHA_GPDISP_LO16:
1155 return fixP->fx_size + addr;
1159 /* Attempt to simplify or even eliminate a fixup. The return value is
1160 ignored; perhaps it was once meaningful, but now it is historical.
1161 To indicate that a fixup has been eliminated, set fixP->fx_done.
1163 For ELF, here it is that we transform the GPDISP_HI16 reloc we used
1164 internally into the GPDISP reloc used externally. We had to do
1165 this so that we'd have the GPDISP_LO16 reloc as a tag to compute
1166 the distance to the "lda" instruction for setting the addend to
1170 md_apply_fix (fixP, valueP)
1174 char * const fixpos = fixP->fx_frag->fr_literal + fixP->fx_where;
1175 valueT value = *valueP;
1176 unsigned image, size;
1178 switch (fixP->fx_r_type)
1180 /* The GPDISP relocations are processed internally with a symbol
1181 referring to the current function; we need to drop in a value
1182 which, when added to the address of the start of the function,
1183 gives the desired GP. */
1184 case BFD_RELOC_ALPHA_GPDISP_HI16:
1186 fixS *next = fixP->fx_next;
1187 assert (next->fx_r_type == BFD_RELOC_ALPHA_GPDISP_LO16);
1189 fixP->fx_offset = (next->fx_frag->fr_address + next->fx_where
1190 - fixP->fx_frag->fr_address - fixP->fx_where);
1192 value = (value - sign_extend_16 (value)) >> 16;
1195 fixP->fx_r_type = BFD_RELOC_ALPHA_GPDISP;
1199 case BFD_RELOC_ALPHA_GPDISP_LO16:
1200 value = sign_extend_16 (value);
1201 fixP->fx_offset = 0;
1207 fixP->fx_addsy = section_symbol (now_seg);
1208 md_number_to_chars (fixpos, value, 2);
1213 fixP->fx_r_type = BFD_RELOC_16_PCREL;
1218 fixP->fx_r_type = BFD_RELOC_32_PCREL;
1223 fixP->fx_r_type = BFD_RELOC_64_PCREL;
1226 if (fixP->fx_pcrel == 0 && fixP->fx_addsy == 0)
1228 md_number_to_chars (fixpos, value, size);
1234 case BFD_RELOC_GPREL32:
1235 assert (fixP->fx_subsy == alpha_gp_symbol);
1237 /* FIXME: inherited this obliviousness of `value' -- why? */
1238 md_number_to_chars (fixpos, -alpha_gp_value, 4);
1242 case BFD_RELOC_GPREL32:
1246 case BFD_RELOC_23_PCREL_S2:
1247 if (fixP->fx_pcrel == 0 && fixP->fx_addsy == 0)
1249 image = bfd_getl32(fixpos);
1250 image = (image & ~0x1FFFFF) | ((value >> 2) & 0x1FFFFF);
1255 case BFD_RELOC_ALPHA_HINT:
1256 if (fixP->fx_pcrel == 0 && fixP->fx_addsy == 0)
1258 image = bfd_getl32(fixpos);
1259 image = (image & ~0x3FFF) | ((value >> 2) & 0x3FFF);
1265 case BFD_RELOC_ALPHA_LITERAL:
1266 md_number_to_chars (fixpos, value, 2);
1269 case BFD_RELOC_ALPHA_LITUSE:
1273 case BFD_RELOC_ALPHA_ELF_LITERAL:
1274 case BFD_RELOC_ALPHA_LITUSE:
1278 case BFD_RELOC_ALPHA_LINKAGE:
1279 case BFD_RELOC_ALPHA_CODEADDR:
1284 case BFD_RELOC_ALPHA_USER_LITERAL:
1285 case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
1286 case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
1287 case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
1290 case BFD_RELOC_ALPHA_USER_GPDISP:
1291 case BFD_RELOC_ALPHA_USER_GPRELHIGH:
1292 case BFD_RELOC_ALPHA_USER_GPRELLOW:
1298 const struct alpha_operand *operand;
1300 if ((int)fixP->fx_r_type >= 0)
1301 as_fatal (_("unhandled relocation type %s"),
1302 bfd_get_reloc_code_name (fixP->fx_r_type));
1304 assert (-(int)fixP->fx_r_type < (int)alpha_num_operands);
1305 operand = &alpha_operands[-(int)fixP->fx_r_type];
1307 /* The rest of these fixups only exist internally during symbol
1308 resolution and have no representation in the object file.
1309 Therefore they must be completely resolved as constants. */
1311 if (fixP->fx_addsy != 0
1312 && S_GET_SEGMENT (fixP->fx_addsy) != absolute_section)
1313 as_bad_where (fixP->fx_file, fixP->fx_line,
1314 _("non-absolute expression in constant field"));
1316 image = bfd_getl32(fixpos);
1317 image = insert_operand(image, operand, (offsetT)value,
1318 fixP->fx_file, fixP->fx_line);
1323 if (fixP->fx_addsy != 0 || fixP->fx_pcrel != 0)
1327 as_warn_where(fixP->fx_file, fixP->fx_line,
1328 _("type %d reloc done?\n"), (int)fixP->fx_r_type);
1333 md_number_to_chars(fixpos, image, 4);
1341 * Look for a register name in the given symbol.
1345 md_undefined_symbol(name)
1350 int is_float = 0, num;
1355 if (name[1] == 'p' && name[2] == '\0')
1356 return alpha_register_table[AXP_REG_FP];
1361 if (!isdigit(*++name))
1365 case '0': case '1': case '2': case '3': case '4':
1366 case '5': case '6': case '7': case '8': case '9':
1367 if (name[1] == '\0')
1368 num = name[0] - '0';
1369 else if (name[0] != '0' && isdigit(name[1]) && name[2] == '\0')
1371 num = (name[0] - '0') * 10 + name[1] - '0';
1378 if (!alpha_noat_on && (num + is_float) == AXP_REG_AT)
1379 as_warn(_("Used $at without \".set noat\""));
1380 return alpha_register_table[num + is_float];
1383 if (name[1] == 't' && name[2] == '\0')
1386 as_warn(_("Used $at without \".set noat\""));
1387 return alpha_register_table[AXP_REG_AT];
1392 if (name[1] == 'p' && name[2] == '\0')
1393 return alpha_register_table[alpha_gp_register];
1397 if (name[1] == 'p' && name[2] == '\0')
1398 return alpha_register_table[AXP_REG_SP];
1406 /* @@@ Magic ECOFF bits. */
1409 alpha_frob_ecoff_data ()
1412 /* $zero and $f31 are read-only */
1413 alpha_gprmask &= ~1;
1414 alpha_fprmask &= ~1;
1418 /* Hook to remember a recently defined label so that the auto-align
1419 code can adjust the symbol after we know what alignment will be
1423 alpha_define_label (sym)
1426 alpha_insn_label = sym;
1429 /* Return true if we must always emit a reloc for a type and false if
1430 there is some hope of resolving it a assembly time. */
1433 alpha_force_relocation (f)
1436 if (alpha_flag_relax)
1439 switch (f->fx_r_type)
1441 case BFD_RELOC_ALPHA_GPDISP_HI16:
1442 case BFD_RELOC_ALPHA_GPDISP_LO16:
1443 case BFD_RELOC_ALPHA_GPDISP:
1445 case BFD_RELOC_ALPHA_LITERAL:
1448 case BFD_RELOC_ALPHA_ELF_LITERAL:
1450 case BFD_RELOC_ALPHA_LITUSE:
1451 case BFD_RELOC_GPREL32:
1453 case BFD_RELOC_ALPHA_LINKAGE:
1454 case BFD_RELOC_ALPHA_CODEADDR:
1457 case BFD_RELOC_ALPHA_USER_LITERAL:
1458 case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
1459 case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
1460 case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
1461 case BFD_RELOC_ALPHA_USER_GPDISP:
1462 case BFD_RELOC_ALPHA_USER_GPRELHIGH:
1463 case BFD_RELOC_ALPHA_USER_GPRELLOW:
1467 case BFD_RELOC_23_PCREL_S2:
1470 case BFD_RELOC_ALPHA_HINT:
1474 assert((int)f->fx_r_type < 0 && -(int)f->fx_r_type < (int)alpha_num_operands);
1479 /* Return true if we can partially resolve a relocation now. */
1482 alpha_fix_adjustable (f)
1486 /* Prevent all adjustments to global symbols */
1487 if (S_IS_EXTERN (f->fx_addsy) || S_IS_WEAK (f->fx_addsy))
1491 /* Are there any relocation types for which we must generate a reloc
1492 but we can adjust the values contained within it? */
1493 switch (f->fx_r_type)
1495 case BFD_RELOC_ALPHA_GPDISP_HI16:
1496 case BFD_RELOC_ALPHA_GPDISP_LO16:
1497 case BFD_RELOC_ALPHA_GPDISP:
1501 case BFD_RELOC_ALPHA_LITERAL:
1504 case BFD_RELOC_ALPHA_ELF_LITERAL:
1507 case BFD_RELOC_ALPHA_USER_LITERAL:
1510 case BFD_RELOC_ALPHA_LINKAGE:
1511 case BFD_RELOC_ALPHA_CODEADDR:
1515 case BFD_RELOC_ALPHA_LITUSE:
1517 case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
1518 case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
1519 case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
1520 case BFD_RELOC_ALPHA_USER_GPDISP:
1521 case BFD_RELOC_ALPHA_USER_GPRELHIGH:
1522 case BFD_RELOC_ALPHA_USER_GPRELLOW:
1526 case BFD_RELOC_GPREL32:
1527 case BFD_RELOC_23_PCREL_S2:
1530 case BFD_RELOC_ALPHA_HINT:
1534 assert ((int)f->fx_r_type < 0
1535 && - (int)f->fx_r_type < (int)alpha_num_operands);
1541 /* Generate the BFD reloc to be stuck in the object file from the
1542 fixup used internally in the assembler. */
1545 tc_gen_reloc (sec, fixp)
1546 asection *sec ATTRIBUTE_UNUSED;
1551 reloc = (arelent *) xmalloc (sizeof (arelent));
1552 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
1553 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1554 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1556 /* Make sure none of our internal relocations make it this far.
1557 They'd better have been fully resolved by this point. */
1558 assert ((int)fixp->fx_r_type > 0);
1560 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1561 if (reloc->howto == NULL)
1563 as_bad_where (fixp->fx_file, fixp->fx_line,
1564 _("cannot represent `%s' relocation in object file"),
1565 bfd_get_reloc_code_name (fixp->fx_r_type));
1569 if (!fixp->fx_pcrel != !reloc->howto->pc_relative)
1571 as_fatal (_("internal error? cannot generate `%s' relocation"),
1572 bfd_get_reloc_code_name (fixp->fx_r_type));
1574 assert (!fixp->fx_pcrel == !reloc->howto->pc_relative);
1577 if (fixp->fx_r_type == BFD_RELOC_ALPHA_LITERAL)
1579 /* fake out bfd_perform_relocation. sigh */
1580 reloc->addend = -alpha_gp_value;
1585 reloc->addend = fixp->fx_offset;
1588 * Ohhh, this is ugly. The problem is that if this is a local global
1589 * symbol, the relocation will entirely be performed at link time, not
1590 * at assembly time. bfd_perform_reloc doesn't know about this sort
1591 * of thing, and as a result we need to fake it out here.
1593 if ((S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy))
1594 && !S_IS_COMMON(fixp->fx_addsy))
1595 reloc->addend -= symbol_get_bfdsym (fixp->fx_addsy)->value;
1602 /* Parse a register name off of the input_line and return a register
1603 number. Gets md_undefined_symbol above to do the register name
1606 Only called as a part of processing the ECOFF .frame directive. */
1609 tc_get_register (frame)
1610 int frame ATTRIBUTE_UNUSED;
1612 int framereg = AXP_REG_SP;
1615 if (*input_line_pointer == '$')
1617 char *s = input_line_pointer;
1618 char c = get_symbol_end ();
1619 symbolS *sym = md_undefined_symbol (s);
1621 *strchr(s, '\0') = c;
1622 if (sym && (framereg = S_GET_VALUE (sym)) <= 31)
1625 as_warn (_("frame reg expected, using $%d."), framereg);
1628 note_gpreg (framereg);
1632 /* This is called before the symbol table is processed. In order to
1633 work with gcc when using mips-tfile, we must keep all local labels.
1634 However, in other cases, we want to discard them. If we were
1635 called with -g, but we didn't see any debugging information, it may
1636 mean that gcc is smuggling debugging information through to
1637 mips-tfile, in which case we must generate all local labels. */
1642 alpha_frob_file_before_adjust ()
1644 if (alpha_debug != 0
1645 && ! ecoff_debugging_seen)
1646 flag_keep_locals = 1;
1649 #endif /* OBJ_ECOFF */
1653 /* Before the relocations are written, reorder them, so that user supplied
1654 !lituse relocations follow the appropriate !literal relocations. Also
1655 convert the gas-internal relocations to the appropriate linker relocations.
1659 alpha_adjust_symtab ()
1661 if (alpha_literal_hash)
1664 fprintf (stderr, "alpha_adjust_symtab called\n");
1667 /* Go over each section, reordering the relocations so that all of the
1668 explicit LITUSE's are adjacent to the explicit LITERAL's */
1669 bfd_map_over_sections (stdoutput, alpha_adjust_symtab_relocs, (char *) 0);
1674 /* Inner function to move LITUSE's next to the LITERAL. */
1677 alpha_adjust_symtab_relocs (abfd, sec, ptr)
1678 bfd *abfd ATTRIBUTE_UNUSED;
1680 PTR ptr ATTRIBUTE_UNUSED;
1682 segment_info_type *seginfo = seg_info (sec);
1692 int n_dup_literals = 0;
1695 /* If seginfo is NULL, we did not create this section; don't do anything with
1696 it. By using a pointer to a pointer, we can update the links in place. */
1697 if (seginfo == NULL)
1700 /* If there are no relocations, skip the section. */
1701 if (! seginfo->fix_root)
1704 /* First rebuild the fixup chain without the expicit lituse's. */
1705 prevP = &(seginfo->fix_root);
1706 for (fixp = seginfo->fix_root; fixp; fixp = next)
1708 next = fixp->fx_next;
1709 fixp->fx_next = (fixS *)0;
1714 switch (fixp->fx_r_type)
1718 prevP = &(fixp->fx_next);
1721 "alpha_adjust_symtab_relocs: 0x%lx, other relocation %s\n",
1723 bfd_get_reloc_code_name (fixp->fx_r_type));
1727 case BFD_RELOC_ALPHA_USER_LITERAL:
1729 prevP = &(fixp->fx_next);
1730 /* prevent assembler from trying to adjust the offset */
1733 if (fixp->tc_fix_data.info->n_literals != 1)
1736 "alpha_adjust_symtab_relocs: 0x%lx, !literal!%.6d, # literals = %2d\n",
1738 fixp->tc_fix_data.info->sequence,
1739 fixp->tc_fix_data.info->n_literals);
1743 /* do not link in lituse's */
1744 case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
1745 case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
1746 case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
1748 if (fixp->tc_fix_data.info->n_literals == 0)
1749 as_bad_where (fixp->fx_file, fixp->fx_line,
1750 _("No !literal!%d was found"),
1751 fixp->tc_fix_data.info->sequence);
1754 "alpha_adjust_symtab_relocs: 0x%lx, !lituse !%.6d, # lituses = %2d, next_lituse = 0x%lx\n",
1756 fixp->tc_fix_data.info->sequence,
1757 fixp->tc_fix_data.info->n_lituses,
1758 (long)fixp->tc_fix_data.next_lituse);
1764 /* If there were any lituses, go and add them to the chain, unless there is
1765 more than one !literal for a given sequence number. They are linked
1766 through the next_lituse field in reverse order, so as we go through the
1767 next_lituse chain, we effectively reverse the chain once again. If there
1768 was more than one !literal, we fall back to loading up the address w/o
1769 optimization. Also, if the !literals/!lituses are spread in different
1770 segments (happens in the Linux kernel semaphores), suppress the
1774 for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
1776 switch (fixp->fx_r_type)
1781 case BFD_RELOC_ALPHA_USER_LITERAL:
1783 fixp->fx_r_type = BFD_RELOC_ALPHA_ELF_LITERAL;
1785 fixp->fx_r_type = BFD_RELOC_ALPHA_LITERAL; /* XXX check this */
1787 if (fixp->tc_fix_data.info->n_literals == 1
1788 && ! fixp->tc_fix_data.info->multi_section_p)
1790 for (lituse = fixp->tc_fix_data.info->lituse;
1791 lituse != (fixS *)0;
1792 lituse = lituse->tc_fix_data.next_lituse)
1794 lituse->fx_next = fixp->fx_next;
1795 fixp->fx_next = lituse;
1800 case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
1801 case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
1802 case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
1803 fixp->fx_r_type = BFD_RELOC_ALPHA_LITUSE;
1810 fprintf (stderr, "alpha_adjust_symtab_relocs: %s, %d literal%s, %d duplicate literal%s, %d lituse%s\n\n",
1812 n_literals, (n_literals == 1) ? "" : "s",
1813 n_dup_literals, (n_dup_literals == 1) ? "" : "s",
1814 n_lituses, (n_lituses == 1) ? "" : "s");
1818 #endif /* RELOC_OP_P */
1823 debug_exp (tok, ntok)
1829 fprintf (stderr, "debug_exp: %d tokens", ntok);
1830 for (i = 0; i < ntok; i++)
1832 expressionS *t = &tok[i];
1836 default: name = "unknown"; break;
1837 case O_illegal: name = "O_illegal"; break;
1838 case O_absent: name = "O_absent"; break;
1839 case O_constant: name = "O_constant"; break;
1840 case O_symbol: name = "O_symbol"; break;
1841 case O_symbol_rva: name = "O_symbol_rva"; break;
1842 case O_register: name = "O_register"; break;
1843 case O_big: name = "O_big"; break;
1844 case O_uminus: name = "O_uminus"; break;
1845 case O_bit_not: name = "O_bit_not"; break;
1846 case O_logical_not: name = "O_logical_not"; break;
1847 case O_multiply: name = "O_multiply"; break;
1848 case O_divide: name = "O_divide"; break;
1849 case O_modulus: name = "O_modulus"; break;
1850 case O_left_shift: name = "O_left_shift"; break;
1851 case O_right_shift: name = "O_right_shift"; break;
1852 case O_bit_inclusive_or: name = "O_bit_inclusive_or"; break;
1853 case O_bit_or_not: name = "O_bit_or_not"; break;
1854 case O_bit_exclusive_or: name = "O_bit_exclusive_or"; break;
1855 case O_bit_and: name = "O_bit_and"; break;
1856 case O_add: name = "O_add"; break;
1857 case O_subtract: name = "O_subtract"; break;
1858 case O_eq: name = "O_eq"; break;
1859 case O_ne: name = "O_ne"; break;
1860 case O_lt: name = "O_lt"; break;
1861 case O_le: name = "O_le"; break;
1862 case O_ge: name = "O_ge"; break;
1863 case O_gt: name = "O_gt"; break;
1864 case O_logical_and: name = "O_logical_and"; break;
1865 case O_logical_or: name = "O_logical_or"; break;
1866 case O_index: name = "O_index"; break;
1867 case O_pregister: name = "O_pregister"; break;
1868 case O_cpregister: name = "O_cpregister"; break;
1869 case O_literal: name = "O_literal"; break;
1870 case O_lituse_base: name = "O_lituse_base"; break;
1871 case O_lituse_bytoff: name = "O_lituse_bytoff"; break;
1872 case O_lituse_jsr: name = "O_lituse_jsr"; break;
1873 case O_gpdisp: name = "O_gpdisp"; break;
1874 case O_gprelhigh: name = "O_gprelhigh"; break;
1875 case O_gprellow: name = "O_gprellow"; break;
1876 case O_md10: name = "O_md10"; break;
1877 case O_md11: name = "O_md11"; break;
1878 case O_md12: name = "O_md12"; break;
1879 case O_md13: name = "O_md13"; break;
1880 case O_md14: name = "O_md14"; break;
1881 case O_md15: name = "O_md15"; break;
1882 case O_md16: name = "O_md16"; break;
1885 fprintf (stderr, ", %s(%s, %s, %d)", name,
1886 (t->X_add_symbol) ? S_GET_NAME (t->X_add_symbol) : "--",
1887 (t->X_op_symbol) ? S_GET_NAME (t->X_op_symbol) : "--",
1888 (int)t->X_add_number);
1890 fprintf (stderr, "\n");
1895 /* Parse the arguments to an opcode. */
1898 tokenize_arguments (str, tok, ntok)
1903 expressionS *end_tok = tok + ntok;
1904 char *old_input_line_pointer;
1905 int saw_comma = 0, saw_arg = 0;
1907 expressionS *orig_tok = tok;
1911 const struct alpha_reloc_op_tag *r;
1914 int reloc_found_p = 0;
1917 memset (tok, 0, sizeof (*tok) * ntok);
1919 /* Save and restore input_line_pointer around this function */
1920 old_input_line_pointer = input_line_pointer;
1921 input_line_pointer = str;
1923 while (tok < end_tok && *input_line_pointer)
1926 switch (*input_line_pointer)
1933 /* A relocation operand can be placed after the normal operand on an
1934 assembly language statement, and has the following form:
1935 !relocation_type!sequence_number. */
1937 { /* only support one relocation op per insn */
1938 as_bad (_("More than one relocation op per insn"));
1945 for (p = ++input_line_pointer;
1946 ((c = *p) != '!' && c != ';' && c != '#' && c != ','
1947 && !is_end_of_line[c]);
1951 /* Parse !relocation_type */
1952 len = p - input_line_pointer;
1955 as_bad (_("No relocation operand"));
1961 as_bad (_("No !sequence-number after !%s"), input_line_pointer);
1965 r = &alpha_reloc_op[0];
1966 for (i = alpha_num_reloc_op-1; i >= 0; i--, r++)
1968 if (len == r->length
1969 && memcmp (input_line_pointer, r->name, len) == 0)
1974 as_bad (_("Unknown relocation operand: !%s"), input_line_pointer);
1978 input_line_pointer = ++p;
1980 /* Parse !sequence_number */
1981 memset (tok, '\0', sizeof (expressionS));
1984 if (tok->X_op != O_constant
1985 || ! ALPHA_RELOC_SEQUENCE_OK (tok->X_add_number))
1987 as_bad (_("Bad sequence number: !%s!%s"), r->name, input_line_pointer);
1998 ++input_line_pointer;
1999 if (saw_comma || !saw_arg)
2006 char *hold = input_line_pointer++;
2008 /* First try for parenthesized register ... */
2010 if (*input_line_pointer == ')' && tok->X_op == O_register)
2012 tok->X_op = (saw_comma ? O_cpregister : O_pregister);
2015 ++input_line_pointer;
2020 /* ... then fall through to plain expression */
2021 input_line_pointer = hold;
2025 if (saw_arg && !saw_comma)
2029 if (tok->X_op == O_illegal || tok->X_op == O_absent)
2042 input_line_pointer = old_input_line_pointer;
2045 debug_exp (orig_tok, ntok - (end_tok - tok));
2048 return ntok - (end_tok - tok);
2051 input_line_pointer = old_input_line_pointer;
2052 return TOKENIZE_ERROR;
2056 input_line_pointer = old_input_line_pointer;
2057 return TOKENIZE_ERROR_REPORT;
2061 /* Search forward through all variants of an opcode looking for a
2064 static const struct alpha_opcode *
2065 find_opcode_match(first_opcode, tok, pntok, pcpumatch)
2066 const struct alpha_opcode *first_opcode;
2067 const expressionS *tok;
2071 const struct alpha_opcode *opcode = first_opcode;
2073 int got_cpu_match = 0;
2077 const unsigned char *opidx;
2080 /* Don't match opcodes that don't exist on this architecture */
2081 if (!(opcode->flags & alpha_target))
2086 for (opidx = opcode->operands; *opidx; ++opidx)
2088 const struct alpha_operand *operand = &alpha_operands[*opidx];
2090 /* only take input from real operands */
2091 if (operand->flags & AXP_OPERAND_FAKE)
2094 /* when we expect input, make sure we have it */
2097 if ((operand->flags & AXP_OPERAND_OPTIONAL_MASK) == 0)
2102 /* match operand type with expression type */
2103 switch (operand->flags & AXP_OPERAND_TYPECHECK_MASK)
2105 case AXP_OPERAND_IR:
2106 if (tok[tokidx].X_op != O_register
2107 || !is_ir_num(tok[tokidx].X_add_number))
2110 case AXP_OPERAND_FPR:
2111 if (tok[tokidx].X_op != O_register
2112 || !is_fpr_num(tok[tokidx].X_add_number))
2115 case AXP_OPERAND_IR|AXP_OPERAND_PARENS:
2116 if (tok[tokidx].X_op != O_pregister
2117 || !is_ir_num(tok[tokidx].X_add_number))
2120 case AXP_OPERAND_IR|AXP_OPERAND_PARENS|AXP_OPERAND_COMMA:
2121 if (tok[tokidx].X_op != O_cpregister
2122 || !is_ir_num(tok[tokidx].X_add_number))
2126 case AXP_OPERAND_RELATIVE:
2127 case AXP_OPERAND_SIGNED:
2128 case AXP_OPERAND_UNSIGNED:
2129 switch (tok[tokidx].X_op)
2144 /* everything else should have been fake */
2150 /* possible match -- did we use all of our input? */
2159 while (++opcode-alpha_opcodes < alpha_num_opcodes
2160 && !strcmp(opcode->name, first_opcode->name));
2163 *pcpumatch = got_cpu_match;
2168 /* Search forward through all variants of a macro looking for a syntax
2171 static const struct alpha_macro *
2172 find_macro_match(first_macro, tok, pntok)
2173 const struct alpha_macro *first_macro;
2174 const expressionS *tok;
2177 const struct alpha_macro *macro = first_macro;
2182 const enum alpha_macro_arg *arg = macro->argsets;
2196 /* index register */
2198 if (tokidx >= ntok || tok[tokidx].X_op != O_register
2199 || !is_ir_num(tok[tokidx].X_add_number))
2204 /* parenthesized index register */
2206 if (tokidx >= ntok || tok[tokidx].X_op != O_pregister
2207 || !is_ir_num(tok[tokidx].X_add_number))
2212 /* optional parenthesized index register */
2214 if (tokidx < ntok && tok[tokidx].X_op == O_pregister
2215 && is_ir_num(tok[tokidx].X_add_number))
2219 /* leading comma with a parenthesized index register */
2221 if (tokidx >= ntok || tok[tokidx].X_op != O_cpregister
2222 || !is_ir_num(tok[tokidx].X_add_number))
2227 /* floating point register */
2229 if (tokidx >= ntok || tok[tokidx].X_op != O_register
2230 || !is_fpr_num(tok[tokidx].X_add_number))
2235 /* normal expression */
2239 switch (tok[tokidx].X_op)
2249 case O_lituse_bytoff:
2263 /* optional !literal!<number> */
2266 if (tokidx < ntok && tok[tokidx].X_op == O_literal)
2271 /* optional !lituse_base!<number> */
2274 if (tokidx < ntok && tok[tokidx].X_op == O_lituse_base)
2279 /* optional !lituse_bytoff!<number> */
2282 if (tokidx < ntok && tok[tokidx].X_op == O_lituse_bytoff)
2287 /* optional !lituse_jsr!<number> */
2290 if (tokidx < ntok && tok[tokidx].X_op == O_lituse_jsr)
2296 while (*arg != MACRO_EOA)
2304 while (++macro-alpha_macros < alpha_num_macros
2305 && !strcmp(macro->name, first_macro->name));
2310 /* Insert an operand value into an instruction. */
2313 insert_operand(insn, operand, val, file, line)
2315 const struct alpha_operand *operand;
2320 if (operand->bits != 32 && !(operand->flags & AXP_OPERAND_NOOVERFLOW))
2324 if (operand->flags & AXP_OPERAND_SIGNED)
2326 max = (1 << (operand->bits - 1)) - 1;
2327 min = -(1 << (operand->bits - 1));
2331 max = (1 << operand->bits) - 1;
2335 if (val < min || val > max)
2338 _("operand out of range (%s not between %d and %d)");
2339 char buf[sizeof (val) * 3 + 2];
2341 sprint_value(buf, val);
2343 as_warn_where(file, line, err, buf, min, max);
2345 as_warn(err, buf, min, max);
2349 if (operand->insert)
2351 const char *errmsg = NULL;
2353 insn = (*operand->insert) (insn, val, &errmsg);
2358 insn |= ((val & ((1 << operand->bits) - 1)) << operand->shift);
2364 * Turn an opcode description and a set of arguments into
2365 * an instruction and a fixup.
2369 assemble_insn(opcode, tok, ntok, insn)
2370 const struct alpha_opcode *opcode;
2371 const expressionS *tok;
2373 struct alpha_insn *insn;
2375 const unsigned char *argidx;
2379 memset (insn, 0, sizeof (*insn));
2380 image = opcode->opcode;
2382 for (argidx = opcode->operands; *argidx; ++argidx)
2384 const struct alpha_operand *operand = &alpha_operands[*argidx];
2385 const expressionS *t = (const expressionS *)0;
2387 if (operand->flags & AXP_OPERAND_FAKE)
2389 /* fake operands take no value and generate no fixup */
2390 image = insert_operand(image, operand, 0, NULL, 0);
2396 switch (operand->flags & AXP_OPERAND_OPTIONAL_MASK)
2398 case AXP_OPERAND_DEFAULT_FIRST:
2401 case AXP_OPERAND_DEFAULT_SECOND:
2404 case AXP_OPERAND_DEFAULT_ZERO:
2406 static expressionS zero_exp;
2408 zero_exp.X_op = O_constant;
2409 zero_exp.X_unsigned = 1;
2424 image = insert_operand(image, operand, regno(t->X_add_number),
2429 image = insert_operand(image, operand, t->X_add_number, NULL, 0);
2434 struct alpha_fixup *fixup;
2436 if (insn->nfixups >= MAX_INSN_FIXUPS)
2437 as_fatal(_("too many fixups"));
2439 fixup = &insn->fixups[insn->nfixups++];
2442 fixup->reloc = operand->default_reloc;
2452 * Actually output an instruction with its fixup.
2457 struct alpha_insn *insn;
2462 /* Take care of alignment duties */
2463 if (alpha_auto_align_on && alpha_current_align < 2)
2464 alpha_align (2, (char *) NULL, alpha_insn_label, 0);
2465 if (alpha_current_align > 2)
2466 alpha_current_align = 2;
2467 alpha_insn_label = NULL;
2469 /* Write out the instruction. */
2471 md_number_to_chars (f, insn->insn, 4);
2474 dwarf2_emit_insn (4);
2477 /* Apply the fixups in order */
2478 for (i = 0; i < insn->nfixups; ++i)
2480 const struct alpha_operand *operand = (const struct alpha_operand *)0;
2481 struct alpha_fixup *fixup = &insn->fixups[i];
2485 char buffer[ALPHA_RELOC_DIGITS];
2486 struct alpha_literal_tag *info;
2489 /* Some fixups are only used internally and so have no howto */
2490 if ((int)fixup->reloc < 0)
2492 operand = &alpha_operands[-(int)fixup->reloc];
2494 pcrel = ((operand->flags & AXP_OPERAND_RELATIVE) != 0);
2496 else switch (fixup->reloc)
2499 /* These relocation types are only used internally. */
2500 case BFD_RELOC_ALPHA_GPDISP_HI16:
2501 case BFD_RELOC_ALPHA_GPDISP_LO16:
2507 /* and these also are internal only relocations */
2508 case BFD_RELOC_ALPHA_USER_LITERAL:
2509 case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
2510 case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
2511 case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
2512 case BFD_RELOC_ALPHA_USER_GPDISP:
2513 case BFD_RELOC_ALPHA_USER_GPRELHIGH:
2514 case BFD_RELOC_ALPHA_USER_GPRELLOW:
2522 reloc_howto_type *reloc_howto
2523 = bfd_reloc_type_lookup (stdoutput, fixup->reloc);
2524 assert (reloc_howto);
2526 size = bfd_get_reloc_size (reloc_howto);
2527 pcrel = reloc_howto->pc_relative;
2529 assert (size >= 1 && size <= 4);
2533 fixP = fix_new_exp (frag_now, f - frag_now->fr_literal, size,
2534 &fixup->exp, pcrel, fixup->reloc);
2536 /* Turn off complaints that the addend is too large for some fixups,
2537 and copy in the sequence number for the explicit relocations. */
2538 switch (fixup->reloc)
2540 case BFD_RELOC_ALPHA_GPDISP_LO16:
2542 case BFD_RELOC_ALPHA_LITERAL:
2545 case BFD_RELOC_ALPHA_ELF_LITERAL:
2547 case BFD_RELOC_GPREL32:
2548 fixP->fx_no_overflow = 1;
2552 case BFD_RELOC_ALPHA_USER_LITERAL:
2553 fixP->fx_no_overflow = 1;
2554 sprintf (buffer, "!%u", insn->sequence[i]);
2555 info = ((struct alpha_literal_tag *)
2556 hash_find (alpha_literal_hash, buffer));
2560 size_t len = strlen (buffer);
2563 info = ((struct alpha_literal_tag *)
2564 xcalloc (sizeof (struct alpha_literal_tag) + len, 1));
2566 info->segment = now_seg;
2567 info->sequence = insn->sequence[i];
2568 strcpy (info->string, buffer);
2569 errmsg = hash_insert (alpha_literal_hash, info->string, (PTR)info);
2576 if (info->segment != now_seg)
2577 info->multi_section_p = 1;
2579 fixP->tc_fix_data.info = info;
2582 case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
2583 case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
2584 case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
2585 sprintf (buffer, "!%u", insn->sequence[i]);
2586 info = ((struct alpha_literal_tag *)
2587 hash_find (alpha_literal_hash, buffer));
2591 size_t len = strlen (buffer);
2594 info = ((struct alpha_literal_tag *)
2595 xcalloc (sizeof (struct alpha_literal_tag) + len, 1));
2597 info->segment = now_seg;
2598 info->sequence = insn->sequence[i];
2599 strcpy (info->string, buffer);
2600 errmsg = hash_insert (alpha_literal_hash, info->string, (PTR)info);
2605 fixP->tc_fix_data.info = info;
2606 fixP->tc_fix_data.next_lituse = info->lituse;
2607 info->lituse = fixP;
2608 if (info->segment != now_seg)
2609 info->multi_section_p = 1;
2615 if ((int)fixup->reloc < 0)
2617 if (operand->flags & AXP_OPERAND_NOOVERFLOW)
2618 fixP->fx_no_overflow = 1;
2625 /* Given an opcode name and a pre-tokenized set of arguments, assemble
2626 the insn, but do not emit it.
2628 Note that this implies no macros allowed, since we can't store more
2629 than one insn in an insn structure. */
2632 assemble_tokens_to_insn(opname, tok, ntok, insn)
2634 const expressionS *tok;
2636 struct alpha_insn *insn;
2638 const struct alpha_opcode *opcode;
2640 /* search opcodes */
2641 opcode = (const struct alpha_opcode *) hash_find (alpha_opcode_hash, opname);
2645 opcode = find_opcode_match (opcode, tok, &ntok, &cpumatch);
2648 assemble_insn (opcode, tok, ntok, insn);
2652 as_bad (_("inappropriate arguments for opcode `%s'"), opname);
2654 as_bad (_("opcode `%s' not supported for target %s"), opname,
2658 as_bad (_("unknown opcode `%s'"), opname);
2661 /* Given an opcode name and a pre-tokenized set of arguments, take the
2662 opcode all the way through emission. */
2665 assemble_tokens (opname, tok, ntok, local_macros_on)
2667 const expressionS *tok;
2669 int local_macros_on;
2671 int found_something = 0;
2672 const struct alpha_opcode *opcode;
2673 const struct alpha_macro *macro;
2677 if (local_macros_on)
2679 macro = ((const struct alpha_macro *)
2680 hash_find (alpha_macro_hash, opname));
2683 found_something = 1;
2684 macro = find_macro_match (macro, tok, &ntok);
2687 (*macro->emit) (tok, ntok, macro->arg);
2694 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
2696 const expressionS *reloc_exp = &tok[ntok-1];
2697 const struct alpha_reloc_op_tag *r = ALPHA_RELOC_TABLE (reloc_exp->X_op);
2698 as_bad (_("Cannot use !%s!%d with %s"), r->name,
2699 (int)reloc_exp->X_add_number, opname);
2704 /* search opcodes */
2705 opcode = (const struct alpha_opcode *) hash_find (alpha_opcode_hash, opname);
2708 found_something = 1;
2709 opcode = find_opcode_match (opcode, tok, &ntok, &cpumatch);
2712 struct alpha_insn insn;
2713 assemble_insn (opcode, tok, ntok, &insn);
2719 if (found_something)
2721 as_bad (_("inappropriate arguments for opcode `%s'"), opname);
2723 as_bad (_("opcode `%s' not supported for target %s"), opname,
2726 as_bad (_("unknown opcode `%s'"), opname);
2730 /* Some instruction sets indexed by lg(size) */
2731 static const char * const sextX_op[] = { "sextb", "sextw", "sextl", NULL };
2732 static const char * const insXl_op[] = { "insbl", "inswl", "insll", "insql" };
2733 static const char * const insXh_op[] = { NULL, "inswh", "inslh", "insqh" };
2734 static const char * const extXl_op[] = { "extbl", "extwl", "extll", "extql" };
2735 static const char * const extXh_op[] = { NULL, "extwh", "extlh", "extqh" };
2736 static const char * const mskXl_op[] = { "mskbl", "mskwl", "mskll", "mskql" };
2737 static const char * const mskXh_op[] = { NULL, "mskwh", "msklh", "mskqh" };
2738 static const char * const stX_op[] = { "stb", "stw", "stl", "stq" };
2739 static const char * const ldX_op[] = { "ldb", "ldw", "ldll", "ldq" };
2740 static const char * const ldXu_op[] = { "ldbu", "ldwu", NULL, NULL };
2742 /* Implement the ldgp macro. */
2745 emit_ldgp (tok, ntok, unused)
2746 const expressionS *tok;
2747 int ntok ATTRIBUTE_UNUSED;
2748 const PTR unused ATTRIBUTE_UNUSED;
2753 #if defined(OBJ_ECOFF) || defined(OBJ_ELF)
2754 /* from "ldgp r1,n(r2)", generate "ldah r1,X(R2); lda r1,Y(r1)"
2755 with appropriate constants and relocations. */
2756 struct alpha_insn insn;
2757 expressionS newtok[3];
2761 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
2763 const expressionS *reloc_exp = &tok[ntok-1];
2764 const struct alpha_reloc_op_tag *r = ALPHA_RELOC_TABLE (reloc_exp->X_op);
2765 as_bad (_("Cannot use !%s!%d with %s"), r->name,
2766 (int)reloc_exp->X_add_number, "ldgp");
2772 if (regno (tok[2].X_add_number) == AXP_REG_PV)
2773 ecoff_set_gp_prolog_size (0);
2777 set_tok_const (newtok[1], 0);
2780 assemble_tokens_to_insn ("ldah", newtok, 3, &insn);
2785 if (addend.X_op != O_constant)
2786 as_bad (_("can not resolve expression"));
2787 addend.X_op = O_symbol;
2788 addend.X_add_symbol = alpha_gp_symbol;
2792 insn.fixups[0].exp = addend;
2793 insn.fixups[0].reloc = BFD_RELOC_ALPHA_GPDISP_HI16;
2797 set_tok_preg (newtok[2], tok[0].X_add_number);
2799 assemble_tokens_to_insn ("lda", newtok, 3, &insn);
2802 addend.X_add_number += 4;
2806 insn.fixups[0].exp = addend;
2807 insn.fixups[0].reloc = BFD_RELOC_ALPHA_GPDISP_LO16;
2810 #endif /* OBJ_ECOFF || OBJ_ELF */
2815 /* Add symbol+addend to link pool.
2816 Return offset from basesym to entry in link pool.
2818 Add new fixup only if offset isn't 16bit. */
2821 add_to_link_pool (basesym, sym, addend)
2826 segT current_section = now_seg;
2827 int current_subsec = now_subseg;
2829 bfd_reloc_code_real_type reloc_type;
2831 segment_info_type *seginfo = seg_info (alpha_link_section);
2834 offset = - *symbol_get_obj (basesym);
2836 /* @@ This assumes all entries in a given section will be of the same
2837 size... Probably correct, but unwise to rely on. */
2838 /* This must always be called with the same subsegment. */
2840 if (seginfo->frchainP)
2841 for (fixp = seginfo->frchainP->fix_root;
2842 fixp != (fixS *) NULL;
2843 fixp = fixp->fx_next, offset += 8)
2845 if (fixp->fx_addsy == sym && fixp->fx_offset == addend)
2847 if (range_signed_16 (offset))
2854 /* Not found in 16bit signed range. */
2856 subseg_set (alpha_link_section, 0);
2860 fix_new (frag_now, p - frag_now->fr_literal, 8, sym, addend, 0,
2863 subseg_set (current_section, current_subsec);
2864 seginfo->literal_pool_size += 8;
2868 #endif /* OBJ_EVAX */
2870 /* Load a (partial) expression into a target register.
2872 If poffset is not null, after the call it will either contain
2873 O_constant 0, or a 16-bit offset appropriate for any MEM format
2874 instruction. In addition, pbasereg will be modified to point to
2875 the base register to use in that MEM format instruction.
2877 In any case, *pbasereg should contain a base register to add to the
2878 expression. This will normally be either AXP_REG_ZERO or
2879 alpha_gp_register. Symbol addresses will always be loaded via $gp,
2880 so "foo($0)" is interpreted as adding the address of foo to $0;
2881 i.e. "ldq $targ, LIT($gp); addq $targ, $0, $targ". Odd, perhaps,
2882 but this is what OSF/1 does.
2884 If explicit relocations of the form !literal!<number> are allowed,
2885 and used, then explict_reloc with be an expression pointer.
2887 Finally, the return value is true if the calling macro may emit a
2888 LITUSE reloc if otherwise appropriate. */
2891 load_expression (targreg, exp, pbasereg, poffset, explicit_reloc)
2893 const expressionS *exp;
2895 expressionS *poffset;
2896 const expressionS *explicit_reloc;
2898 int emit_lituse = 0;
2899 offsetT addend = exp->X_add_number;
2900 int basereg = *pbasereg;
2901 struct alpha_insn insn;
2902 expressionS newtok[3];
2911 /* attempt to reduce .lit load by splitting the offset from
2912 its symbol when possible, but don't create a situation in
2914 if (!range_signed_32 (addend) &&
2915 (alpha_noat_on || targreg == AXP_REG_AT))
2917 lit = add_to_literal_pool (exp->X_add_symbol, addend,
2918 alpha_lita_section, 8);
2923 lit = add_to_literal_pool (exp->X_add_symbol, 0,
2924 alpha_lita_section, 8);
2928 as_fatal (_("overflow in literal (.lita) table"));
2930 /* emit "ldq r, lit(gp)" */
2932 if (basereg != alpha_gp_register && targreg == basereg)
2935 as_bad (_("macro requires $at register while noat in effect"));
2936 if (targreg == AXP_REG_AT)
2937 as_bad (_("macro requires $at while $at in use"));
2939 set_tok_reg (newtok[0], AXP_REG_AT);
2942 set_tok_reg (newtok[0], targreg);
2943 set_tok_sym (newtok[1], alpha_lita_symbol, lit);
2944 set_tok_preg (newtok[2], alpha_gp_register);
2946 assemble_tokens_to_insn ("ldq", newtok, 3, &insn);
2948 assert (explicit_reloc == (const expressionS *)0);
2949 assert (insn.nfixups == 1);
2950 insn.fixups[0].reloc = BFD_RELOC_ALPHA_LITERAL;
2951 #endif /* OBJ_ECOFF */
2953 /* emit "ldq r, gotoff(gp)" */
2955 if (basereg != alpha_gp_register && targreg == basereg)
2958 as_bad (_("macro requires $at register while noat in effect"));
2959 if (targreg == AXP_REG_AT)
2960 as_bad (_("macro requires $at while $at in use"));
2962 set_tok_reg (newtok[0], AXP_REG_AT);
2965 set_tok_reg (newtok[0], targreg);
2967 /* XXX: Disable this .got minimizing optimization so that we can get
2968 better instruction offset knowledge in the compiler. This happens
2969 very infrequently anyway. */
2970 if (1 || (!range_signed_32 (addend)
2971 && (alpha_noat_on || targreg == AXP_REG_AT)))
2978 set_tok_sym (newtok[1], exp->X_add_symbol, 0);
2981 set_tok_preg (newtok[2], alpha_gp_register);
2983 assemble_tokens_to_insn ("ldq", newtok, 3, &insn);
2985 assert (insn.nfixups == 1);
2986 if (!explicit_reloc)
2987 insn.fixups[0].reloc = BFD_RELOC_ALPHA_ELF_LITERAL;
2991 insn.fixups[0].reloc
2992 = (ALPHA_RELOC_TABLE (explicit_reloc->X_op))->reloc;
2993 insn.sequence[0] = explicit_reloc->X_add_number;
2998 #endif /* OBJ_ELF */
3002 /* Find symbol or symbol pointer in link section. */
3004 assert (explicit_reloc == (const expressionS *)0);
3005 if (exp->X_add_symbol == alpha_evax_proc.symbol)
3007 if (range_signed_16 (addend))
3009 set_tok_reg (newtok[0], targreg);
3010 set_tok_const (newtok[1], addend);
3011 set_tok_preg (newtok[2], basereg);
3012 assemble_tokens_to_insn ("lda", newtok, 3, &insn);
3017 set_tok_reg (newtok[0], targreg);
3018 set_tok_const (newtok[1], 0);
3019 set_tok_preg (newtok[2], basereg);
3020 assemble_tokens_to_insn ("lda", newtok, 3, &insn);
3025 if (!range_signed_32 (addend))
3027 link = add_to_link_pool (alpha_evax_proc.symbol,
3028 exp->X_add_symbol, addend);
3033 link = add_to_link_pool (alpha_evax_proc.symbol,
3034 exp->X_add_symbol, 0);
3036 set_tok_reg (newtok[0], targreg);
3037 set_tok_const (newtok[1], link);
3038 set_tok_preg (newtok[2], basereg);
3039 assemble_tokens_to_insn ("ldq", newtok, 3, &insn);
3041 #endif /* OBJ_EVAX */
3048 if (basereg != alpha_gp_register && basereg != AXP_REG_ZERO)
3050 /* emit "addq r, base, r" */
3052 set_tok_reg (newtok[1], basereg);
3053 set_tok_reg (newtok[2], targreg);
3054 assemble_tokens ("addq", newtok, 3, 0);
3063 assert (explicit_reloc == (const expressionS *)0);
3067 /* Assume that this difference expression will be resolved to an
3068 absolute value and that that value will fit in 16 bits. */
3070 assert (explicit_reloc == (const expressionS *)0);
3071 set_tok_reg (newtok[0], targreg);
3073 set_tok_preg (newtok[2], basereg);
3074 assemble_tokens ("lda", newtok, 3, 0);
3077 set_tok_const (*poffset, 0);
3081 if (exp->X_add_number > 0)
3082 as_bad (_("bignum invalid; zero assumed"));
3084 as_bad (_("floating point number invalid; zero assumed"));
3089 as_bad (_("can't handle expression"));
3094 if (!range_signed_32 (addend))
3098 /* for 64-bit addends, just put it in the literal pool */
3101 /* emit "ldq targreg, lit(basereg)" */
3102 lit = add_to_link_pool (alpha_evax_proc.symbol,
3103 section_symbol (absolute_section), addend);
3104 set_tok_reg (newtok[0], targreg);
3105 set_tok_const (newtok[1], lit);
3106 set_tok_preg (newtok[2], alpha_gp_register);
3107 assemble_tokens ("ldq", newtok, 3, 0);
3110 if (alpha_lit8_section == NULL)
3112 create_literal_section (".lit8",
3113 &alpha_lit8_section,
3114 &alpha_lit8_symbol);
3117 alpha_lit8_literal = add_to_literal_pool (alpha_lit8_symbol, 0x8000,
3118 alpha_lita_section, 8);
3119 if (alpha_lit8_literal >= 0x8000)
3120 as_fatal (_("overflow in literal (.lita) table"));
3124 lit = add_to_literal_pool (NULL, addend, alpha_lit8_section, 8) - 0x8000;
3126 as_fatal (_("overflow in literal (.lit8) table"));
3128 /* emit "lda litreg, .lit8+0x8000" */
3130 if (targreg == basereg)
3133 as_bad (_("macro requires $at register while noat in effect"));
3134 if (targreg == AXP_REG_AT)
3135 as_bad (_("macro requires $at while $at in use"));
3137 set_tok_reg (newtok[0], AXP_REG_AT);
3140 set_tok_reg (newtok[0], targreg);
3142 set_tok_sym (newtok[1], alpha_lita_symbol, alpha_lit8_literal);
3145 set_tok_sym (newtok[1], alpha_lit8_symbol, 0x8000);
3147 set_tok_preg (newtok[2], alpha_gp_register);
3149 assemble_tokens_to_insn ("ldq", newtok, 3, &insn);
3151 assert (insn.nfixups == 1);
3153 insn.fixups[0].reloc = BFD_RELOC_ALPHA_LITERAL;
3156 insn.fixups[0].reloc = BFD_RELOC_ALPHA_ELF_LITERAL;
3161 /* emit "ldq litreg, lit(litreg)" */
3163 set_tok_const (newtok[1], lit);
3164 set_tok_preg (newtok[2], newtok[0].X_add_number);
3166 assemble_tokens_to_insn ("ldq", newtok, 3, &insn);
3168 assert (insn.nfixups < MAX_INSN_FIXUPS);
3169 if (insn.nfixups > 0)
3171 memmove (&insn.fixups[1], &insn.fixups[0],
3172 sizeof (struct alpha_fixup) * insn.nfixups);
3175 insn.fixups[0].reloc = BFD_RELOC_ALPHA_LITUSE;
3176 insn.fixups[0].exp.X_op = O_symbol;
3177 insn.fixups[0].exp.X_add_symbol = section_symbol (now_seg);
3178 insn.fixups[0].exp.X_add_number = LITUSE_BASE;
3183 /* emit "addq litreg, base, target" */
3185 if (basereg != AXP_REG_ZERO)
3187 set_tok_reg (newtok[1], basereg);
3188 set_tok_reg (newtok[2], targreg);
3189 assemble_tokens ("addq", newtok, 3, 0);
3191 #endif /* !OBJ_EVAX */
3194 set_tok_const (*poffset, 0);
3195 *pbasereg = targreg;
3199 offsetT low, high, extra, tmp;
3201 /* for 32-bit operands, break up the addend */
3203 low = sign_extend_16 (addend);
3205 high = sign_extend_16 (tmp >> 16);
3207 if (tmp - (high << 16))
3211 high = sign_extend_16 (tmp >> 16);
3216 set_tok_reg (newtok[0], targreg);
3217 set_tok_preg (newtok[2], basereg);
3221 /* emit "ldah r, extra(r) */
3222 set_tok_const (newtok[1], extra);
3223 assemble_tokens ("ldah", newtok, 3, 0);
3224 set_tok_preg (newtok[2], basereg = targreg);
3229 /* emit "ldah r, high(r) */
3230 set_tok_const (newtok[1], high);
3231 assemble_tokens ("ldah", newtok, 3, 0);
3233 set_tok_preg (newtok[2], basereg);
3236 if ((low && !poffset) || (!poffset && basereg != targreg))
3238 /* emit "lda r, low(base)" */
3239 set_tok_const (newtok[1], low);
3240 assemble_tokens ("lda", newtok, 3, 0);
3246 set_tok_const (*poffset, low);
3247 *pbasereg = basereg;
3253 /* The lda macro differs from the lda instruction in that it handles
3254 most simple expressions, particualrly symbol address loads and
3258 emit_lda (tok, ntok, opname)
3259 const expressionS *tok;
3264 const expressionS *reloc = (const expressionS *)0;
3267 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
3269 const struct alpha_reloc_op_tag *r;
3271 reloc = &tok[ntok-1];
3272 r = ALPHA_RELOC_TABLE (reloc->X_op);
3273 switch (reloc->X_op)
3276 as_bad (_("Cannot use !%s!%d with %s"), r->name,
3277 (int)reloc->X_add_number, (const char *)opname);
3279 reloc = (const expressionS *)0;
3287 /* For lda $x,0($x)!lituse_base!y, don't use load_expression, since
3288 it is really too general for our needs. Instead just generate the
3292 || tok[0].X_op != O_register
3293 || !is_ir_num(tok[0].X_add_number)
3294 || tok[1].X_op != O_constant
3295 || tok[2].X_op != O_pregister
3296 || !is_ir_num(tok[2].X_add_number))
3298 as_bad (_("bad instruction format for lda !%s!%ld"), r->name,
3299 (long) reloc->X_add_number);
3301 reloc = (const expressionS *)0;
3306 emit_loadstore (tok, ntok, "lda");
3313 basereg = (tok[1].X_op == O_constant ? AXP_REG_ZERO : alpha_gp_register);
3315 basereg = tok[2].X_add_number;
3317 (void) load_expression (tok[0].X_add_number, &tok[1], &basereg, NULL, reloc);
3320 /* The ldah macro differs from the ldah instruction in that it has $31
3321 as an implied base register. */
3324 emit_ldah (tok, ntok, unused)
3325 const expressionS *tok;
3326 int ntok ATTRIBUTE_UNUSED;
3327 const PTR unused ATTRIBUTE_UNUSED;
3329 expressionS newtok[3];
3332 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
3334 const expressionS *reloc_exp = &tok[ntok-1];
3335 const struct alpha_reloc_op_tag *r = ALPHA_RELOC_TABLE (reloc_exp->X_op);
3336 as_bad (_("Cannot use !%s!%d with %s"), r->name,
3337 (int)reloc_exp->X_add_number, "ldah");
3344 set_tok_preg (newtok[2], AXP_REG_ZERO);
3346 assemble_tokens ("ldah", newtok, 3, 0);
3349 /* Handle all "simple" integer register loads -- ldq, ldq_l, ldq_u,
3350 etc. They differ from the real instructions in that they do simple
3351 expressions like the lda macro. */
3354 emit_ir_load (tok, ntok, opname)
3355 const expressionS *tok;
3359 int basereg, lituse;
3360 expressionS newtok[3];
3361 struct alpha_insn insn;
3364 const expressionS *reloc = (const expressionS *)0;
3366 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
3368 const struct alpha_reloc_op_tag *r;
3370 reloc = &tok[ntok-1];
3371 switch (reloc->X_op)
3378 if (strcmp ((const char *)opname, "ldq") == 0)
3380 emit_lda (tok, ntok, opname);
3387 r = ALPHA_RELOC_TABLE (reloc->X_op);
3388 as_bad (_("Cannot use !%s!%d with %s"), r->name,
3389 (int)reloc->X_add_number, (const char *)opname);
3395 basereg = (tok[1].X_op == O_constant ? AXP_REG_ZERO : alpha_gp_register);
3397 basereg = tok[2].X_add_number;
3399 lituse = load_expression (tok[0].X_add_number, &tok[1], &basereg,
3400 &newtok[1], (const expressionS *)0);
3403 set_tok_preg (newtok[2], basereg);
3405 assemble_tokens_to_insn ((const char *)opname, newtok, 3, &insn);
3410 int nfixups = insn.nfixups;
3411 const struct alpha_reloc_op_tag *r = ALPHA_RELOC_TABLE (reloc->X_op);
3413 assert (nfixups < MAX_INSN_FIXUPS);
3414 insn.fixups[nfixups].reloc = r->reloc;
3415 insn.fixups[nfixups].exp.X_op = O_symbol;
3416 insn.fixups[nfixups].exp.X_add_symbol = section_symbol (now_seg);
3417 insn.fixups[nfixups].exp.X_add_number = r->lituse;
3418 insn.sequence[nfixups] = reloc->X_add_number;
3425 assert (insn.nfixups < MAX_INSN_FIXUPS);
3426 if (insn.nfixups > 0)
3428 memmove (&insn.fixups[1], &insn.fixups[0],
3429 sizeof (struct alpha_fixup) * insn.nfixups);
3432 insn.fixups[0].reloc = BFD_RELOC_ALPHA_LITUSE;
3433 insn.fixups[0].exp.X_op = O_symbol;
3434 insn.fixups[0].exp.X_add_symbol = section_symbol (now_seg);
3435 insn.fixups[0].exp.X_add_number = LITUSE_BASE;
3441 /* Handle fp register loads, and both integer and fp register stores.
3442 Again, we handle simple expressions. */
3445 emit_loadstore (tok, ntok, opname)
3446 const expressionS *tok;
3450 int basereg, lituse;
3451 expressionS newtok[3];
3452 struct alpha_insn insn;
3455 const expressionS *reloc = (const expressionS *)0;
3457 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
3459 reloc = &tok[--ntok];
3460 if (reloc->X_op != O_lituse_base)
3462 const struct alpha_reloc_op_tag *r = &alpha_reloc_op[ reloc->X_md ];
3463 as_bad (_("Cannot use !%s!%d with %s"), r->name,
3464 (int)reloc->X_add_number, (const char *)opname);
3470 basereg = (tok[1].X_op == O_constant ? AXP_REG_ZERO : alpha_gp_register);
3472 basereg = tok[2].X_add_number;
3474 if (tok[1].X_op != O_constant || !range_signed_16(tok[1].X_add_number))
3477 as_bad (_("macro requires $at register while noat in effect"));
3479 lituse = load_expression (AXP_REG_AT, &tok[1], &basereg, &newtok[1],
3480 (const expressionS *)0);
3489 set_tok_preg (newtok[2], basereg);
3491 assemble_tokens_to_insn ((const char *)opname, newtok, 3, &insn);
3496 int nfixups = insn.nfixups;
3497 const struct alpha_reloc_op_tag *r = ALPHA_RELOC_TABLE (reloc->X_op);
3499 assert (nfixups < MAX_INSN_FIXUPS);
3500 insn.fixups[nfixups].reloc = r->reloc;
3501 insn.fixups[nfixups].exp.X_op = O_symbol;
3502 insn.fixups[nfixups].exp.X_add_symbol = section_symbol (now_seg);
3503 insn.fixups[nfixups].exp.X_add_number = r->lituse;
3504 insn.sequence[nfixups] = reloc->X_add_number;
3511 assert (insn.nfixups < MAX_INSN_FIXUPS);
3512 if (insn.nfixups > 0)
3514 memmove (&insn.fixups[1], &insn.fixups[0],
3515 sizeof (struct alpha_fixup) * insn.nfixups);
3518 insn.fixups[0].reloc = BFD_RELOC_ALPHA_LITUSE;
3519 insn.fixups[0].exp.X_op = O_symbol;
3520 insn.fixups[0].exp.X_add_symbol = section_symbol (now_seg);
3521 insn.fixups[0].exp.X_add_number = LITUSE_BASE;
3527 /* Load a half-word or byte as an unsigned value. */
3530 emit_ldXu (tok, ntok, vlgsize)
3531 const expressionS *tok;
3535 if (alpha_target & AXP_OPCODE_BWX)
3536 emit_ir_load (tok, ntok, ldXu_op[(long)vlgsize]);
3539 expressionS newtok[3];
3542 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
3544 const expressionS *reloc_exp = &tok[ntok-1];
3545 const struct alpha_reloc_op_tag *r
3546 = ALPHA_RELOC_TABLE (reloc_exp->X_op);
3548 as_bad (_("Cannot use !%s!%d with %s"), r->name,
3549 (int)reloc_exp->X_add_number, "ldbu/ldwu");
3555 as_bad (_("macro requires $at register while noat in effect"));
3557 /* emit "lda $at, exp" */
3559 memcpy (newtok, tok, sizeof (expressionS) * ntok);
3560 newtok[0].X_add_number = AXP_REG_AT;
3561 assemble_tokens ("lda", newtok, ntok, 1);
3563 /* emit "ldq_u targ, 0($at)" */
3566 set_tok_const (newtok[1], 0);
3567 set_tok_preg (newtok[2], AXP_REG_AT);
3568 assemble_tokens ("ldq_u", newtok, 3, 1);
3570 /* emit "extXl targ, $at, targ" */
3572 set_tok_reg (newtok[1], AXP_REG_AT);
3573 newtok[2] = newtok[0];
3574 assemble_tokens (extXl_op[(long)vlgsize], newtok, 3, 1);
3578 /* Load a half-word or byte as a signed value. */
3581 emit_ldX (tok, ntok, vlgsize)
3582 const expressionS *tok;
3586 emit_ldXu (tok, ntok, vlgsize);
3587 assemble_tokens (sextX_op[(long)vlgsize], tok, 1, 1);
3590 /* Load an integral value from an unaligned address as an unsigned
3594 emit_uldXu (tok, ntok, vlgsize)
3595 const expressionS *tok;
3599 long lgsize = (long)vlgsize;
3600 expressionS newtok[3];
3603 as_bad (_("macro requires $at register while noat in effect"));
3605 /* emit "lda $at, exp" */
3607 memcpy (newtok, tok, sizeof (expressionS) * ntok);
3608 newtok[0].X_add_number = AXP_REG_AT;
3609 assemble_tokens ("lda", newtok, ntok, 1);
3611 /* emit "ldq_u $t9, 0($at)" */
3613 set_tok_reg (newtok[0], AXP_REG_T9);
3614 set_tok_const (newtok[1], 0);
3615 set_tok_preg (newtok[2], AXP_REG_AT);
3616 assemble_tokens ("ldq_u", newtok, 3, 1);
3618 /* emit "ldq_u $t10, size-1($at)" */
3620 set_tok_reg (newtok[0], AXP_REG_T10);
3621 set_tok_const (newtok[1], (1<<lgsize)-1);
3622 assemble_tokens ("ldq_u", newtok, 3, 1);
3624 /* emit "extXl $t9, $at, $t9" */
3626 set_tok_reg (newtok[0], AXP_REG_T9);
3627 set_tok_reg (newtok[1], AXP_REG_AT);
3628 set_tok_reg (newtok[2], AXP_REG_T9);
3629 assemble_tokens (extXl_op[lgsize], newtok, 3, 1);
3631 /* emit "extXh $t10, $at, $t10" */
3633 set_tok_reg (newtok[0], AXP_REG_T10);
3634 set_tok_reg (newtok[2], AXP_REG_T10);
3635 assemble_tokens (extXh_op[lgsize], newtok, 3, 1);
3637 /* emit "or $t9, $t10, targ" */
3639 set_tok_reg (newtok[0], AXP_REG_T9);
3640 set_tok_reg (newtok[1], AXP_REG_T10);
3642 assemble_tokens ("or", newtok, 3, 1);
3645 /* Load an integral value from an unaligned address as a signed value.
3646 Note that quads should get funneled to the unsigned load since we
3647 don't have to do the sign extension. */
3650 emit_uldX (tok, ntok, vlgsize)
3651 const expressionS *tok;
3655 emit_uldXu (tok, ntok, vlgsize);
3656 assemble_tokens (sextX_op[(long)vlgsize], tok, 1, 1);
3659 /* Implement the ldil macro. */
3662 emit_ldil (tok, ntok, unused)
3663 const expressionS *tok;
3665 const PTR unused ATTRIBUTE_UNUSED;
3667 expressionS newtok[2];
3670 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
3672 const expressionS *reloc_exp = &tok[ntok-1];
3673 const struct alpha_reloc_op_tag *r = ALPHA_RELOC_TABLE (reloc_exp->X_op);
3674 as_bad (_("Cannot use !%s!%d with %s"), r->name,
3675 (int)reloc_exp->X_add_number, "ldil");
3680 memcpy (newtok, tok, sizeof (newtok));
3681 newtok[1].X_add_number = sign_extend_32 (tok[1].X_add_number);
3683 assemble_tokens ("lda", newtok, ntok, 1);
3686 /* Store a half-word or byte. */
3689 emit_stX (tok, ntok, vlgsize)
3690 const expressionS *tok;
3694 int lgsize = (int) (long)vlgsize;
3696 if (alpha_target & AXP_OPCODE_BWX)
3697 emit_loadstore (tok, ntok, stX_op[lgsize]);
3700 expressionS newtok[3];
3703 as_bad(_("macro requires $at register while noat in effect"));
3705 /* emit "lda $at, exp" */
3707 memcpy (newtok, tok, sizeof (expressionS) * ntok);
3708 newtok[0].X_add_number = AXP_REG_AT;
3709 assemble_tokens ("lda", newtok, ntok, 1);
3711 /* emit "ldq_u $t9, 0($at)" */
3713 set_tok_reg (newtok[0], AXP_REG_T9);
3714 set_tok_const (newtok[1], 0);
3715 set_tok_preg (newtok[2], AXP_REG_AT);
3716 assemble_tokens ("ldq_u", newtok, 3, 1);
3718 /* emit "insXl src, $at, $t10" */
3721 set_tok_reg (newtok[1], AXP_REG_AT);
3722 set_tok_reg (newtok[2], AXP_REG_T10);
3723 assemble_tokens (insXl_op[lgsize], newtok, 3, 1);
3725 /* emit "mskXl $t9, $at, $t9" */
3727 set_tok_reg (newtok[0], AXP_REG_T9);
3728 newtok[2] = newtok[0];
3729 assemble_tokens (mskXl_op[lgsize], newtok, 3, 1);
3731 /* emit "or $t9, $t10, $t9" */
3733 set_tok_reg (newtok[1], AXP_REG_T10);
3734 assemble_tokens ("or", newtok, 3, 1);
3736 /* emit "stq_u $t9, 0($at) */
3738 set_tok_const (newtok[1], 0);
3739 set_tok_preg (newtok[2], AXP_REG_AT);
3740 assemble_tokens ("stq_u", newtok, 3, 1);
3744 /* Store an integer to an unaligned address. */
3747 emit_ustX (tok, ntok, vlgsize)
3748 const expressionS *tok;
3752 int lgsize = (int) (long)vlgsize;
3753 expressionS newtok[3];
3755 /* emit "lda $at, exp" */
3757 memcpy (newtok, tok, sizeof (expressionS) * ntok);
3758 newtok[0].X_add_number = AXP_REG_AT;
3759 assemble_tokens ("lda", newtok, ntok, 1);
3761 /* emit "ldq_u $9, 0($at)" */
3763 set_tok_reg (newtok[0], AXP_REG_T9);
3764 set_tok_const (newtok[1], 0);
3765 set_tok_preg (newtok[2], AXP_REG_AT);
3766 assemble_tokens ("ldq_u", newtok, 3, 1);
3768 /* emit "ldq_u $10, size-1($at)" */
3770 set_tok_reg (newtok[0], AXP_REG_T10);
3771 set_tok_const (newtok[1], (1 << lgsize)-1);
3772 assemble_tokens ("ldq_u", newtok, 3, 1);
3774 /* emit "insXl src, $at, $t11" */
3777 set_tok_reg (newtok[1], AXP_REG_AT);
3778 set_tok_reg (newtok[2], AXP_REG_T11);
3779 assemble_tokens (insXl_op[lgsize], newtok, 3, 1);
3781 /* emit "insXh src, $at, $t12" */
3783 set_tok_reg (newtok[2], AXP_REG_T12);
3784 assemble_tokens (insXh_op[lgsize], newtok, 3, 1);
3786 /* emit "mskXl $t9, $at, $t9" */
3788 set_tok_reg (newtok[0], AXP_REG_T9);
3789 newtok[2] = newtok[0];
3790 assemble_tokens (mskXl_op[lgsize], newtok, 3, 1);
3792 /* emit "mskXh $t10, $at, $t10" */
3794 set_tok_reg (newtok[0], AXP_REG_T10);
3795 newtok[2] = newtok[0];
3796 assemble_tokens (mskXh_op[lgsize], newtok, 3, 1);
3798 /* emit "or $t9, $t11, $t9" */
3800 set_tok_reg (newtok[0], AXP_REG_T9);
3801 set_tok_reg (newtok[1], AXP_REG_T11);
3802 newtok[2] = newtok[0];
3803 assemble_tokens ("or", newtok, 3, 1);
3805 /* emit "or $t10, $t12, $t10" */
3807 set_tok_reg (newtok[0], AXP_REG_T10);
3808 set_tok_reg (newtok[1], AXP_REG_T12);
3809 newtok[2] = newtok[0];
3810 assemble_tokens ("or", newtok, 3, 1);
3812 /* emit "stq_u $t9, 0($at)" */
3814 set_tok_reg (newtok[0], AXP_REG_T9);
3815 set_tok_const (newtok[1], 0);
3816 set_tok_preg (newtok[2], AXP_REG_AT);
3817 assemble_tokens ("stq_u", newtok, 3, 1);
3819 /* emit "stq_u $t10, size-1($at)" */
3821 set_tok_reg (newtok[0], AXP_REG_T10);
3822 set_tok_const (newtok[1], (1 << lgsize)-1);
3823 assemble_tokens ("stq_u", newtok, 3, 1);
3826 /* Sign extend a half-word or byte. The 32-bit sign extend is
3827 implemented as "addl $31, $r, $t" in the opcode table. */
3830 emit_sextX (tok, ntok, vlgsize)
3831 const expressionS *tok;
3835 long lgsize = (long)vlgsize;
3837 if (alpha_target & AXP_OPCODE_BWX)
3838 assemble_tokens (sextX_op[lgsize], tok, ntok, 0);
3841 int bitshift = 64 - 8 * (1 << lgsize);
3842 expressionS newtok[3];
3845 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
3847 const expressionS *reloc_exp = &tok[ntok-1];
3848 const struct alpha_reloc_op_tag *r
3849 = ALPHA_RELOC_TABLE (reloc_exp->X_op);
3851 as_bad (_("Cannot use !%s!%d with %s"), r->name,
3852 (int)reloc_exp->X_add_number, "setxt");
3857 /* emit "sll src,bits,dst" */
3860 set_tok_const (newtok[1], bitshift);
3861 newtok[2] = tok[ntok - 1];
3862 assemble_tokens ("sll", newtok, 3, 1);
3864 /* emit "sra dst,bits,dst" */
3866 newtok[0] = newtok[2];
3867 assemble_tokens ("sra", newtok, 3, 1);
3871 /* Implement the division and modulus macros. */
3875 /* Make register usage like in normal procedure call.
3876 Don't clobber PV and RA. */
3879 emit_division (tok, ntok, symname)
3880 const expressionS *tok;
3884 /* DIVISION and MODULUS. Yech.
3889 * mov x,R16 # if x != R16
3890 * mov y,R17 # if y != R17
3895 * with appropriate optimizations if R0,R16,R17 are the registers
3896 * specified by the compiler.
3901 expressionS newtok[3];
3904 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
3906 const expressionS *reloc_exp = &tok[ntok-1];
3907 const struct alpha_reloc_op_tag *r = ALPHA_RELOC_TABLE (reloc_exp->X_op);
3908 as_bad (_("Cannot use !%s!%d with %s"), r->name,
3909 (int)reloc_exp->X_add_number, (char char *)symname);
3914 xr = regno (tok[0].X_add_number);
3915 yr = regno (tok[1].X_add_number);
3920 rr = regno (tok[2].X_add_number);
3922 /* Move the operands into the right place */
3923 if (yr == AXP_REG_R16 && xr == AXP_REG_R17)
3925 /* They are in exactly the wrong order -- swap through AT */
3928 as_bad (_("macro requires $at register while noat in effect"));
3930 set_tok_reg (newtok[0], AXP_REG_R16);
3931 set_tok_reg (newtok[1], AXP_REG_AT);
3932 assemble_tokens ("mov", newtok, 2, 1);
3934 set_tok_reg (newtok[0], AXP_REG_R17);
3935 set_tok_reg (newtok[1], AXP_REG_R16);
3936 assemble_tokens ("mov", newtok, 2, 1);
3938 set_tok_reg (newtok[0], AXP_REG_AT);
3939 set_tok_reg (newtok[1], AXP_REG_R17);
3940 assemble_tokens ("mov", newtok, 2, 1);
3944 if (yr == AXP_REG_R16)
3946 set_tok_reg (newtok[0], AXP_REG_R16);
3947 set_tok_reg (newtok[1], AXP_REG_R17);
3948 assemble_tokens ("mov", newtok, 2, 1);
3951 if (xr != AXP_REG_R16)
3953 set_tok_reg (newtok[0], xr);
3954 set_tok_reg (newtok[1], AXP_REG_R16);
3955 assemble_tokens ("mov", newtok, 2, 1);
3958 if (yr != AXP_REG_R16 && yr != AXP_REG_R17)
3960 set_tok_reg (newtok[0], yr);
3961 set_tok_reg (newtok[1], AXP_REG_R17);
3962 assemble_tokens ("mov", newtok, 2, 1);
3966 sym = symbol_find_or_make ((const char *)symname);
3968 set_tok_reg (newtok[0], AXP_REG_AT);
3969 set_tok_sym (newtok[1], sym, 0);
3970 assemble_tokens ("lda", newtok, 2, 1);
3972 /* Call the division routine */
3973 set_tok_reg (newtok[0], AXP_REG_AT);
3974 set_tok_cpreg (newtok[1], AXP_REG_AT);
3975 set_tok_const (newtok[2], 0);
3976 assemble_tokens ("jsr", newtok, 3, 1);
3978 /* Move the result to the right place */
3979 if (rr != AXP_REG_R0)
3981 set_tok_reg (newtok[0], AXP_REG_R0);
3982 set_tok_reg (newtok[1], rr);
3983 assemble_tokens ("mov", newtok, 2, 1);
3987 #else /* !OBJ_EVAX */
3990 emit_division (tok, ntok, symname)
3991 const expressionS *tok;
3995 /* DIVISION and MODULUS. Yech.
4005 * with appropriate optimizations if t10,t11,t12 are the registers
4006 * specified by the compiler.
4011 expressionS newtok[3];
4014 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
4016 const expressionS *reloc_exp = &tok[ntok-1];
4017 const struct alpha_reloc_op_tag *r = ALPHA_RELOC_TABLE (reloc_exp->X_op);
4018 as_bad (_("Cannot use !%s!%d with %s"), r->name,
4019 (int)reloc_exp->X_add_number, (const char *)symname);
4024 xr = regno (tok[0].X_add_number);
4025 yr = regno (tok[1].X_add_number);
4030 rr = regno (tok[2].X_add_number);
4032 sym = symbol_find_or_make ((const char *)symname);
4034 /* Move the operands into the right place */
4035 if (yr == AXP_REG_T10 && xr == AXP_REG_T11)
4037 /* They are in exactly the wrong order -- swap through AT */
4040 as_bad (_("macro requires $at register while noat in effect"));
4042 set_tok_reg (newtok[0], AXP_REG_T10);
4043 set_tok_reg (newtok[1], AXP_REG_AT);
4044 assemble_tokens ("mov", newtok, 2, 1);
4046 set_tok_reg (newtok[0], AXP_REG_T11);
4047 set_tok_reg (newtok[1], AXP_REG_T10);
4048 assemble_tokens ("mov", newtok, 2, 1);
4050 set_tok_reg (newtok[0], AXP_REG_AT);
4051 set_tok_reg (newtok[1], AXP_REG_T11);
4052 assemble_tokens ("mov", newtok, 2, 1);
4056 if (yr == AXP_REG_T10)
4058 set_tok_reg (newtok[0], AXP_REG_T10);
4059 set_tok_reg (newtok[1], AXP_REG_T11);
4060 assemble_tokens ("mov", newtok, 2, 1);
4063 if (xr != AXP_REG_T10)
4065 set_tok_reg (newtok[0], xr);
4066 set_tok_reg (newtok[1], AXP_REG_T10);
4067 assemble_tokens ("mov", newtok, 2, 1);
4070 if (yr != AXP_REG_T10 && yr != AXP_REG_T11)
4072 set_tok_reg (newtok[0], yr);
4073 set_tok_reg (newtok[1], AXP_REG_T11);
4074 assemble_tokens ("mov", newtok, 2, 1);
4078 /* Call the division routine */
4079 set_tok_reg (newtok[0], AXP_REG_T9);
4080 set_tok_sym (newtok[1], sym, 0);
4081 assemble_tokens ("jsr", newtok, 2, 1);
4083 /* Reload the GP register */
4087 #if defined(OBJ_ECOFF) || defined(OBJ_ELF)
4088 set_tok_reg (newtok[0], alpha_gp_register);
4089 set_tok_const (newtok[1], 0);
4090 set_tok_preg (newtok[2], AXP_REG_T9);
4091 assemble_tokens ("ldgp", newtok, 3, 1);
4094 /* Move the result to the right place */
4095 if (rr != AXP_REG_T12)
4097 set_tok_reg (newtok[0], AXP_REG_T12);
4098 set_tok_reg (newtok[1], rr);
4099 assemble_tokens ("mov", newtok, 2, 1);
4103 #endif /* !OBJ_EVAX */
4105 /* The jsr and jmp macros differ from their instruction counterparts
4106 in that they can load the target address and default most
4110 emit_jsrjmp (tok, ntok, vopname)
4111 const expressionS *tok;
4115 const char *opname = (const char *) vopname;
4116 struct alpha_insn insn;
4117 expressionS newtok[3];
4118 int r, tokidx = 0, lituse = 0;
4121 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
4123 const expressionS *reloc_exp = &tok[ntok-1];
4124 const struct alpha_reloc_op_tag *r = ALPHA_RELOC_TABLE (reloc_exp->X_op);
4125 as_bad (_("Cannot use !%s!%d with %s"), r->name,
4126 (int)reloc_exp->X_add_number, opname);
4131 if (tokidx < ntok && tok[tokidx].X_op == O_register)
4132 r = regno (tok[tokidx++].X_add_number);
4134 r = strcmp (opname, "jmp") == 0 ? AXP_REG_ZERO : AXP_REG_RA;
4136 set_tok_reg (newtok[0], r);
4138 if (tokidx < ntok &&
4139 (tok[tokidx].X_op == O_pregister || tok[tokidx].X_op == O_cpregister))
4140 r = regno (tok[tokidx++].X_add_number);
4142 /* keep register if jsr $n.<sym> */
4146 int basereg = alpha_gp_register;
4147 lituse = load_expression (r = AXP_REG_PV, &tok[tokidx], &basereg, NULL,
4148 (const expressionS *)0);
4152 set_tok_cpreg (newtok[1], r);
4155 /* FIXME: Add hint relocs to BFD for evax. */
4158 newtok[2] = tok[tokidx];
4161 set_tok_const (newtok[2], 0);
4163 assemble_tokens_to_insn (opname, newtok, 3, &insn);
4165 /* add the LITUSE fixup */
4168 assert (insn.nfixups < MAX_INSN_FIXUPS);
4169 if (insn.nfixups > 0)
4171 memmove (&insn.fixups[1], &insn.fixups[0],
4172 sizeof (struct alpha_fixup) * insn.nfixups);
4175 insn.fixups[0].reloc = BFD_RELOC_ALPHA_LITUSE;
4176 insn.fixups[0].exp.X_op = O_symbol;
4177 insn.fixups[0].exp.X_add_symbol = section_symbol (now_seg);
4178 insn.fixups[0].exp.X_add_number = LITUSE_JSR;
4184 /* The ret and jcr instructions differ from their instruction
4185 counterparts in that everything can be defaulted. */
4188 emit_retjcr (tok, ntok, vopname)
4189 const expressionS *tok;
4193 const char *opname = (const char *)vopname;
4194 expressionS newtok[3];
4198 if (ntok && USER_RELOC_P (tok[ntok-1].X_op))
4200 const expressionS *reloc_exp = &tok[ntok-1];
4201 const struct alpha_reloc_op_tag *r = ALPHA_RELOC_TABLE (reloc_exp->X_op);
4202 as_bad (_("Cannot use !%s!%d with %s"), r->name,
4203 (int)reloc_exp->X_add_number, opname);
4208 if (tokidx < ntok && tok[tokidx].X_op == O_register)
4209 r = regno (tok[tokidx++].X_add_number);
4213 set_tok_reg (newtok[0], r);
4215 if (tokidx < ntok &&
4216 (tok[tokidx].X_op == O_pregister || tok[tokidx].X_op == O_cpregister))
4217 r = regno (tok[tokidx++].X_add_number);
4221 set_tok_cpreg (newtok[1], r);
4224 newtok[2] = tok[tokidx];
4226 set_tok_const (newtok[2], strcmp(opname, "ret") == 0);
4228 assemble_tokens (opname, newtok, 3, 0);
4231 /* Assembler directives */
4233 /* Handle the .text pseudo-op. This is like the usual one, but it
4234 clears alpha_insn_label and restores auto alignment. */
4242 alpha_insn_label = NULL;
4243 alpha_auto_align_on = 1;
4244 alpha_current_align = 0;
4247 /* Handle the .data pseudo-op. This is like the usual one, but it
4248 clears alpha_insn_label and restores auto alignment. */
4255 alpha_insn_label = NULL;
4256 alpha_auto_align_on = 1;
4257 alpha_current_align = 0;
4260 #if defined (OBJ_ECOFF) || defined (OBJ_EVAX)
4262 /* Handle the OSF/1 and openVMS .comm pseudo quirks.
4263 openVMS constructs a section for every common symbol. */
4266 s_alpha_comm (ignore)
4269 register char *name;
4273 register symbolS *symbolP;
4276 segT current_section = now_seg;
4277 int current_subsec = now_subseg;
4281 name = input_line_pointer;
4282 c = get_symbol_end ();
4284 /* just after name is now '\0' */
4285 p = input_line_pointer;
4290 /* Alpha OSF/1 compiler doesn't provide the comma, gcc does. */
4291 if (*input_line_pointer == ',')
4293 input_line_pointer++;
4296 if ((temp = get_absolute_expression ()) < 0)
4298 as_warn (_(".COMMon length (%ld.) <0! Ignored."), (long) temp);
4299 ignore_rest_of_line ();
4304 symbolP = symbol_find_or_make (name);
4307 /* Make a section for the common symbol. */
4308 new_seg = subseg_new (xstrdup (name), 0);
4314 /* alignment might follow */
4315 if (*input_line_pointer == ',')
4319 input_line_pointer++;
4320 align = get_absolute_expression ();
4321 bfd_set_section_alignment (stdoutput, new_seg, align);
4325 if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))
4327 as_bad (_("Ignoring attempt to re-define symbol"));
4328 ignore_rest_of_line ();
4333 if (bfd_section_size (stdoutput, new_seg) > 0)
4335 if (bfd_section_size (stdoutput, new_seg) != temp)
4336 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4337 S_GET_NAME (symbolP),
4338 (long) bfd_section_size (stdoutput, new_seg),
4342 if (S_GET_VALUE (symbolP))
4344 if (S_GET_VALUE (symbolP) != (valueT) temp)
4345 as_bad (_("Length of .comm \"%s\" is already %ld. Not changed to %ld."),
4346 S_GET_NAME (symbolP),
4347 (long) S_GET_VALUE (symbolP),
4354 subseg_set (new_seg, 0);
4355 p = frag_more (temp);
4356 new_seg->flags |= SEC_IS_COMMON;
4357 if (! S_IS_DEFINED (symbolP))
4358 S_SET_SEGMENT (symbolP, new_seg);
4360 S_SET_VALUE (symbolP, (valueT) temp);
4362 S_SET_EXTERNAL (symbolP);
4366 subseg_set (current_section, current_subsec);
4369 know (symbol_get_frag (symbolP) == &zero_address_frag);
4371 demand_empty_rest_of_line ();
4374 #endif /* ! OBJ_ELF */
4378 /* Handle the .rdata pseudo-op. This is like the usual one, but it
4379 clears alpha_insn_label and restores auto alignment. */
4382 s_alpha_rdata (ignore)
4387 temp = get_absolute_expression ();
4388 subseg_new (".rdata", 0);
4389 demand_empty_rest_of_line ();
4390 alpha_insn_label = NULL;
4391 alpha_auto_align_on = 1;
4392 alpha_current_align = 0;
4399 /* Handle the .sdata pseudo-op. This is like the usual one, but it
4400 clears alpha_insn_label and restores auto alignment. */
4403 s_alpha_sdata (ignore)
4408 temp = get_absolute_expression ();
4409 subseg_new (".sdata", 0);
4410 demand_empty_rest_of_line ();
4411 alpha_insn_label = NULL;
4412 alpha_auto_align_on = 1;
4413 alpha_current_align = 0;
4419 /* Handle the .section pseudo-op. This is like the usual one, but it
4420 clears alpha_insn_label and restores auto alignment. */
4423 s_alpha_section (ignore)
4426 obj_elf_section (ignore);
4428 alpha_insn_label = NULL;
4429 alpha_auto_align_on = 1;
4430 alpha_current_align = 0;
4435 int dummy ATTRIBUTE_UNUSED;
4437 if (ECOFF_DEBUGGING)
4438 ecoff_directive_ent (0);
4441 char *name, name_end;
4442 name = input_line_pointer;
4443 name_end = get_symbol_end ();
4445 if (! is_name_beginner (*name))
4447 as_warn (_(".ent directive has no name"));
4448 *input_line_pointer = name_end;
4454 if (alpha_cur_ent_sym)
4455 as_warn (_("nested .ent directives"));
4457 sym = symbol_find_or_make (name);
4458 symbol_get_bfdsym (sym)->flags |= BSF_FUNCTION;
4459 alpha_cur_ent_sym = sym;
4461 /* The .ent directive is sometimes followed by a number. Not sure
4462 what it really means, but ignore it. */
4463 *input_line_pointer = name_end;
4465 if (*input_line_pointer == ',')
4467 input_line_pointer++;
4470 if (isdigit (*input_line_pointer) || *input_line_pointer == '-')
4471 (void) get_absolute_expression ();
4473 demand_empty_rest_of_line ();
4479 int dummy ATTRIBUTE_UNUSED;
4481 if (ECOFF_DEBUGGING)
4482 ecoff_directive_end (0);
4485 char *name, name_end;
4486 name = input_line_pointer;
4487 name_end = get_symbol_end ();
4489 if (! is_name_beginner (*name))
4491 as_warn (_(".end directive has no name"));
4492 *input_line_pointer = name_end;
4498 sym = symbol_find (name);
4499 if (sym != alpha_cur_ent_sym)
4500 as_warn (_(".end directive names different symbol than .ent"));
4502 /* Create an expression to calculate the size of the function. */
4505 symbol_get_obj (sym)->size =
4506 (expressionS *) xmalloc (sizeof (expressionS));
4507 symbol_get_obj (sym)->size->X_op = O_subtract;
4508 symbol_get_obj (sym)->size->X_add_symbol
4509 = symbol_new ("L0\001", now_seg, frag_now_fix (), frag_now);
4510 symbol_get_obj (sym)->size->X_op_symbol = sym;
4511 symbol_get_obj (sym)->size->X_add_number = 0;
4514 alpha_cur_ent_sym = NULL;
4516 *input_line_pointer = name_end;
4518 demand_empty_rest_of_line ();
4526 if (ECOFF_DEBUGGING)
4529 ecoff_directive_fmask (0);
4531 ecoff_directive_mask (0);
4534 discard_rest_of_line ();
4538 s_alpha_frame (dummy)
4539 int dummy ATTRIBUTE_UNUSED;
4541 if (ECOFF_DEBUGGING)
4542 ecoff_directive_frame (0);
4544 discard_rest_of_line ();
4548 s_alpha_prologue (ignore)
4549 int ignore ATTRIBUTE_UNUSED;
4554 arg = get_absolute_expression ();
4555 demand_empty_rest_of_line ();
4557 if (ECOFF_DEBUGGING)
4558 sym = ecoff_get_cur_proc_sym ();
4560 sym = alpha_cur_ent_sym;
4565 case 0: /* No PV required. */
4566 S_SET_OTHER (sym, STO_ALPHA_NOPV
4567 | (S_GET_OTHER (sym) & ~STO_ALPHA_STD_GPLOAD));
4569 case 1: /* Std GP load. */
4570 S_SET_OTHER (sym, STO_ALPHA_STD_GPLOAD
4571 | (S_GET_OTHER (sym) & ~STO_ALPHA_STD_GPLOAD));
4573 case 2: /* Non-std use of PV. */
4577 as_bad (_("Invalid argument %d to .prologue."), arg);
4582 static char * first_file_directive;
4585 s_alpha_file (ignore)
4586 int ignore ATTRIBUTE_UNUSED;
4588 /* Save the first .file directive we see, so that we can change our
4589 minds about whether ecoff debugging should or shouldn't be enabled. */
4590 if (alpha_flag_mdebug < 0 && ! first_file_directive)
4592 char *start = input_line_pointer;
4595 discard_rest_of_line ();
4597 len = input_line_pointer - start;
4598 first_file_directive = xmalloc (len + 1);
4599 memcpy (first_file_directive, start, len);
4600 first_file_directive[len] = '\0';
4602 input_line_pointer = start;
4605 if (ECOFF_DEBUGGING)
4606 ecoff_directive_file (0);
4608 dwarf2_directive_file (0);
4612 s_alpha_loc (ignore)
4613 int ignore ATTRIBUTE_UNUSED;
4615 if (ECOFF_DEBUGGING)
4616 ecoff_directive_loc (0);
4618 dwarf2_directive_loc (0);
4625 /* If we've been undecided about mdebug, make up our minds in favour. */
4626 if (alpha_flag_mdebug < 0)
4628 segT sec = subseg_new(".mdebug", 0);
4629 bfd_set_section_flags(stdoutput, sec, SEC_HAS_CONTENTS|SEC_READONLY);
4630 bfd_set_section_alignment(stdoutput, sec, 3);
4632 ecoff_read_begin_hook ();
4634 if (first_file_directive)
4636 char *save_ilp = input_line_pointer;
4637 input_line_pointer = first_file_directive;
4638 ecoff_directive_file (0);
4639 input_line_pointer = save_ilp;
4640 free (first_file_directive);
4643 alpha_flag_mdebug = 1;
4649 s_alpha_coff_wrapper (which)
4652 static void (* const fns[]) PARAMS ((int)) = {
4653 ecoff_directive_begin,
4654 ecoff_directive_bend,
4655 ecoff_directive_def,
4656 ecoff_directive_dim,
4657 ecoff_directive_endef,
4658 ecoff_directive_scl,
4659 ecoff_directive_tag,
4660 ecoff_directive_val,
4663 assert (which >= 0 && which < (int) (sizeof (fns)/sizeof (*fns)));
4665 if (ECOFF_DEBUGGING)
4669 as_bad (_("ECOFF debugging is disabled."));
4670 ignore_rest_of_line ();
4673 #endif /* OBJ_ELF */
4677 /* Handle the section specific pseudo-op. */
4680 s_alpha_section (secid)
4684 #define EVAX_SECTION_COUNT 5
4685 static char *section_name[EVAX_SECTION_COUNT+1] =
4686 { "NULL", ".rdata", ".comm", ".link", ".ctors", ".dtors" };
4688 if ((secid <= 0) || (secid > EVAX_SECTION_COUNT))
4690 as_fatal (_("Unknown section directive"));
4691 demand_empty_rest_of_line ();
4694 temp = get_absolute_expression ();
4695 subseg_new (section_name[secid], 0);
4696 demand_empty_rest_of_line ();
4697 alpha_insn_label = NULL;
4698 alpha_auto_align_on = 1;
4699 alpha_current_align = 0;
4702 /* Parse .ent directives. */
4705 s_alpha_ent (ignore)
4709 expressionS symexpr;
4711 alpha_evax_proc.pdsckind = 0;
4712 alpha_evax_proc.framereg = -1;
4713 alpha_evax_proc.framesize = 0;
4714 alpha_evax_proc.rsa_offset = 0;
4715 alpha_evax_proc.ra_save = AXP_REG_RA;
4716 alpha_evax_proc.fp_save = -1;
4717 alpha_evax_proc.imask = 0;
4718 alpha_evax_proc.fmask = 0;
4719 alpha_evax_proc.prologue = 0;
4720 alpha_evax_proc.type = 0;
4722 expression (&symexpr);
4724 if (symexpr.X_op != O_symbol)
4726 as_fatal (_(".ent directive has no symbol"));
4727 demand_empty_rest_of_line ();
4731 symbol = make_expr_symbol (&symexpr);
4732 symbol_get_bfdsym (symbol)->flags |= BSF_FUNCTION;
4733 alpha_evax_proc.symbol = symbol;
4735 demand_empty_rest_of_line ();
4739 /* Parse .frame <framreg>,<framesize>,RA,<rsa_offset> directives. */
4742 s_alpha_frame (ignore)
4747 alpha_evax_proc.framereg = tc_get_register (1);
4750 if (*input_line_pointer++ != ','
4751 || get_absolute_expression_and_terminator (&val) != ',')
4753 as_warn (_("Bad .frame directive 1./2. param"));
4754 --input_line_pointer;
4755 demand_empty_rest_of_line ();
4759 alpha_evax_proc.framesize = val;
4761 (void) tc_get_register (1);
4763 if (*input_line_pointer++ != ',')
4765 as_warn (_("Bad .frame directive 3./4. param"));
4766 --input_line_pointer;
4767 demand_empty_rest_of_line ();
4770 alpha_evax_proc.rsa_offset = get_absolute_expression ();
4776 s_alpha_pdesc (ignore)
4786 segment_info_type *seginfo = seg_info (alpha_link_section);
4788 if (now_seg != alpha_link_section)
4790 as_bad (_(".pdesc directive not in link (.link) section"));
4791 demand_empty_rest_of_line ();
4795 if ((alpha_evax_proc.symbol == 0)
4796 || (!S_IS_DEFINED (alpha_evax_proc.symbol)))
4798 as_fatal (_(".pdesc has no matching .ent"));
4799 demand_empty_rest_of_line ();
4803 *symbol_get_obj (alpha_evax_proc.symbol) =
4804 (valueT) seginfo->literal_pool_size;
4807 if (exp.X_op != O_symbol)
4809 as_warn (_(".pdesc directive has no entry symbol"));
4810 demand_empty_rest_of_line ();
4814 entry_sym = make_expr_symbol (&exp);
4815 /* Save bfd symbol of proc desc in function symbol. */
4816 symbol_get_bfdsym (alpha_evax_proc.symbol)->udata.p
4817 = symbol_get_bfdsym (entry_sym);
4820 if (*input_line_pointer++ != ',')
4822 as_warn (_("No comma after .pdesc <entryname>"));
4823 demand_empty_rest_of_line ();
4828 name = input_line_pointer;
4829 name_end = get_symbol_end ();
4831 if (strncmp(name, "stack", 5) == 0)
4833 alpha_evax_proc.pdsckind = PDSC_S_K_KIND_FP_STACK;
4835 else if (strncmp(name, "reg", 3) == 0)
4837 alpha_evax_proc.pdsckind = PDSC_S_K_KIND_FP_REGISTER;
4839 else if (strncmp(name, "null", 4) == 0)
4841 alpha_evax_proc.pdsckind = PDSC_S_K_KIND_NULL;
4845 as_fatal (_("unknown procedure kind"));
4846 demand_empty_rest_of_line ();
4850 *input_line_pointer = name_end;
4851 demand_empty_rest_of_line ();
4853 #ifdef md_flush_pending_output
4854 md_flush_pending_output ();
4857 frag_align (3, 0, 0);
4859 fixp = fix_new (frag_now, p - frag_now->fr_literal, 8, 0, 0, 0, 0);
4861 seginfo->literal_pool_size += 16;
4863 *p = alpha_evax_proc.pdsckind
4864 | ((alpha_evax_proc.framereg == 29) ? PDSC_S_M_BASE_REG_IS_FP : 0);
4865 *(p+1) = PDSC_S_M_NATIVE
4866 | PDSC_S_M_NO_JACKET;
4868 switch (alpha_evax_proc.pdsckind)
4870 case PDSC_S_K_KIND_NULL:
4874 case PDSC_S_K_KIND_FP_REGISTER:
4875 *(p+2) = alpha_evax_proc.fp_save;
4876 *(p+3) = alpha_evax_proc.ra_save;
4878 case PDSC_S_K_KIND_FP_STACK:
4879 md_number_to_chars (p+2, (valueT)alpha_evax_proc.rsa_offset, 2);
4881 default: /* impossible */
4886 *(p+5) = alpha_evax_proc.type & 0x0f;
4888 /* Signature offset. */
4889 md_number_to_chars (p+6, (valueT)0, 2);
4891 fix_new_exp (frag_now, p-frag_now->fr_literal+8, 8, &exp, 0, BFD_RELOC_64);
4893 if (alpha_evax_proc.pdsckind == PDSC_S_K_KIND_NULL)
4896 /* Add dummy fix to make add_to_link_pool work. */
4898 fixp = fix_new (frag_now, p - frag_now->fr_literal, 8, 0, 0, 0, 0);
4900 seginfo->literal_pool_size += 8;
4902 /* pdesc+16: Size. */
4903 md_number_to_chars (p, (valueT)alpha_evax_proc.framesize, 4);
4905 md_number_to_chars (p+4, (valueT)0, 2);
4908 md_number_to_chars (p+6, alpha_evax_proc.prologue, 2);
4910 if (alpha_evax_proc.pdsckind == PDSC_S_K_KIND_FP_REGISTER)
4913 /* Add dummy fix to make add_to_link_pool work. */
4915 fixp = fix_new (frag_now, p - frag_now->fr_literal, 8, 0, 0, 0, 0);
4917 seginfo->literal_pool_size += 8;
4919 /* pdesc+24: register masks. */
4921 md_number_to_chars (p, alpha_evax_proc.imask, 4);
4922 md_number_to_chars (p+4, alpha_evax_proc.fmask, 4);
4927 /* Support for crash debug on vms. */
4930 s_alpha_name (ignore)
4935 segment_info_type *seginfo = seg_info (alpha_link_section);
4937 if (now_seg != alpha_link_section)
4939 as_bad (_(".name directive not in link (.link) section"));
4940 demand_empty_rest_of_line ();
4945 if (exp.X_op != O_symbol)
4947 as_warn (_(".name directive has no symbol"));
4948 demand_empty_rest_of_line ();
4952 demand_empty_rest_of_line ();
4954 #ifdef md_flush_pending_output
4955 md_flush_pending_output ();
4958 frag_align (3, 0, 0);
4960 seginfo->literal_pool_size += 8;
4962 fix_new_exp (frag_now, p-frag_now->fr_literal, 8, &exp, 0, BFD_RELOC_64);
4968 s_alpha_linkage (ignore)
4974 #ifdef md_flush_pending_output
4975 md_flush_pending_output ();
4979 if (exp.X_op != O_symbol)
4981 as_fatal (_("No symbol after .linkage"));
4985 p = frag_more (LKP_S_K_SIZE);
4986 memset (p, 0, LKP_S_K_SIZE);
4987 fix_new_exp (frag_now, p - frag_now->fr_literal, LKP_S_K_SIZE, &exp, 0,\
4988 BFD_RELOC_ALPHA_LINKAGE);
4990 demand_empty_rest_of_line ();
4996 s_alpha_code_address (ignore)
5002 #ifdef md_flush_pending_output
5003 md_flush_pending_output ();
5007 if (exp.X_op != O_symbol)
5009 as_fatal (_("No symbol after .code_address"));
5015 fix_new_exp (frag_now, p - frag_now->fr_literal, 8, &exp, 0,\
5016 BFD_RELOC_ALPHA_CODEADDR);
5018 demand_empty_rest_of_line ();
5024 s_alpha_fp_save (ignore)
5028 alpha_evax_proc.fp_save = tc_get_register (1);
5030 demand_empty_rest_of_line ();
5035 s_alpha_mask (ignore)
5040 if (get_absolute_expression_and_terminator (&val) != ',')
5042 as_warn (_("Bad .mask directive"));
5043 --input_line_pointer;
5047 alpha_evax_proc.imask = val;
5048 (void)get_absolute_expression ();
5050 demand_empty_rest_of_line ();
5056 s_alpha_fmask (ignore)
5061 if (get_absolute_expression_and_terminator (&val) != ',')
5063 as_warn (_("Bad .fmask directive"));
5064 --input_line_pointer;
5068 alpha_evax_proc.fmask = val;
5069 (void) get_absolute_expression ();
5071 demand_empty_rest_of_line ();
5077 s_alpha_end (ignore)
5082 c = get_symbol_end ();
5083 *input_line_pointer = c;
5084 demand_empty_rest_of_line ();
5085 alpha_evax_proc.symbol = 0;
5091 s_alpha_file (ignore)
5096 static char case_hack[32];
5098 extern char *demand_copy_string PARAMS ((int *lenP));
5100 sprintf (case_hack, "<CASE:%01d%01d>",
5101 alpha_flag_hash_long_names, alpha_flag_show_after_trunc);
5103 s = symbol_find_or_make (case_hack);
5104 symbol_get_bfdsym (s)->flags |= BSF_FILE;
5106 get_absolute_expression ();
5107 s = symbol_find_or_make (demand_copy_string (&length));
5108 symbol_get_bfdsym (s)->flags |= BSF_FILE;
5109 demand_empty_rest_of_line ();
5113 #endif /* OBJ_EVAX */
5115 /* Handle the .gprel32 pseudo op. */
5118 s_alpha_gprel32 (ignore)
5119 int ignore ATTRIBUTE_UNUSED;
5131 e.X_add_symbol = section_symbol(absolute_section);
5144 e.X_add_symbol = section_symbol (absolute_section);
5147 e.X_op = O_subtract;
5148 e.X_op_symbol = alpha_gp_symbol;
5156 if (alpha_auto_align_on && alpha_current_align < 2)
5157 alpha_align (2, (char *) NULL, alpha_insn_label, 0);
5158 if (alpha_current_align > 2)
5159 alpha_current_align = 2;
5160 alpha_insn_label = NULL;
5164 fix_new_exp (frag_now, p-frag_now->fr_literal, 4,
5165 &e, 0, BFD_RELOC_GPREL32);
5168 /* Handle floating point allocation pseudo-ops. This is like the
5169 generic vresion, but it makes sure the current label, if any, is
5170 correctly aligned. */
5173 s_alpha_float_cons (type)
5200 if (alpha_auto_align_on && alpha_current_align < log_size)
5201 alpha_align (log_size, (char *) NULL, alpha_insn_label, 0);
5202 if (alpha_current_align > log_size)
5203 alpha_current_align = log_size;
5204 alpha_insn_label = NULL;
5209 /* Handle the .proc pseudo op. We don't really do much with it except
5213 s_alpha_proc (is_static)
5214 int is_static ATTRIBUTE_UNUSED;
5222 /* Takes ".proc name,nargs" */
5224 name = input_line_pointer;
5225 c = get_symbol_end ();
5226 p = input_line_pointer;
5227 symbolP = symbol_find_or_make (name);
5230 if (*input_line_pointer != ',')
5233 as_warn (_("Expected comma after name \"%s\""), name);
5236 ignore_rest_of_line ();
5240 input_line_pointer++;
5241 temp = get_absolute_expression ();
5243 /* *symbol_get_obj (symbolP) = (signed char) temp; */
5244 as_warn (_("unhandled: .proc %s,%d"), name, temp);
5245 demand_empty_rest_of_line ();
5248 /* Handle the .set pseudo op. This is used to turn on and off most of
5249 the assembler features. */
5253 int x ATTRIBUTE_UNUSED;
5259 name = input_line_pointer;
5260 ch = get_symbol_end ();
5263 if (s[0] == 'n' && s[1] == 'o')
5268 if (!strcmp ("reorder", s))
5270 else if (!strcmp ("at", s))
5271 alpha_noat_on = !yesno;
5272 else if (!strcmp ("macro", s))
5273 alpha_macros_on = yesno;
5274 else if (!strcmp ("move", s))
5276 else if (!strcmp ("volatile", s))
5279 as_warn (_("Tried to .set unrecognized mode `%s'"), name);
5281 *input_line_pointer = ch;
5282 demand_empty_rest_of_line ();
5285 /* Handle the .base pseudo op. This changes the assembler's notion of
5286 the $gp register. */
5289 s_alpha_base (ignore)
5290 int ignore ATTRIBUTE_UNUSED;
5293 if (first_32bit_quadrant)
5295 /* not fatal, but it might not work in the end */
5296 as_warn (_("File overrides no-base-register option."));
5297 first_32bit_quadrant = 0;
5302 if (*input_line_pointer == '$')
5304 input_line_pointer++;
5305 if (*input_line_pointer == 'r')
5306 input_line_pointer++;
5309 alpha_gp_register = get_absolute_expression ();
5310 if (alpha_gp_register < 0 || alpha_gp_register > 31)
5312 alpha_gp_register = AXP_REG_GP;
5313 as_warn (_("Bad base register, using $%d."), alpha_gp_register);
5316 demand_empty_rest_of_line ();
5319 /* Handle the .align pseudo-op. This aligns to a power of two. It
5320 also adjusts any current instruction label. We treat this the same
5321 way the MIPS port does: .align 0 turns off auto alignment. */
5324 s_alpha_align (ignore)
5325 int ignore ATTRIBUTE_UNUSED;
5329 long max_alignment = 15;
5331 align = get_absolute_expression ();
5332 if (align > max_alignment)
5334 align = max_alignment;
5335 as_bad (_("Alignment too large: %d. assumed"), align);
5339 as_warn (_("Alignment negative: 0 assumed"));
5343 if (*input_line_pointer == ',')
5345 input_line_pointer++;
5346 fill = get_absolute_expression ();
5354 alpha_auto_align_on = 1;
5355 alpha_align (align, pfill, alpha_insn_label, 1);
5359 alpha_auto_align_on = 0;
5362 demand_empty_rest_of_line ();
5365 /* Hook the normal string processor to reset known alignment. */
5368 s_alpha_stringer (terminate)
5371 alpha_current_align = 0;
5372 alpha_insn_label = NULL;
5373 stringer (terminate);
5376 /* Hook the normal space processing to reset known alignment. */
5379 s_alpha_space (ignore)
5382 alpha_current_align = 0;
5383 alpha_insn_label = NULL;
5387 /* Hook into cons for auto-alignment. */
5390 alpha_cons_align (size)
5396 while ((size >>= 1) != 0)
5399 if (alpha_auto_align_on && alpha_current_align < log_size)
5400 alpha_align (log_size, (char *) NULL, alpha_insn_label, 0);
5401 if (alpha_current_align > log_size)
5402 alpha_current_align = log_size;
5403 alpha_insn_label = NULL;
5406 /* Here come the .uword, .ulong, and .uquad explicitly unaligned
5407 pseudos. We just turn off auto-alignment and call down to cons. */
5410 s_alpha_ucons (bytes)
5413 int hold = alpha_auto_align_on;
5414 alpha_auto_align_on = 0;
5416 alpha_auto_align_on = hold;
5419 /* Switch the working cpu type. */
5422 s_alpha_arch (ignored)
5423 int ignored ATTRIBUTE_UNUSED;
5426 const struct cpu_type *p;
5429 name = input_line_pointer;
5430 ch = get_symbol_end ();
5432 for (p = cpu_types; p->name; ++p)
5433 if (strcmp(name, p->name) == 0)
5435 alpha_target_name = p->name, alpha_target = p->flags;
5438 as_warn("Unknown CPU identifier `%s'", name);
5441 *input_line_pointer = ch;
5442 demand_empty_rest_of_line ();
5448 /* print token expression with alpha specific extension. */
5451 alpha_print_token(f, exp)
5453 const expressionS *exp;
5463 expressionS nexp = *exp;
5464 nexp.X_op = O_register;
5465 print_expr (f, &nexp);
5470 print_expr (f, exp);
5477 /* The target specific pseudo-ops which we support. */
5479 const pseudo_typeS md_pseudo_table[] =
5482 {"comm", s_alpha_comm, 0}, /* osf1 compiler does this */
5483 {"rdata", s_alpha_rdata, 0},
5485 {"text", s_alpha_text, 0},
5486 {"data", s_alpha_data, 0},
5488 {"sdata", s_alpha_sdata, 0},
5491 {"section", s_alpha_section, 0},
5492 {"section.s", s_alpha_section, 0},
5493 {"sect", s_alpha_section, 0},
5494 {"sect.s", s_alpha_section, 0},
5497 { "pdesc", s_alpha_pdesc, 0},
5498 { "name", s_alpha_name, 0},
5499 { "linkage", s_alpha_linkage, 0},
5500 { "code_address", s_alpha_code_address, 0},
5501 { "ent", s_alpha_ent, 0},
5502 { "frame", s_alpha_frame, 0},
5503 { "fp_save", s_alpha_fp_save, 0},
5504 { "mask", s_alpha_mask, 0},
5505 { "fmask", s_alpha_fmask, 0},
5506 { "end", s_alpha_end, 0},
5507 { "file", s_alpha_file, 0},
5508 { "rdata", s_alpha_section, 1},
5509 { "comm", s_alpha_comm, 0},
5510 { "link", s_alpha_section, 3},
5511 { "ctors", s_alpha_section, 4},
5512 { "dtors", s_alpha_section, 5},
5515 /* Frame related pseudos. */
5516 {"ent", s_alpha_ent, 0},
5517 {"end", s_alpha_end, 0},
5518 {"mask", s_alpha_mask, 0},
5519 {"fmask", s_alpha_mask, 1},
5520 {"frame", s_alpha_frame, 0},
5521 {"prologue", s_alpha_prologue, 0},
5522 {"file", s_alpha_file, 5},
5523 {"loc", s_alpha_loc, 9},
5524 {"stabs", s_alpha_stab, 's'},
5525 {"stabn", s_alpha_stab, 'n'},
5526 /* COFF debugging related pseudos. */
5527 {"begin", s_alpha_coff_wrapper, 0},
5528 {"bend", s_alpha_coff_wrapper, 1},
5529 {"def", s_alpha_coff_wrapper, 2},
5530 {"dim", s_alpha_coff_wrapper, 3},
5531 {"endef", s_alpha_coff_wrapper, 4},
5532 {"scl", s_alpha_coff_wrapper, 5},
5533 {"tag", s_alpha_coff_wrapper, 6},
5534 {"val", s_alpha_coff_wrapper, 7},
5536 {"prologue", s_ignore, 0},
5538 {"gprel32", s_alpha_gprel32, 0},
5539 {"t_floating", s_alpha_float_cons, 'd'},
5540 {"s_floating", s_alpha_float_cons, 'f'},
5541 {"f_floating", s_alpha_float_cons, 'F'},
5542 {"g_floating", s_alpha_float_cons, 'G'},
5543 {"d_floating", s_alpha_float_cons, 'D'},
5545 {"proc", s_alpha_proc, 0},
5546 {"aproc", s_alpha_proc, 1},
5547 {"set", s_alpha_set, 0},
5548 {"reguse", s_ignore, 0},
5549 {"livereg", s_ignore, 0},
5550 {"base", s_alpha_base, 0}, /*??*/
5551 {"option", s_ignore, 0},
5552 {"aent", s_ignore, 0},
5553 {"ugen", s_ignore, 0},
5554 {"eflag", s_ignore, 0},
5556 {"align", s_alpha_align, 0},
5557 {"double", s_alpha_float_cons, 'd'},
5558 {"float", s_alpha_float_cons, 'f'},
5559 {"single", s_alpha_float_cons, 'f'},
5560 {"ascii", s_alpha_stringer, 0},
5561 {"asciz", s_alpha_stringer, 1},
5562 {"string", s_alpha_stringer, 1},
5563 {"space", s_alpha_space, 0},
5564 {"skip", s_alpha_space, 0},
5565 {"zero", s_alpha_space, 0},
5567 /* Unaligned data pseudos. */
5568 {"uword", s_alpha_ucons, 2},
5569 {"ulong", s_alpha_ucons, 4},
5570 {"uquad", s_alpha_ucons, 8},
5573 /* Dwarf wants these versions of unaligned. */
5574 {"2byte", s_alpha_ucons, 2},
5575 {"4byte", s_alpha_ucons, 4},
5576 {"8byte", s_alpha_ucons, 8},
5579 /* We don't do any optimizing, so we can safely ignore these. */
5580 {"noalias", s_ignore, 0},
5581 {"alias", s_ignore, 0},
5583 {"arch", s_alpha_arch, 0},
5589 /* Build a BFD section with its flags set appropriately for the .lita,
5590 .lit8, or .lit4 sections. */
5593 create_literal_section (name, secp, symp)
5598 segT current_section = now_seg;
5599 int current_subsec = now_subseg;
5602 *secp = new_sec = subseg_new (name, 0);
5603 subseg_set (current_section, current_subsec);
5604 bfd_set_section_alignment (stdoutput, new_sec, 4);
5605 bfd_set_section_flags (stdoutput, new_sec,
5606 SEC_RELOC | SEC_ALLOC | SEC_LOAD | SEC_READONLY
5609 S_CLEAR_EXTERNAL (*symp = section_symbol (new_sec));
5614 /* @@@ GP selection voodoo. All of this seems overly complicated and
5615 unnecessary; which is the primary reason it's for ECOFF only. */
5624 vma = bfd_get_section_vma (foo, sec);
5625 if (vma && vma < alpha_gp_value)
5626 alpha_gp_value = vma;
5632 assert (alpha_gp_value == 0);
5634 /* Get minus-one in whatever width... */
5635 alpha_gp_value = 0; alpha_gp_value--;
5637 /* Select the smallest VMA of these existing sections. */
5638 maybe_set_gp (alpha_lita_section);
5640 /* These were disabled before -- should we use them? */
5641 maybe_set_gp (sdata);
5642 maybe_set_gp (lit8_sec);
5643 maybe_set_gp (lit4_sec);
5646 /* @@ Will a simple 0x8000 work here? If not, why not? */
5647 #define GP_ADJUSTMENT (0x8000 - 0x10)
5649 alpha_gp_value += GP_ADJUSTMENT;
5651 S_SET_VALUE (alpha_gp_symbol, alpha_gp_value);
5654 printf (_("Chose GP value of %lx\n"), alpha_gp_value);
5657 #endif /* OBJ_ECOFF */
5659 /* Called internally to handle all alignment needs. This takes care
5660 of eliding calls to frag_align if'n the cached current alignment
5661 says we've already got it, as well as taking care of the auto-align
5662 feature wrt labels. */
5665 alpha_align (n, pfill, label, force)
5669 int force ATTRIBUTE_UNUSED;
5671 if (alpha_current_align >= n)
5676 if (subseg_text_p (now_seg))
5677 frag_align_code (n, 0);
5679 frag_align (n, 0, 0);
5682 frag_align (n, *pfill, 0);
5684 alpha_current_align = n;
5686 if (label != NULL && S_GET_SEGMENT (label) == now_seg)
5688 symbol_set_frag (label, frag_now);
5689 S_SET_VALUE (label, (valueT) frag_now_fix ());
5692 record_alignment (now_seg, n);
5694 /* ??? If alpha_flag_relax && force && elf, record the requested alignment
5695 in a reloc for the linker to see. */
5698 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
5699 of an rs_align_code fragment. */
5702 alpha_handle_align (fragp)
5705 static char const unop[4] = { 0x00, 0x00, 0xe0, 0x2f };
5706 static char const nopunop[8] = {
5707 0x1f, 0x04, 0xff, 0x47,
5708 0x00, 0x00, 0xe0, 0x2f
5714 if (fragp->fr_type != rs_align_code)
5717 bytes = fragp->fr_next->fr_address - fragp->fr_address - fragp->fr_fix;
5718 p = fragp->fr_literal + fragp->fr_fix;
5731 memcpy (p, unop, 4);
5737 memcpy (p, nopunop, 8);
5739 fragp->fr_fix += fix;
5743 /* The Alpha has support for some VAX floating point types, as well as for
5744 IEEE floating point. We consider IEEE to be the primary floating point
5745 format, and sneak in the VAX floating point support here. */
5746 #define md_atof vax_md_atof
5747 #include "config/atof-vax.c"