1 /* tc-alpha.c - Processor-specific code for the DEC Alpha CPU.
2 Copyright (C) 1989, 1993, 1994 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.
7 This file is part of GAS, the GNU Assembler.
9 GAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GAS; see the file COPYING. If not, write to
21 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 * Mach Operating System
25 * Copyright (c) 1993 Carnegie Mellon University
26 * All Rights Reserved.
28 * Permission to use, copy, modify and distribute this software and its
29 * documentation is hereby granted, provided that both the copyright
30 * notice and this permission notice appear in all copies of the
31 * software, derivative works or modified versions, and any portions
32 * thereof, and that both notices appear in supporting documentation.
34 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
35 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
36 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
38 * Carnegie Mellon requests users of this software to return to
41 * School of Computer Science
42 * Carnegie Mellon University
43 * Pittsburgh PA 15213-3890
45 * any improvements or extensions that they make and grant Carnegie the
46 * rights to redistribute these changes.
50 * 5-Oct-93 Alessandro Forin (af) at Carnegie-Mellon University
53 * Author: Alessandro Forin, Carnegie Mellon University
58 #include "alpha-opcode.h"
61 /* These are exported to relaxing code, even though we don't do any
62 relaxing on this processor currently. */
63 const relax_typeS md_relax_table[1];
64 int md_short_jump_size = 4;
65 int md_long_jump_size = 4;
67 /* handle of the OPCODE hash table */
68 static struct hash_control *op_hash;
70 /* sections we'll want to keep track of */
71 static segT lita_sec, rdata, sdata;
73 /* setting for ".set [no]{at,macro}" */
74 static int at_ok = 1, macro_ok = 1;
76 /* Keep track of global pointer. */
77 valueT alpha_gp_value;
80 /* We'll probably be using this relocation frequently, and we
81 will want to compare for it. */
82 static reloc_howto_type *gpdisp_hi16_howto;
84 /* These are exported to ECOFF code. */
85 unsigned long alpha_gprmask, alpha_fprmask;
87 /* Used for LITUSE relocations. */
88 static expressionS lituse_basereg, lituse_byteoff, lituse_jsr;
90 /* Address size: In OSF/1 1.3, an undocumented "-32addr" option will
91 cause all addresses to be treated as 32-bit values in memory. (The
92 in-register versions are all sign-extended to 64 bits, of course.)
93 Some other systems may want this option too. */
96 /* Imported functions -- they should be defined in header files somewhere. */
97 extern segT subseg_get ();
98 extern PTR bfd_alloc_by_size_t ();
99 extern void s_globl (), s_long (), s_short (), s_space (), cons (), s_text (),
100 s_data (), float_cons ();
102 /* Static functions, needing forward declarations. */
103 static void s_mask (), s_base (), s_proc (), s_alpha_set ();
104 static void s_gprel32 (), s_rdata (), s_sdata (), s_alpha_comm ();
105 static int alpha_ip ();
107 const pseudo_typeS md_pseudo_table[] =
109 {"common", s_comm, 0}, /* is this used? */
110 {"comm", s_alpha_comm, 0}, /* osf1 compiler does this */
111 {"rdata", s_rdata, 0},
112 {"sdata", s_sdata, 0},
113 {"gprel32", s_gprel32, 0},
114 {"t_floating", float_cons, 'd'},
115 {"s_floating", float_cons, 'f'},
116 {"f_floating", float_cons, 'F'},
117 {"g_floating", float_cons, 'G'},
118 {"d_floating", float_cons, 'D'},
121 {"aproc", s_proc, 1},
122 {"set", s_alpha_set, 0},
123 {"reguse", s_ignore, 0},
124 {"livereg", s_ignore, 0},
125 {"extern", s_ignore, 0}, /*??*/
126 {"base", s_base, 0}, /*??*/
127 {"option", s_ignore, 0},
128 {"prologue", s_ignore, 0},
129 {"aent", s_ignore, 0},
130 {"ugen", s_ignore, 0},
132 /* We don't do any optimizing, so we can safely ignore these. */
133 {"noalias", s_ignore, 0},
134 {"alias", s_ignore, 0},
139 #define SA 21 /* shift for register Ra */
140 #define SB 16 /* shift for register Rb */
141 #define SC 0 /* shift for register Rc */
142 #define SN 13 /* shift for 8 bit immediate # */
154 #define OPCODE(X) (((X) >> 26) & 0x3f)
155 #define OP_FCN(X) (((X) >> 5) & 0x7f)
157 #ifndef FIRST_32BIT_QUADRANT
158 #define FIRST_32BIT_QUADRANT 0
161 int first_32bit_quadrant = FIRST_32BIT_QUADRANT;
162 int base_register = FIRST_32BIT_QUADRANT ? ZERO : GP;
164 int no_mixed_code = 0;
167 /* This array holds the chars that always start a comment. If the
168 pre-processor is disabled, these aren't very useful */
169 const char comment_chars[] = "#";
171 /* This array holds the chars that only start a comment at the beginning of
172 a line. If the line seems to have the form '# 123 filename'
173 .line and .file directives will appear in the pre-processed output */
174 /* Note that input_file.c hand checks for '#' at the beginning of the
175 first line of the input file. This is because the compiler outputs
176 #NO_APP at the beginning of its output. */
177 /* Also note that '/*' will always start a comment */
178 const char line_comment_chars[] = "#";
180 /* Chars that can be used to separate mant from exp in floating point nums */
181 const char EXP_CHARS[] = "eE";
183 const char line_separator_chars[1];
185 /* Chars that mean this number is a floating point constant, as in
186 "0f12.456" or "0d1.2345e12". */
187 char FLT_CHARS[] = "rRsSfFdDxXpP";
189 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
190 changed in read.c. Ideally it shouldn't have to know about it at all,
191 but nothing is ideal around here. */
196 bfd_reloc_code_real_type code;
199 /* Occasionally, two relocations will be desired for one address.
200 Mainly only in cases like "jsr $r,foo" where we want both a LITUSE
205 unsigned long opcode; /* need at least 32 bits */
206 struct reloc_data reloc[MAX_RELOCS];
209 static void getExpression (char *str, struct alpha_it *insn);
210 static char *expr_end;
212 #define note_gpreg(R) (alpha_gprmask |= (1 << (R)))
213 #define note_fpreg(R) (alpha_fprmask |= (1 << (R)))
216 tc_get_register (frame)
223 if (*input_line_pointer == '$')
225 input_line_pointer++;
226 if (input_line_pointer[0] == 's'
227 && input_line_pointer[1] == 'p')
229 input_line_pointer += 2;
233 framereg = get_absolute_expression ();
234 framereg &= 31; /* ? */
237 as_warn ("frame reg expected, using $%d.", framereg);
239 note_gpreg (framereg);
249 temp = get_absolute_expression ();
252 rdata = subseg_get (".rdata", 0);
253 subseg_set (rdata, (subsegT) temp);
255 rdata = subseg_new (".rdata", 0);
257 demand_empty_rest_of_line ();
266 temp = get_absolute_expression ();
269 sdata = subseg_get (".sdata", 0);
270 subseg_set (sdata, (subsegT) temp);
272 sdata = subseg_new (".sdata", 0);
274 demand_empty_rest_of_line ();
278 s_alpha_comm (ignore)
285 register symbolS *symbolP;
287 name = input_line_pointer;
288 c = get_symbol_end ();
289 /* just after name is now '\0' */
290 p = input_line_pointer;
293 /* Alpha OSF/1 compiler doesn't provide the comma, gcc does. */
294 if (*input_line_pointer == ',')
296 input_line_pointer++;
299 if ((temp = get_absolute_expression ()) < 0)
301 as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp);
302 ignore_rest_of_line ();
306 symbolP = symbol_find_or_make (name);
308 if (S_IS_DEFINED (symbolP))
310 as_bad ("Ignoring attempt to re-define symbol");
311 ignore_rest_of_line ();
314 if (S_GET_VALUE (symbolP))
316 if (S_GET_VALUE (symbolP) != (valueT) temp)
317 as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.",
318 S_GET_NAME (symbolP),
319 (long) S_GET_VALUE (symbolP),
324 S_SET_VALUE (symbolP, (valueT) temp);
325 S_SET_EXTERNAL (symbolP);
328 know (symbolP->sy_frag == &zero_address_frag);
329 demand_empty_rest_of_line ();
333 tc_gen_reloc (sec, fixp)
338 bfd_reloc_code_real_type code;
340 reloc = (arelent *) bfd_alloc_by_size_t (stdoutput, sizeof (arelent));
341 reloc->sym_ptr_ptr = &fixp->fx_addsy->bsym;
342 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
344 if (fixp->fx_r_type > BFD_RELOC_UNUSED || fixp->fx_r_type < 0)
347 if (fixp->fx_r_type == BFD_RELOC_ALPHA_GPDISP_HI16)
349 if (!gpdisp_hi16_howto)
350 gpdisp_hi16_howto = bfd_reloc_type_lookup (stdoutput,
352 reloc->howto = gpdisp_hi16_howto;
355 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
356 assert (reloc->howto != 0);
357 if (!fixp->fx_pcrel != !reloc->howto->pc_relative)
359 as_fatal ("bug in handling type-%d relocs", fixp->fx_r_type);
362 assert (!fixp->fx_pcrel == !reloc->howto->pc_relative);
364 if (reloc->howto->pc_relative
365 && reloc->howto->pcrel_offset
367 && code != BFD_RELOC_ALPHA_GPDISP_HI16
368 && code != BFD_RELOC_ALPHA_GPDISP_LO16
372 reloc->addend = fixp->fx_offset - reloc->address;
375 reloc->addend = fixp->fx_offset;
382 if (first_32bit_quadrant)
384 /* not fatal, but it might not work in the end */
385 as_warn ("File overrides no-base-register option.");
386 first_32bit_quadrant = 0;
390 if (*input_line_pointer == '$')
392 input_line_pointer++;
393 if (*input_line_pointer == 'r')
394 input_line_pointer++;
397 base_register = get_absolute_expression ();
398 if (base_register < 0 || base_register > 31)
401 as_warn ("Bad base register, using $r.", base_register);
403 demand_empty_rest_of_line ();
417 e.X_add_symbol = section_symbol (absolute_section);
428 fix_new_exp (frag_now, p - frag_now->fr_literal, 4, &e, 0,
433 create_lita_section ()
435 segT current_section = now_seg;
436 int current_subsec = now_subseg;
438 lita_sec = subseg_new (".lita", 0);
439 subseg_set (current_section, current_subsec);
440 bfd_set_section_flags (stdoutput, lita_sec,
441 SEC_RELOC | SEC_ALLOC | SEC_LOAD | SEC_READONLY
443 bfd_set_section_alignment (stdoutput, lita_sec, 3);
446 /* This function is called once, at assembler startup time. It should
447 set up all the tables, etc. that the MD part of the assembler will need. */
455 op_hash = hash_new ();
457 for (i = 0; i < NUMOPCODES; )
459 const char *name = alpha_opcodes[i].name;
460 retval = hash_insert (op_hash, name, (PTR) & alpha_opcodes[i]);
463 as_bad ("internal error: can't hash opcode `%s': %s",
464 alpha_opcodes[i].name, retval);
469 while (i < NUMOPCODES
470 && (alpha_opcodes[i].name == name
471 || !strcmp (alpha_opcodes[i].name, name)));
473 /* Some opcodes include modifiers of various sorts with a "/mod"
474 syntax, like the architecture documentation suggests. However,
475 for use with gcc at least, we also need to access those same
476 opcodes without the "/". */
477 for (i = 0; i < NUMOPCODES; )
479 const char *name = alpha_opcodes[i].name;
480 if (strchr (name, '/'))
482 char *p = xmalloc (strlen (name));
483 const char *q = name;
491 retval = hash_insert (op_hash, p, (PTR) & alpha_opcodes[i]);
494 /* Ignore failures -- the opcode table does duplicate
495 some variants in different forms, like "hw_st/q" and
498 as_bad ("internal error: can't hash opcode variant `%s': %s",
506 while (i < NUMOPCODES
507 && (alpha_opcodes[i].name == name
508 || !strcmp (alpha_opcodes[i].name, name)));
514 as_fatal ("Broken assembler. No assembly attempted.");
516 lituse_basereg.X_op = O_constant;
517 lituse_basereg.X_add_number = 1;
518 lituse_byteoff.X_op = O_constant;
519 lituse_byteoff.X_add_number = 2;
520 lituse_jsr.X_op = O_constant;
521 lituse_jsr.X_add_number = 3;
523 /* So .sbss will get used for tiny objects. */
524 bfd_set_gp_size (stdoutput, 8);
525 create_lita_section ();
526 /* For handling the GP, create a symbol that won't be output in the
527 symbol table. We'll edit it out of relocs later. */
528 gp = symbol_new ("<GP value>", lita_sec, 0x8000, &zero_address_frag);
529 symbol_remove (gp, &symbol_rootP, &symbol_lastP);
541 struct alpha_it insns[MAX_INSNS];
543 count = alpha_ip (str, insns);
547 for (i = 0; i < count; i++)
551 /* put out the opcode */
552 md_number_to_chars (toP, insns[i].opcode, 4);
554 /* put out the symbol-dependent stuff */
555 for (j = 0; j < MAX_RELOCS; j++)
557 struct reloc_data *r = &insns[i].reloc[j];
560 if (r->code != BFD_RELOC_NONE)
562 if (r->exp.X_op == O_constant)
564 r->exp.X_add_symbol = section_symbol (absolute_section);
565 r->exp.X_op = O_symbol;
567 f = fix_new_exp (frag_now, (toP - frag_now->fr_literal), 4,
568 &r->exp, r->pcrel, r->code);
570 if (r->code == BFD_RELOC_ALPHA_GPDISP_LO16)
572 static bit_fixS cookie;
573 /* This'll make the range checking in write.c shut up. */
574 f->fx_bit_fixP = &cookie;
580 /* @@ Will a simple 0x8000 work here? If not, why not? */
581 #define GP_ADJUSTMENT (0x8000 - 0x10)
586 bfd_vma lita_vma, sdata_vma;
588 if (alpha_gp_value != 0)
592 lita_vma = bfd_get_section_vma (abfd, lita_sec);
597 sdata_vma = bfd_get_section_vma (abfd, sdata);
603 /* Who knows which order they'll get laid out in? */
604 || (sdata_vma != 0 && sdata_vma < lita_vma))
605 alpha_gp_value = sdata_vma;
607 alpha_gp_value = lita_vma;
609 alpha_gp_value += GP_ADJUSTMENT;
611 S_SET_VALUE (gp, alpha_gp_value);
614 printf ("Chose GP value of %lx\n", alpha_gp_value);
619 alpha_force_relocation (f)
622 switch (f->fx_r_type)
624 case BFD_RELOC_ALPHA_GPDISP_HI16:
625 case BFD_RELOC_ALPHA_GPDISP_LO16:
626 case BFD_RELOC_ALPHA_LITERAL:
627 case BFD_RELOC_ALPHA_LITUSE:
628 case BFD_RELOC_GPREL32:
630 case BFD_RELOC_ALPHA_HINT:
635 case BFD_RELOC_23_PCREL_S2:
645 alpha_fix_adjustable (f)
648 /* Are there any relocation types for which we must generate a reloc
649 but we can adjust the values contained within it? */
650 switch (f->fx_r_type)
652 case BFD_RELOC_ALPHA_GPDISP_HI16:
653 case BFD_RELOC_ALPHA_GPDISP_LO16:
655 case BFD_RELOC_GPREL32:
658 return !alpha_force_relocation (f);
662 md_section_align (seg, size)
667 /* This should probably be handled within BFD, or by pulling the
668 number from BFD at least. */
676 /* Add this thing to the .lita section and produce a LITERAL reloc referring
681 Set GP value properly, and have values in LITERAL references set
686 load_symbol_address (reg, insn)
688 struct alpha_it *insn;
690 static symbolS *lita_sym;
701 lita_sym = section_symbol (lita_sec);
702 S_CLEAR_EXTERNAL (lita_sym);
705 retval = add_to_literal_pool (insn->reloc[0].exp.X_add_symbol,
706 insn->reloc[0].exp.X_add_number,
709 /* @@ Get these numbers from GP setting. */
710 retval -= GP_ADJUSTMENT;
712 /* Now emit a LITERAL relocation for the original section. */
713 insn->reloc[0].exp.X_op = O_symbol;
714 insn->reloc[0].exp.X_add_symbol = lita_sym;
715 insn->reloc[0].exp.X_add_number = retval;
716 insn->reloc[0].code = BFD_RELOC_ALPHA_LITERAL;
718 if (retval == 0x8000)
720 as_fatal ("overflow in literal (.lita) table");
723 insn->opcode = (0xa0000000 /* ldl */
725 | (base_register << SB)
728 insn->opcode = (0xa4000000 /* ldq */
730 | (base_register << SB)
732 note_gpreg (base_register);
735 /* To load an address with a single instruction,
736 emit a LITERAL reloc in this section, and a REFQUAD
737 for the .lita section, so that we'll be able to access
739 lda REG, xx -> ldq REG, -32752(gp)
740 lda REG, xx+4 -> ldq REG, -32752(gp)
743 The offsets need to start near -0x8000, and the generated LITERAL
744 relocations should negate the offset. I don't completely grok the
748 load_expression (reg, insn)
750 struct alpha_it *insn;
755 addend = insn->reloc[0].exp.X_add_number;
756 insn->reloc[0].exp.X_add_number = 0;
757 load_symbol_address (reg, insn);
763 if ((x & ~0x7fff) != 0
764 && (x & ~0x7fff) + 0x8000 != 0)
766 as_bad ("assembler not prepared to handle constants >16 bits yet");
770 insn[1].opcode = (0x20000000 /* lda */
773 | (addend & 0xffff));
774 insn[1].reloc[0].code = BFD_RELOC_ALPHA_LITUSE;
775 insn[1].reloc[0].exp = lituse_basereg;
781 getExpression (str, this_insn)
783 struct alpha_it *this_insn;
788 #if 0 /* Not converted to bfd yet, and I don't think we need them
789 for ECOFF. Re-adding a.out support will probably require
791 static const struct am {
793 bfd_reloc_code_real_type reloc;
795 { "hi", RELOC_48_63 },
796 { "lo", RELOC_0_15 },
797 { "ml", RELOC_16_31 },
798 { "mh", RELOC_32_47 },
799 { "uhi", RELOC_U_48_63 },
800 { "uml", RELOC_U_16_31 },
801 { "umh", RELOC_U_32_47 },
805 /* Handle macros: "%macroname(expr)" */
816 while (*q && *p == *q)
824 str = p; /* keep the '(' */
825 this_insn->reloc = m->reloc;
830 save_in = input_line_pointer;
831 input_line_pointer = str;
833 seg = expression (&this_insn->reloc[0].exp);
834 /* XXX validate seg and exp, make sure they're reasonable */
835 expr_end = input_line_pointer;
836 input_line_pointer = save_in;
839 /* Note that for now, this function is called recursively (by way of
840 calling md_assemble again). Some of the macros defined as part of
841 the assembly language are currently rewritten as sequences of
842 strings to be assembled. See, for example, the handling of "divq".
844 For efficiency, this should be fixed someday. */
846 alpha_ip (str, insns)
848 struct alpha_it insns[];
854 struct alpha_opcode *pattern;
858 int match = 0, num_gen = 1;
862 islower (*s) || *s == '_' || *s == '/' || *s == '4' || *s == '8';
881 as_warn ("Unknown opcode: `%s'", str);
884 if ((pattern = (struct alpha_opcode *) hash_find (op_hash, str)) == NULL)
886 as_warn ("Unknown opcode: `%s'", str);
895 opcode = pattern->match;
897 memset (insns, 0, sizeof (*insns));
898 for (i = 0; i < MAX_RELOCS; i++)
899 insns[0].reloc[i].code = BFD_RELOC_NONE;
900 for (i = 1; i < MAX_INSNS; i++)
903 /* Build the opcode, checking as we go to make sure that the
905 for (args = pattern->args;; ++args)
910 case '\0': /* end of args */
929 case '(': /* these must match exactly */
938 case '1': /* next operand must be a register */
948 case 'a': /* $at: as temporary */
954 case 'g': /* $gp: base register */
957 mask = base_register;
960 case 's': /* $sp: stack pointer */
967 case 'r': /* any register */
968 if (!isdigit (c = *s++))
985 if ((c = 10 * (c - '0') + (*s++ - '0')) >= 32)
994 if ((c == GP) && first_32bit_quadrant)
1004 /* Got the register, now figure out where it goes in
1012 opcode |= mask << SA;
1017 opcode |= mask << SB;
1026 opcode |= (mask << SA) | mask;
1029 case 'R': /* ra and rb are the same */
1030 opcode |= (mask << SA) | (mask << SB);
1034 opcode |= (mask << SA) | (mask << SB) | (mask);
1040 case 'e': /* next operand is a floating point register */
1044 if (*s++ == '$' && *s++ == 'f' && isdigit (*s))
1049 mask = 10 * (mask - '0') + (*s++ - '0');
1060 /* same encoding as gp registers */
1066 case 'h': /* bits 16..31 */
1067 insns[0].reloc = RELOC_16_31;
1071 case 'l': /* bits 0..15 */
1072 insns[0].reloc[0].code = BFD_RELOC_16;
1075 case 'L': /* 21 bit PC relative immediate */
1076 insns[0].reloc[0].code = BFD_RELOC_23_PCREL_S2;
1077 insns[0].reloc[0].pcrel = 1;
1080 case 'i': /* 14 bit immediate */
1081 if (OPCODE (opcode) != 0x1a)
1082 /* Not a jmp variant?? */
1084 else if (opcode & 0x8000)
1085 /* ret or jsr_coroutine */
1087 insns[0].reloc[0].code = BFD_RELOC_14;
1088 insns[0].reloc[0].pcrel = 0;
1093 insns[0].reloc[0].code = BFD_RELOC_ALPHA_HINT;
1094 insns[0].reloc[0].pcrel = 1;
1098 case 'b': /* 8 bit immediate */
1099 insns[0].reloc[0].code = BFD_RELOC_8;
1103 case 't': /* 12 bit 0...11 */
1104 insns[0].reloc = RELOC_0_12;
1107 case '8': /* 8 bit 0...7 */
1108 insns[0].reloc = RELOC_0_8;
1111 case 'I': /* 26 bit immediate */
1112 insns[0].reloc = RELOC_0_25;
1124 getExpression (s, &insns[0]);
1126 /* Handle overflow in certain instructions by converting
1127 to other instructions. */
1128 if (insns[0].reloc[0].code == BFD_RELOC_8
1129 && insns[0].reloc[0].exp.X_op == O_constant
1130 && (insns[0].reloc[0].exp.X_add_number < 0
1131 || insns[0].reloc[0].exp.X_add_number > 0xff))
1133 if (OPCODE (opcode) == 0x10
1134 && (OP_FCN (opcode) == 0x00 /* addl */
1135 || OP_FCN (opcode) == 0x40 /* addl/v */
1136 || OP_FCN (opcode) == 0x20 /* addq */
1137 || OP_FCN (opcode) == 0x60 /* addq/v */
1138 || OP_FCN (opcode) == 0x09 /* subl */
1139 || OP_FCN (opcode) == 0x49 /* subl/v */
1140 || OP_FCN (opcode) == 0x29 /* subq */
1141 || OP_FCN (opcode) == 0x69 /* subq/v */
1142 || OP_FCN (opcode) == 0x02 /* s4addl */
1143 || OP_FCN (opcode) == 0x22 /* s4addq */
1144 || OP_FCN (opcode) == 0x0b /* s4subl */
1145 || OP_FCN (opcode) == 0x2b /* s4subq */
1146 || OP_FCN (opcode) == 0x12 /* s8addl */
1147 || OP_FCN (opcode) == 0x32 /* s8addq */
1148 || OP_FCN (opcode) == 0x1b /* s8subl */
1149 || OP_FCN (opcode) == 0x3b /* s8subq */
1151 /* Can we make it fit by negating? */
1152 && -insns[0].reloc[0].exp.X_add_number < 0xff
1153 && -insns[0].reloc[0].exp.X_add_number > 0)
1155 opcode ^= 0x120; /* convert add<=>sub */
1156 insns[0].reloc[0].exp.X_add_number *= -1;
1158 else if (at_ok && macro_ok)
1160 /* Constant value supplied, but it's too large. */
1162 sprintf (expansion, "lda $%d,%d($%d)", AT,
1163 insns[0].reloc[0].exp.X_add_number, ZERO);
1164 md_assemble (expansion);
1165 opcode |= 0x1000 /* use reg */ | (AT << SB);
1166 insns[0].reloc[0].code = BFD_RELOC_NONE;
1169 as_bad ("overflow in 8-bit literal field in `operate' format insn");
1173 /* The following two.. take advantage of the fact that
1174 opcode already contains most of what we need to know.
1175 We just prepend to the instr an "ldah
1176 $r,%ml(expr)($base)" and turn this one (done later
1177 after we return) into something like "stq
1178 $r,%lo(expr)(at)" or "ldq $r,%lo(expr)($r)".
1180 NOTE: This can fail later on at link time if the
1181 offset from $base actually turns out to be more than
1182 2**31 or 2**47 if use_large_offsets is set. */
1183 case 'P': /* Addressing macros: PUT */
1184 mask = AT; /* register 'at' */
1187 case 'G': /* Addressing macros: GET */
1189 /* All it is missing is the expression, which is what we
1194 getExpression (s, &insns[0]);
1197 /* Must check for "lda ..,number" too */
1198 if (insns[0].reloc[0].exp.X_op == O_big)
1200 as_warn ("Sorry, not yet. Put bignums in .data section yourself.");
1203 if (insns[0].reloc[0].exp.X_op == O_constant)
1205 /* This only handles 32bit numbers */
1206 register int val = insns[0].reloc[0].exp.X_add_number;
1207 register short sval;
1209 insns[0].reloc[0].code = BFD_RELOC_NONE;
1210 insns[1].reloc[0].code = BFD_RELOC_NONE;
1213 if ((sval != val) && (val & 0x8000))
1219 if (optnum && (sval == val))
1221 /* optimize away the ldah */
1223 opcode |= (ZERO << SB) | (val & 0xffff);
1228 insns[1].opcode = opcode | (mask << SB) | (val & 0xffff);
1229 opcode = 0x24000000 /*ldah*/ |
1230 mask << SA | (ZERO << SB) |
1231 ((val >> 16) & 0xffff);
1234 else if (insns[0].reloc[0].exp.X_op == O_symbol)
1236 unsigned long old_opcode = opcode;
1240 as_bad ("insn requires expansion but `nomacro' specified");
1241 else if (*args == 'G')
1244 as_bad ("insn expansion requires AT use, but `noat' specified");
1247 num_gen = load_expression (tmp_reg, insns);
1248 opcode = insns[0].opcode;
1249 /* lda is opcode 8, 0x20000000 */
1250 if (OPCODE (old_opcode) != 0x08)
1253 i = &insns[num_gen++];
1254 i->reloc[0].code = BFD_RELOC_NONE;
1255 i->opcode = old_opcode | (tmp_reg << SB);
1262 insns[1].reloc[0].exp = insns[0].reloc[0].exp;
1264 /* Generate: ldah REG,x1(GP); OP ?,x0(REG) */
1266 abort (); /* relocs need fixing */
1268 insns[1].reloc = RELOC_0_15;
1269 insns[1].opcode = opcode | mask << SB;
1271 insns[0].reloc = RELOC_16_31;
1272 opcode = 0x24000000 /*ldah*/ | mask << SA | (base_register << SB);
1278 /* Same failure modes as above, actually most of the
1279 same code shared. */
1280 case 'B': /* Builtins */
1285 case 'a': /* ldgp */
1287 if (first_32bit_quadrant || no_mixed_code)
1289 switch (OUTPUT_FLAVOR)
1291 case bfd_target_aout_flavour:
1292 /* this is cmu's a.out version */
1293 insns[0].reloc[0].code = BFD_RELOC_NONE;
1294 /* generate "zap %r,0xf,%r" to take high 32 bits */
1295 opcode |= 0x48001600 /* zap ?,#,?*/ | (0xf << SN);
1297 case bfd_target_ecoff_flavour:
1298 /* Given "ldgp R1,N(R2)", turn it into something
1299 like "ldah R1,###(R2) ; lda R1,###(R1)" with
1300 appropriate constants and relocations. */
1302 unsigned long r1, r2;
1303 unsigned long addend = 0;
1308 insns[0].reloc[0].code = BFD_RELOC_ALPHA_GPDISP_HI16;
1309 insns[0].reloc[0].pcrel = 1;
1310 insns[0].reloc[0].exp.X_op = O_symbol;
1311 insns[0].reloc[0].exp.X_add_symbol = gp;
1312 insns[0].reloc[0].exp.X_add_number = 0;
1313 insns[0].opcode = (0x24000000 /* ldah */
1316 insns[1].reloc[0].code = BFD_RELOC_ALPHA_GPDISP_LO16;
1317 insns[1].reloc[0].exp.X_op = O_symbol;
1318 insns[1].reloc[0].exp.X_add_symbol = gp;
1319 insns[1].reloc[0].exp.X_add_number = 4;
1320 insns[1].reloc[0].pcrel = 1;
1321 insns[1].opcode = 0x20000000 | (r1 << SA) | (r1 << SB);
1322 opcode = insns[0].opcode;
1323 /* merge in addend */
1324 insns[1].opcode |= addend & 0xffff;
1325 insns[0].opcode |= ((addend >> 16)
1326 + (addend & 0x8000 ? 1 : 0));
1327 ecoff_set_gp_prolog_size (0);
1336 case 'b': /* setgp */
1337 switch (OUTPUT_FLAVOR)
1339 case bfd_target_aout_flavour:
1340 /* generate "zap %r,0xf,$gp" to take high 32 bits */
1341 opcode |= 0x48001600 /* zap ?,#,?*/
1342 | (0xf << SN) | (base_register);
1349 case 'c': /* jsr $r,foo becomes
1352 Register 27, t12, is used by convention
1355 struct alpha_it *jsr;
1357 struct reloc_data *r;
1359 /* We still have to parse the function name */
1362 getExpression (s, &insns[0]);
1363 etmp = insns[0].reloc[0].exp;
1365 num_gen = load_expression (PV, &insns[0]);
1368 jsr = &insns[num_gen++];
1369 jsr->opcode = (0x68004000 /* jsr */
1375 /* LITUSE wasn't emitted yet */
1376 jsr->reloc[0].code = BFD_RELOC_ALPHA_LITUSE;
1377 jsr->reloc[0].exp = lituse_jsr;
1383 r->code = BFD_RELOC_ALPHA_HINT;
1385 opcode = insns[0].opcode;
1389 /* DIVISION and MODULUS. Yech.
1390 Convert OP x,y,result
1396 with appropriate optimizations if t10,t11,t12
1397 are the registers specified by the compiler.
1398 We are missing an obvious optimization
1399 opportunity here; if the ldq generated by the
1400 jsr assembly requires a cycle or two to make
1401 the value available, initiating it before one
1402 or two of the mov instructions would result in
1403 faster execution. */
1404 case '0': /* reml */
1405 case '1': /* divl */
1406 case '2': /* remq */
1407 case '3': /* divq */
1408 case '4': /* remlu */
1409 case '5': /* divlu */
1410 case '6': /* remqu */
1411 case '7': /* divqu */
1413 static char func[8][6] = {
1414 "reml", "divl", "remq", "divq",
1415 "remlu", "divlu", "remqu", "divqu"
1420 /* All regs parsed, in opcode */
1422 /* Do the expansions, one instr at a time */
1424 reg = (opcode >> SA) & 31;
1428 sprintf (expansion, "mov $%d,$%d", reg, T10);
1429 md_assemble (expansion);
1431 reg = (opcode >> SB) & 31;
1433 /* we already overwrote it! */
1435 else if (reg != T11)
1438 sprintf (expansion, "mov $%d,$%d", reg, T11);
1439 md_assemble (expansion);
1441 sprintf (expansion, "lda $%d,__%s", PV, func[*args - '0']);
1442 md_assemble (expansion);
1443 sprintf (expansion, "jsr $%d,($%d),__%s", T9, PV,
1445 md_assemble (expansion);
1447 if (!first_32bit_quadrant)
1452 md_assemble (expansion);
1455 sprintf (expansion, "ldgp $%d,0($%d)",
1457 md_assemble (expansion);
1459 /* Use insns[0] to get at the result */
1460 if ((reg = (opcode & 31)) != PV)
1461 opcode = (0x47e00400 /* or zero,zero,zero */
1463 | reg /* Rc */ ); /* pv->z */
1479 /* Args don't match. */
1480 if (&pattern[1] - alpha_opcodes < NUMOPCODES
1481 && !strcmp (pattern->name, pattern[1].name))
1489 as_warn ("Illegal operands");
1495 /* Args match, see if a float instructions and -nofloats */
1496 if (nofloats && pattern->isa_float)
1502 insns[0].opcode = opcode;
1506 /* Turn a string in input_line_pointer into a floating point constant
1507 of type type, and store the appropriate bytes in *litP. The number
1508 of LITTLENUMS emitted is stored in *sizeP. An error message is
1509 returned, or NULL on OK. */
1511 /* Equal to MAX_PRECISION in atof-ieee.c */
1512 #define MAX_LITTLENUMS 6
1515 md_atof (type, litP, sizeP)
1521 LITTLENUM_TYPE words[MAX_LITTLENUMS];
1522 LITTLENUM_TYPE *wordP;
1524 char *atof_ieee (), *vax_md_atof ();
1530 /* VAX md_atof doesn't like "G" for some reason. */
1534 return vax_md_atof (type, litP, sizeP);
1557 return "Bad call to MD_ATOF()";
1559 t = atof_ieee (input_line_pointer, type, words);
1561 input_line_pointer = t;
1562 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1564 for (wordP = words + prec - 1; prec--;)
1566 md_number_to_chars (litP, (long) (*wordP--), sizeof (LITTLENUM_TYPE));
1567 litP += sizeof (LITTLENUM_TYPE);
1574 md_bignum_to_chars (buf, bignum, nchars)
1576 LITTLENUM_TYPE *bignum;
1581 LITTLENUM_TYPE work = *bignum++;
1582 int nb = CHARS_PER_LITTLENUM;
1586 *buf++ = work & ((1 << BITS_PER_CHAR) - 1);
1589 work >>= BITS_PER_CHAR;
1596 md_parse_option (argP, cntP, vecP)
1606 #if 0 /* I have no idea if this stuff would work any more. And it's
1607 probably not right for ECOFF anyways. */
1608 /* Use base-register addressing, e.g. PIC code */
1611 if (first_32bit_quadrant)
1613 first_32bit_quadrant = 0;
1618 first_32bit_quadrant = 1;
1619 base_register = ZERO;
1621 if (argP[0][1] == 'k')
1627 if (!strcmp (*argP, "32addr"))
1633 if (!strcmp (*argP, "nocpp"))
1644 /* XXXX Align to cache linesize XXXXX */
1651 /* Takes ".proc name,nargs" */
1652 name = input_line_pointer;
1653 c = get_symbol_end ();
1654 p = input_line_pointer;
1655 symbolP = symbol_find_or_make (name);
1658 if (*input_line_pointer != ',')
1661 as_warn ("Expected comma after name \"%s\"", name);
1664 ignore_rest_of_line ();
1668 input_line_pointer++;
1669 temp = get_absolute_expression ();
1671 /* symbolP->sy_other = (signed char) temp; */
1672 as_warn ("unhandled: .proc %s,%d", name, temp);
1673 demand_empty_rest_of_line ();
1680 char *name = input_line_pointer, ch, *s;
1683 while (!is_end_of_line[(unsigned char) *input_line_pointer])
1684 input_line_pointer++;
1685 ch = *input_line_pointer;
1686 *input_line_pointer = '\0';
1689 if (s[0] == 'n' && s[1] == 'o')
1694 if (!strcmp ("reorder", s))
1696 else if (!strcmp ("at", s))
1698 else if (!strcmp ("macro", s))
1701 as_warn ("Tried to set unrecognized symbol: %s", name);
1702 *input_line_pointer = ch;
1703 demand_empty_rest_of_line ();
1706 /* @@ Is this right?? */
1708 md_pcrel_from (fixP)
1711 valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
1712 switch (fixP->fx_r_type)
1714 case BFD_RELOC_ALPHA_GPDISP_HI16:
1715 case BFD_RELOC_ALPHA_GPDISP_LO16:
1718 return fixP->fx_size + addr;
1723 alpha_do_align (n, fill)
1728 && (now_seg == text_section
1729 || !strcmp (now_seg->name, ".init")
1730 || !strcmp (now_seg->name, ".fini")))
1732 static const unsigned char nop_pattern[] = { 0x1f, 0x04, 0xff, 0x47 };
1733 frag_align_pattern (n, nop_pattern, sizeof (nop_pattern));
1740 md_apply_fix (fixP, valueP)
1747 char *p = fixP->fx_frag->fr_literal + fixP->fx_where;
1751 switch (fixP->fx_r_type)
1753 /* The GPDISP relocations are processed internally with a symbol
1754 referring to the current function; we need to drop in a value
1755 which, when added to the address of the start of the function,
1756 gives the desired GP. */
1757 case BFD_RELOC_ALPHA_GPDISP_HI16:
1758 case BFD_RELOC_ALPHA_GPDISP_LO16:
1760 if (fixP->fx_r_type == BFD_RELOC_ALPHA_GPDISP_HI16)
1762 assert (fixP->fx_next->fx_r_type == BFD_RELOC_ALPHA_GPDISP_LO16);
1765 fprintf_vma (stdout, addend);
1768 if (addend & 0x8000)
1771 fixP->fx_offset = 4; /* @@ Compute this using fx_next. */
1777 fprintf_vma (stdout, addend);
1781 fixP->fx_offset = 0;
1783 md_number_to_chars (fixP->fx_frag->fr_literal + fixP->fx_where,
1785 fixP->fx_addsy = section_symbol (absolute_section);
1786 fixP->fx_offset += fixP->fx_frag->fr_address + fixP->fx_where;
1790 /* Write 8 bits, shifted left 13 bit positions. */
1794 *p |= (value << 5) & 0xe0;
1803 as_bad_where (fixP->fx_file, fixP->fx_line,
1804 "overflow in type-%d reloc", (int) fixP->fx_r_type);
1811 /* Don't want overflow checking. */
1814 if (fixP->fx_pcrel == 0
1815 && fixP->fx_addsy == 0)
1817 md_number_to_chars (p, value, size);
1818 /* @@ Overflow checks?? */
1824 if (fixP->fx_addsy != 0
1825 && fixP->fx_addsy->bsym->section != absolute_section)
1826 as_bad_where (fixP->fx_file, fixP->fx_line,
1827 "ret/jsr_coroutine requires constant in displacement field");
1828 else if (value >> 14 != 0)
1829 as_bad_where (fixP->fx_file, fixP->fx_line,
1830 "overflow in 14-bit operand field of ret or jsr_coroutine");
1831 *p++ = value & 0xff;
1833 *p = (*p & 0xc0) | (value & 0x3f);
1836 case BFD_RELOC_23_PCREL_S2:
1837 /* Write 21 bits only. */
1839 *p++ = value & 0xff;
1841 *p++ = value & 0xff;
1844 *p |= (value & 0x1f);
1847 case BFD_RELOC_ALPHA_LITERAL:
1848 case BFD_RELOC_ALPHA_LITUSE:
1851 case BFD_RELOC_GPREL32:
1852 assert (fixP->fx_subsy == gp);
1853 value = - alpha_gp_value; /* huh? this works... */
1855 md_number_to_chars (p, value, 4);
1858 case BFD_RELOC_ALPHA_HINT:
1859 if (fixP->fx_addsy == 0 && fixP->fx_pcrel == 0)
1867 as_fatal ("unknown relocation type %d?", fixP->fx_r_type);
1871 if (fixP->fx_addsy == 0 && fixP->fx_pcrel == 0)
1873 printf ("type %d reloc done?\n", fixP->fx_r_type);
1883 alpha_frob_ecoff_data ()
1886 /* $zero and $f31 are read-only */
1887 alpha_gprmask &= ~1;
1888 alpha_fprmask &= ~1;
1891 /* The Alpha has support for some VAX floating point types, as well as for
1892 IEEE floating point. We consider IEEE to be the primary floating point
1893 format, and sneak in the VAX floating point support here. */
1894 #define md_atof vax_md_atof
1895 #include "config/atof-vax.c"