blob: ba42aaa8bcc610b56976be784541007c3ee5dd2b [file] [log] [blame]
/* tc-alpha.c - Processor-specific code for the DEC Alpha AXP CPU.
Copyright 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
Free Software Foundation, Inc.
Contributed by Carnegie Mellon University, 1993.
Written by Alessandro Forin, based on earlier gas-1.38 target CPU files.
Modified by Ken Raeburn for gas-2.x and ECOFF support.
Modified by Richard Henderson for ELF support.
Modified by Klaus K"ampf for EVAX (OpenVMS/Alpha) support.
This file is part of GAS, the GNU Assembler.
GAS is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GAS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GAS; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
/*
* Mach Operating System
* Copyright (c) 1993 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
#include "as.h"
#include "subsegs.h"
#include "struc-symbol.h"
#include "ecoff.h"
#include "opcode/alpha.h"
#ifdef OBJ_ELF
#include "elf/alpha.h"
#include "dwarf2dbg.h"
#endif
#include <ctype.h>
/* Local types */
#define TOKENIZE_ERROR -1
#define TOKENIZE_ERROR_REPORT -2
#define MAX_INSN_FIXUPS 2
#define MAX_INSN_ARGS 5
struct alpha_fixup {
expressionS exp;
bfd_reloc_code_real_type reloc;
};
struct alpha_insn {
unsigned insn;
int nfixups;
struct alpha_fixup fixups[MAX_INSN_FIXUPS];
unsigned sequence[MAX_INSN_FIXUPS];
};
enum alpha_macro_arg {
MACRO_EOA = 1,
MACRO_IR,
MACRO_PIR,
MACRO_OPIR,
MACRO_CPIR,
MACRO_FPR,
MACRO_EXP,
MACRO_LITERAL,
MACRO_BASE,
MACRO_BYTOFF,
MACRO_JSR
};
struct alpha_macro {
const char *name;
void (*emit) PARAMS ((const expressionS *, int, const PTR));
const PTR arg;
enum alpha_macro_arg argsets[16];
};
/* Extra expression types. */
#define O_pregister O_md1 /* O_register, in parentheses */
#define O_cpregister O_md2 /* + a leading comma */
#ifdef RELOC_OP_P
/* Note, the alpha_reloc_op table below depends on the ordering
of O_literal .. O_gprelow. */
#define O_literal O_md3 /* !literal relocation */
#define O_lituse_base O_md4 /* !lituse_base relocation */
#define O_lituse_bytoff O_md5 /* !lituse_bytoff relocation */
#define O_lituse_jsr O_md6 /* !lituse_jsr relocation */
#define O_gpdisp O_md7 /* !gpdisp relocation */
#define O_gprelhigh O_md8 /* !gprelhigh relocation */
#define O_gprellow O_md9 /* !gprellow relocation */
#define USER_RELOC_P(R) ((R) >= O_literal && (R) <= O_gprellow)
#endif
/* Macros for extracting the type and number of encoded register tokens */
#define is_ir_num(x) (((x) & 32) == 0)
#define is_fpr_num(x) (((x) & 32) != 0)
#define regno(x) ((x) & 31)
/* Something odd inherited from the old assembler */
#define note_gpreg(R) (alpha_gprmask |= (1 << (R)))
#define note_fpreg(R) (alpha_fprmask |= (1 << (R)))
/* Predicates for 16- and 32-bit ranges */
/* XXX: The non-shift version appears to trigger a compiler bug when
cross-assembling from x86 w/ gcc 2.7.2. */
#if 1
#define range_signed_16(x) \
(((offsetT) (x) >> 15) == 0 || ((offsetT) (x) >> 15) == -1)
#define range_signed_32(x) \
(((offsetT) (x) >> 31) == 0 || ((offsetT) (x) >> 31) == -1)
#else
#define range_signed_16(x) ((offsetT) (x) >= -(offsetT) 0x8000 && \
(offsetT) (x) <= (offsetT) 0x7FFF)
#define range_signed_32(x) ((offsetT) (x) >= -(offsetT) 0x80000000 && \
(offsetT) (x) <= (offsetT) 0x7FFFFFFF)
#endif
/* Macros for sign extending from 16- and 32-bits. */
/* XXX: The cast macros will work on all the systems that I care about,
but really a predicate should be found to use the non-cast forms. */
#if 1
#define sign_extend_16(x) ((short) (x))
#define sign_extend_32(x) ((int) (x))
#else
#define sign_extend_16(x) ((offsetT) (((x) & 0xFFFF) ^ 0x8000) - 0x8000)
#define sign_extend_32(x) ((offsetT) (((x) & 0xFFFFFFFF) \
^ 0x80000000) - 0x80000000)
#endif
/* Macros to build tokens */
#define set_tok_reg(t, r) (memset (&(t), 0, sizeof (t)), \
(t).X_op = O_register, \
(t).X_add_number = (r))
#define set_tok_preg(t, r) (memset (&(t), 0, sizeof (t)), \
(t).X_op = O_pregister, \
(t).X_add_number = (r))
#define set_tok_cpreg(t, r) (memset (&(t), 0, sizeof (t)), \
(t).X_op = O_cpregister, \
(t).X_add_number = (r))
#define set_tok_freg(t, r) (memset (&(t), 0, sizeof (t)), \
(t).X_op = O_register, \
(t).X_add_number = (r) + 32)
#define set_tok_sym(t, s, a) (memset (&(t), 0, sizeof (t)), \
(t).X_op = O_symbol, \
(t).X_add_symbol = (s), \
(t).X_add_number = (a))
#define set_tok_const(t, n) (memset (&(t), 0, sizeof (t)), \
(t).X_op = O_constant, \
(t).X_add_number = (n))
/* Prototypes for all local functions */
static int tokenize_arguments PARAMS ((char *, expressionS *, int));
static const struct alpha_opcode *find_opcode_match
PARAMS ((const struct alpha_opcode *, const expressionS *, int *, int *));
static const struct alpha_macro *find_macro_match
PARAMS ((const struct alpha_macro *, const expressionS *, int *));
static unsigned insert_operand
PARAMS ((unsigned, const struct alpha_operand *, offsetT, char *, unsigned));
static void assemble_insn
PARAMS ((const struct alpha_opcode *, const expressionS *, int,
struct alpha_insn *));
static void emit_insn PARAMS ((struct alpha_insn *));
static void assemble_tokens_to_insn
PARAMS ((const char *, const expressionS *, int, struct alpha_insn *));
static void assemble_tokens
PARAMS ((const char *, const expressionS *, int, int));
static int load_expression
PARAMS ((int, const expressionS *, int *, expressionS *,
const expressionS *));
static void emit_ldgp PARAMS ((const expressionS *, int, const PTR));
static void emit_division PARAMS ((const expressionS *, int, const PTR));
static void emit_lda PARAMS ((const expressionS *, int, const PTR));
static void emit_ldah PARAMS ((const expressionS *, int, const PTR));
static void emit_ir_load PARAMS ((const expressionS *, int, const PTR));
static void emit_loadstore PARAMS ((const expressionS *, int, const PTR));
static void emit_jsrjmp PARAMS ((const expressionS *, int, const PTR));
static void emit_ldX PARAMS ((const expressionS *, int, const PTR));
static void emit_ldXu PARAMS ((const expressionS *, int, const PTR));
static void emit_uldX PARAMS ((const expressionS *, int, const PTR));
static void emit_uldXu PARAMS ((const expressionS *, int, const PTR));
static void emit_ldil PARAMS ((const expressionS *, int, const PTR));
static void emit_stX PARAMS ((const expressionS *, int, const PTR));
static void emit_ustX PARAMS ((const expressionS *, int, const PTR));
static void emit_sextX PARAMS ((const expressionS *, int, const PTR));
static void emit_retjcr PARAMS ((const expressionS *, int, const PTR));
static void s_alpha_text PARAMS ((int));
static void s_alpha_data PARAMS ((int));
#ifndef OBJ_ELF
static void s_alpha_comm PARAMS ((int));
static void s_alpha_rdata PARAMS ((int));
#endif
#ifdef OBJ_ECOFF
static void s_alpha_sdata PARAMS ((int));
#endif
#ifdef OBJ_ELF
static void s_alpha_section PARAMS ((int));
static void s_alpha_ent PARAMS ((int));
static void s_alpha_end PARAMS ((int));
static void s_alpha_mask PARAMS ((int));
static void s_alpha_frame PARAMS ((int));
static void s_alpha_prologue PARAMS ((int));
static void s_alpha_file PARAMS ((int));
static void s_alpha_loc PARAMS ((int));
static void s_alpha_stab PARAMS ((int));
static void s_alpha_coff_wrapper PARAMS ((int));
#endif
#ifdef OBJ_EVAX
static void s_alpha_section PARAMS ((int));
#endif
static void s_alpha_gprel32 PARAMS ((int));
static void s_alpha_float_cons PARAMS ((int));
static void s_alpha_proc PARAMS ((int));
static void s_alpha_set PARAMS ((int));
static void s_alpha_base PARAMS ((int));
static void s_alpha_align PARAMS ((int));
static void s_alpha_stringer PARAMS ((int));
static void s_alpha_space PARAMS ((int));
static void create_literal_section PARAMS ((const char *, segT *, symbolS **));
#ifndef OBJ_ELF
static void select_gp_value PARAMS ((void));
#endif
static void alpha_align PARAMS ((int, char *, symbolS *, int));
#ifdef RELOC_OP_P
static void alpha_adjust_symtab_relocs PARAMS ((bfd *, asection *, PTR));
#endif
/* Generic assembler global variables which must be defined by all
targets. */
/* Characters which always start a comment. */
const char comment_chars[] = "#";
/* Characters which start a comment at the beginning of a line. */
const char line_comment_chars[] = "#";
/* Characters which may be used to separate multiple commands on a
single line. */
const char line_separator_chars[] = ";";
/* Characters which are used to indicate an exponent in a floating
point number. */
const char EXP_CHARS[] = "eE";
/* Characters which mean that a number is a floating point constant,
as in 0d1.0. */
#if 0
const char FLT_CHARS[] = "dD";
#else
/* XXX: Do all of these really get used on the alpha?? */
char FLT_CHARS[] = "rRsSfFdDxXpP";
#endif
#ifdef OBJ_EVAX
const char *md_shortopts = "Fm:g+1h:HG:";
#else
const char *md_shortopts = "Fm:gG:";
#endif
struct option md_longopts[] = {
#define OPTION_32ADDR (OPTION_MD_BASE)
{ "32addr", no_argument, NULL, OPTION_32ADDR },
#define OPTION_RELAX (OPTION_32ADDR + 1)
{ "relax", no_argument, NULL, OPTION_RELAX },
#ifdef OBJ_ELF
#define OPTION_MDEBUG (OPTION_RELAX + 1)
#define OPTION_NO_MDEBUG (OPTION_MDEBUG + 1)
{ "mdebug", no_argument, NULL, OPTION_MDEBUG },
{ "no-mdebug", no_argument, NULL, OPTION_NO_MDEBUG },
#endif
{ NULL, no_argument, NULL, 0 }
};
size_t md_longopts_size = sizeof (md_longopts);
#ifdef OBJ_EVAX
#define AXP_REG_R0 0
#define AXP_REG_R16 16
#define AXP_REG_R17 17
#undef AXP_REG_T9
#define AXP_REG_T9 22
#undef AXP_REG_T10
#define AXP_REG_T10 23
#undef AXP_REG_T11
#define AXP_REG_T11 24
#undef AXP_REG_T12
#define AXP_REG_T12 25
#define AXP_REG_AI 25
#undef AXP_REG_FP
#define AXP_REG_FP 29
#undef AXP_REG_GP
#define AXP_REG_GP AXP_REG_PV
#endif /* OBJ_EVAX */
/* The cpu for which we are generating code */
static unsigned alpha_target = AXP_OPCODE_BASE;
static const char *alpha_target_name = "<all>";
/* The hash table of instruction opcodes */
static struct hash_control *alpha_opcode_hash;
/* The hash table of macro opcodes */
static struct hash_control *alpha_macro_hash;
#ifdef OBJ_ECOFF
/* The $gp relocation symbol */
static symbolS *alpha_gp_symbol;
/* XXX: what is this, and why is it exported? */
valueT alpha_gp_value;
#endif
/* The current $gp register */
static int alpha_gp_register = AXP_REG_GP;
/* A table of the register symbols */
static symbolS *alpha_register_table[64];
/* Constant sections, or sections of constants */
#ifdef OBJ_ECOFF
static segT alpha_lita_section;
static segT alpha_lit4_section;
#endif
#ifdef OBJ_EVAX
static segT alpha_link_section;
static segT alpha_ctors_section;
static segT alpha_dtors_section;
#endif
static segT alpha_lit8_section;
/* Symbols referring to said sections. */
#ifdef OBJ_ECOFF
static symbolS *alpha_lita_symbol;
static symbolS *alpha_lit4_symbol;
#endif
#ifdef OBJ_EVAX
static symbolS *alpha_link_symbol;
static symbolS *alpha_ctors_symbol;
static symbolS *alpha_dtors_symbol;
#endif
static symbolS *alpha_lit8_symbol;
/* Literal for .litX+0x8000 within .lita */
#ifdef OBJ_ECOFF
static offsetT alpha_lit4_literal;
static offsetT alpha_lit8_literal;
#endif
#ifdef OBJ_ELF
/* The active .ent symbol. */
static symbolS *alpha_cur_ent_sym;
#endif
/* Is the assembler not allowed to use $at? */
static int alpha_noat_on = 0;
/* Are macros enabled? */
static int alpha_macros_on = 1;
/* Are floats disabled? */
static int alpha_nofloats_on = 0;
/* Are addresses 32 bit? */
static int alpha_addr32_on = 0;
/* Symbol labelling the current insn. When the Alpha gas sees
foo:
.quad 0
and the section happens to not be on an eight byte boundary, it
will align both the symbol and the .quad to an eight byte boundary. */
static symbolS *alpha_insn_label;
/* Whether we should automatically align data generation pseudo-ops.
.align 0 will turn this off. */
static int alpha_auto_align_on = 1;
/* The known current alignment of the current section. */
static int alpha_current_align;
/* These are exported to ECOFF code. */
unsigned long alpha_gprmask, alpha_fprmask;
/* Whether the debugging option was seen. */
static int alpha_debug;
#ifdef OBJ_ELF
/* Whether we are emitting an mdebug section. */
int alpha_flag_mdebug = -1;
#endif
/* Don't fully resolve relocations, allowing code movement in the linker. */
static int alpha_flag_relax;
/* What value to give to bfd_set_gp_size. */
static int g_switch_value = 8;
#ifdef OBJ_EVAX
/* Collect information about current procedure here. */
static struct {
symbolS *symbol; /* proc pdesc symbol */
int pdsckind;
int framereg; /* register for frame pointer */
int framesize; /* size of frame */
int rsa_offset;
int ra_save;
int fp_save;
long imask;
long fmask;
int type;
int prologue;
} alpha_evax_proc;
static int alpha_flag_hash_long_names = 0; /* -+ */
static int alpha_flag_show_after_trunc = 0; /* -H */
/* If the -+ switch is given, then a hash is appended to any name that is
* longer than 64 characters, else longer symbol names are truncated.
*/
#endif
#ifdef RELOC_OP_P
/* A table to map the spelling of a relocation operand into an appropriate
bfd_reloc_code_real_type type. The table is assumed to be ordered such
that op-O_literal indexes into it. */
#define ALPHA_RELOC_TABLE(op) \
&alpha_reloc_op[ ((!USER_RELOC_P (op)) \
? (abort (), 0) \
: (int) (op) - (int) O_literal) ]
#define LITUSE_BASE 1
#define LITUSE_BYTOFF 2
#define LITUSE_JSR 3
static const struct alpha_reloc_op_tag {
const char *name; /* string to lookup */
size_t length; /* size of the string */
bfd_reloc_code_real_type reloc; /* relocation before frob */
operatorT op; /* which operator to use */
int lituse; /* addened to specify lituse */
} alpha_reloc_op[] = {
{
"literal", /* name */
sizeof ("literal")-1, /* length */
BFD_RELOC_ALPHA_USER_LITERAL, /* reloc */
O_literal, /* op */
0, /* lituse */
},
{
"lituse_base", /* name */
sizeof ("lituse_base")-1, /* length */
BFD_RELOC_ALPHA_USER_LITUSE_BASE, /* reloc */
O_lituse_base, /* op */
LITUSE_BASE, /* lituse */
},
{
"lituse_bytoff", /* name */
sizeof ("lituse_bytoff")-1, /* length */
BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF, /* reloc */
O_lituse_bytoff, /* op */
LITUSE_BYTOFF, /* lituse */
},
{
"lituse_jsr", /* name */
sizeof ("lituse_jsr")-1, /* length */
BFD_RELOC_ALPHA_USER_LITUSE_JSR, /* reloc */
O_lituse_jsr, /* op */
LITUSE_JSR, /* lituse */
},
{
"gpdisp", /* name */
sizeof ("gpdisp")-1, /* length */
BFD_RELOC_ALPHA_USER_GPDISP, /* reloc */
O_gpdisp, /* op */
0, /* lituse */
},
{
"gprelhigh", /* name */
sizeof ("gprelhigh")-1, /* length */
BFD_RELOC_ALPHA_USER_GPRELHIGH, /* reloc */
O_gprelhigh, /* op */
0, /* lituse */
},
{
"gprellow", /* name */
sizeof ("gprellow")-1, /* length */
BFD_RELOC_ALPHA_USER_GPRELLOW, /* reloc */
O_gprellow, /* op */
0, /* lituse */
},
};
static const int alpha_num_reloc_op
= sizeof (alpha_reloc_op) / sizeof (*alpha_reloc_op);
/* Maximum # digits needed to hold the largest sequence # */
#define ALPHA_RELOC_DIGITS 25
/* Whether a sequence number is valid. */
#define ALPHA_RELOC_SEQUENCE_OK(X) ((X) > 0 && ((unsigned) (X)) == (X))
/* Structure to hold explict sequence information. */
struct alpha_literal_tag
{
fixS *lituse; /* head of linked list of !literals */
segT segment; /* segment relocs are in or undefined_section*/
int multi_section_p; /* True if more than one section was used */
unsigned sequence; /* sequence # */
unsigned n_literals; /* # of literals */
unsigned n_lituses; /* # of lituses */
char string[1]; /* printable form of sequence to hash with */
};
/* Hash table to link up literals with the appropriate lituse */
static struct hash_control *alpha_literal_hash;
#endif
/* A table of CPU names and opcode sets. */
static const struct cpu_type {
const char *name;
unsigned flags;
} cpu_types[] = {
/* Ad hoc convention: cpu number gets palcode, process code doesn't.
This supports usage under DU 4.0b that does ".arch ev4", and
usage in MILO that does -m21064. Probably something more
specific like -m21064-pal should be used, but oh well. */
{ "21064", AXP_OPCODE_BASE|AXP_OPCODE_EV4 },
{ "21064a", AXP_OPCODE_BASE|AXP_OPCODE_EV4 },
{ "21066", AXP_OPCODE_BASE|AXP_OPCODE_EV4 },
{ "21068", AXP_OPCODE_BASE|AXP_OPCODE_EV4 },
{ "21164", AXP_OPCODE_BASE|AXP_OPCODE_EV5 },
{ "21164a", AXP_OPCODE_BASE|AXP_OPCODE_EV5|AXP_OPCODE_BWX },
{ "21164pc", (AXP_OPCODE_BASE|AXP_OPCODE_EV5|AXP_OPCODE_BWX
|AXP_OPCODE_MAX) },
{ "21264", (AXP_OPCODE_BASE|AXP_OPCODE_EV6|AXP_OPCODE_BWX
|AXP_OPCODE_MAX|AXP_OPCODE_CIX) },
{ "ev4", AXP_OPCODE_BASE },
{ "ev45", AXP_OPCODE_BASE },
{ "lca45", AXP_OPCODE_BASE },
{ "ev5", AXP_OPCODE_BASE },
{ "ev56", AXP_OPCODE_BASE|AXP_OPCODE_BWX },
{ "pca56", AXP_OPCODE_BASE|AXP_OPCODE_BWX|AXP_OPCODE_MAX },
{ "ev6", AXP_OPCODE_BASE|AXP_OPCODE_BWX|AXP_OPCODE_MAX|AXP_OPCODE_CIX },
{ "all", AXP_OPCODE_BASE },
{ 0, 0 }
};
/* The macro table */
static const struct alpha_macro alpha_macros[] = {
/* Load/Store macros */
{ "lda", emit_lda, NULL,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_LITERAL, MACRO_BASE, MACRO_EOA } },
{ "ldah", emit_ldah, NULL,
{ MACRO_IR, MACRO_EXP, MACRO_EOA } },
{ "ldl", emit_ir_load, "ldl",
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ldl_l", emit_ir_load, "ldl_l",
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ldq", emit_ir_load, "ldq",
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_LITERAL, MACRO_EOA } },
{ "ldq_l", emit_ir_load, "ldq_l",
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ldq_u", emit_ir_load, "ldq_u",
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ldf", emit_loadstore, "ldf",
{ MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ldg", emit_loadstore, "ldg",
{ MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "lds", emit_loadstore, "lds",
{ MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ldt", emit_loadstore, "ldt",
{ MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ldb", emit_ldX, (PTR) 0,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ldbu", emit_ldXu, (PTR) 0,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ldw", emit_ldX, (PTR) 1,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ldwu", emit_ldXu, (PTR) 1,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "uldw", emit_uldX, (PTR) 1,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "uldwu", emit_uldXu, (PTR) 1,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "uldl", emit_uldX, (PTR) 2,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "uldlu", emit_uldXu, (PTR) 2,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "uldq", emit_uldXu, (PTR) 3,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ldgp", emit_ldgp, NULL,
{ MACRO_IR, MACRO_EXP, MACRO_PIR, MACRO_EOA } },
{ "ldi", emit_lda, NULL,
{ MACRO_IR, MACRO_EXP, MACRO_EOA } },
{ "ldil", emit_ldil, NULL,
{ MACRO_IR, MACRO_EXP, MACRO_EOA } },
{ "ldiq", emit_lda, NULL,
{ MACRO_IR, MACRO_EXP, MACRO_EOA } },
#if 0
{ "ldif" emit_ldiq, NULL,
{ MACRO_FPR, MACRO_EXP, MACRO_EOA } },
{ "ldid" emit_ldiq, NULL,
{ MACRO_FPR, MACRO_EXP, MACRO_EOA } },
{ "ldig" emit_ldiq, NULL,
{ MACRO_FPR, MACRO_EXP, MACRO_EOA } },
{ "ldis" emit_ldiq, NULL,
{ MACRO_FPR, MACRO_EXP, MACRO_EOA } },
{ "ldit" emit_ldiq, NULL,
{ MACRO_FPR, MACRO_EXP, MACRO_EOA } },
#endif
{ "stl", emit_loadstore, "stl",
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "stl_c", emit_loadstore, "stl_c",
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "stq", emit_loadstore, "stq",
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "stq_c", emit_loadstore, "stq_c",
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "stq_u", emit_loadstore, "stq_u",
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "stf", emit_loadstore, "stf",
{ MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "stg", emit_loadstore, "stg",
{ MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "sts", emit_loadstore, "sts",
{ MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "stt", emit_loadstore, "stt",
{ MACRO_FPR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "stb", emit_stX, (PTR) 0,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "stw", emit_stX, (PTR) 1,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ustw", emit_ustX, (PTR) 1,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ustl", emit_ustX, (PTR) 2,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
{ "ustq", emit_ustX, (PTR) 3,
{ MACRO_IR, MACRO_EXP, MACRO_OPIR, MACRO_BASE, MACRO_EOA } },
/* Arithmetic macros */
#if 0
{ "absl" emit_absl, 1, { IR } },
{ "absl" emit_absl, 2, { IR, IR } },
{ "absl" emit_absl, 2, { EXP, IR } },
{ "absq" emit_absq, 1, { IR } },
{ "absq" emit_absq, 2, { IR, IR } },
{ "absq" emit_absq, 2, { EXP, IR } },
#endif
{ "sextb", emit_sextX, (PTR) 0,
{ MACRO_IR, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_EOA,
/* MACRO_EXP, MACRO_IR, MACRO_EOA */ } },
{ "sextw", emit_sextX, (PTR) 1,
{ MACRO_IR, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_EOA,
/* MACRO_EXP, MACRO_IR, MACRO_EOA */ } },
{ "divl", emit_division, "__divl",
{ MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_IR, MACRO_EOA,
/* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
{ "divlu", emit_division, "__divlu",
{ MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_IR, MACRO_EOA,
/* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
{ "divq", emit_division, "__divq",
{ MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_IR, MACRO_EOA,
/* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
{ "divqu", emit_division, "__divqu",
{ MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_IR, MACRO_EOA,
/* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
{ "reml", emit_division, "__reml",
{ MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_IR, MACRO_EOA,
/* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
{ "remlu", emit_division, "__remlu",
{ MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_IR, MACRO_EOA,
/* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
{ "remq", emit_division, "__remq",
{ MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_IR, MACRO_EOA,
/* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
{ "remqu", emit_division, "__remqu",
{ MACRO_IR, MACRO_IR, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_IR, MACRO_EOA,
/* MACRO_IR, MACRO_EXP, MACRO_IR, MACRO_EOA,
MACRO_IR, MACRO_EXP, MACRO_EOA */ } },
{ "jsr", emit_jsrjmp, "jsr",
{ MACRO_PIR, MACRO_EXP, MACRO_JSR, MACRO_EOA,
MACRO_PIR, MACRO_JSR, MACRO_EOA,
MACRO_IR, MACRO_EXP, MACRO_JSR, MACRO_EOA,
MACRO_EXP, MACRO_JSR, MACRO_EOA } },
{ "jmp", emit_jsrjmp, "jmp",
{ MACRO_PIR, MACRO_EXP, MACRO_JSR, MACRO_EOA,
MACRO_PIR, MACRO_JSR, MACRO_EOA,
MACRO_IR, MACRO_EXP, MACRO_JSR, MACRO_EOA,
MACRO_EXP, MACRO_JSR, MACRO_EOA } },
{ "ret", emit_retjcr, "ret",
{ MACRO_IR, MACRO_EXP, MACRO_EOA,
MACRO_IR, MACRO_EOA,
MACRO_PIR, MACRO_EXP, MACRO_EOA,
MACRO_PIR, MACRO_EOA,
MACRO_EXP, MACRO_EOA,
MACRO_EOA } },
{ "jcr", emit_retjcr, "jcr",
{ MACRO_IR, MACRO_EXP, MACRO_EOA,
MACRO_IR, MACRO_EOA,
MACRO_PIR, MACRO_EXP, MACRO_EOA,
MACRO_PIR, MACRO_EOA,
MACRO_EXP, MACRO_EOA,
MACRO_EOA } },
{ "jsr_coroutine", emit_retjcr, "jcr",
{ MACRO_IR, MACRO_EXP, MACRO_EOA,
MACRO_IR, MACRO_EOA,
MACRO_PIR, MACRO_EXP, MACRO_EOA,
MACRO_PIR, MACRO_EOA,
MACRO_EXP, MACRO_EOA,
MACRO_EOA } },
};
static const unsigned int alpha_num_macros
= sizeof (alpha_macros) / sizeof (*alpha_macros);
/* Public interface functions */
/* This function is called once, at assembler startup time. It sets
up all the tables, etc. that the MD part of the assembler will
need, that can be determined before arguments are parsed. */
void
md_begin ()
{
unsigned int i;
/* Verify that X_op field is wide enough. */
{
expressionS e;
e.X_op = O_max;
assert (e.X_op == O_max);
}
/* Create the opcode hash table */
alpha_opcode_hash = hash_new ();
for (i = 0; i < alpha_num_opcodes;)
{
const char *name, *retval, *slash;
name = alpha_opcodes[i].name;
retval = hash_insert (alpha_opcode_hash, name, (PTR) &alpha_opcodes[i]);
if (retval)
as_fatal (_("internal error: can't hash opcode `%s': %s"), name, retval);
/* Some opcodes include modifiers of various sorts with a "/mod"
syntax, like the architecture manual suggests. However, for
use with gcc at least, we also need access to those same opcodes
without the "/". */
if ((slash = strchr (name, '/')) != NULL)
{
char *p = xmalloc (strlen (name));
memcpy (p, name, slash - name);
strcpy (p + (slash - name), slash + 1);
(void) hash_insert (alpha_opcode_hash, p, (PTR) &alpha_opcodes[i]);
/* Ignore failures -- the opcode table does duplicate some
variants in different forms, like "hw_stq" and "hw_st/q". */
}
while (++i < alpha_num_opcodes
&& (alpha_opcodes[i].name == name
|| !strcmp (alpha_opcodes[i].name, name)))
continue;
}
/* Create the macro hash table */
alpha_macro_hash = hash_new ();
for (i = 0; i < alpha_num_macros;)
{
const char *name, *retval;
name = alpha_macros[i].name;
retval = hash_insert (alpha_macro_hash, name, (PTR) &alpha_macros[i]);
if (retval)
as_fatal (_("internal error: can't hash macro `%s': %s"),
name, retval);
while (++i < alpha_num_macros
&& (alpha_macros[i].name == name
|| !strcmp (alpha_macros[i].name, name)))
continue;
}
/* Construct symbols for each of the registers */
for (i = 0; i < 32; ++i)
{
char name[4];
sprintf (name, "$%d", i);
alpha_register_table[i] = symbol_create (name, reg_section, i,
&zero_address_frag);
}
for (; i < 64; ++i)
{
char name[5];
sprintf (name, "$f%d", i - 32);
alpha_register_table[i] = symbol_create (name, reg_section, i,
&zero_address_frag);
}
/* Create the special symbols and sections we'll be using */
/* So .sbss will get used for tiny objects. */
bfd_set_gp_size (stdoutput, g_switch_value);
#ifdef OBJ_ECOFF
create_literal_section (".lita", &alpha_lita_section, &alpha_lita_symbol);
/* For handling the GP, create a symbol that won't be output in the
symbol table. We'll edit it out of relocs later. */
alpha_gp_symbol = symbol_create ("<GP value>", alpha_lita_section, 0x8000,
&zero_address_frag);
#endif
#ifdef OBJ_EVAX
create_literal_section (".link", &alpha_link_section, &alpha_link_symbol);
#endif
#ifdef OBJ_ELF
if (ECOFF_DEBUGGING)
{
segT sec = subseg_new (".mdebug", (subsegT) 0);
bfd_set_section_flags (stdoutput, sec, SEC_HAS_CONTENTS | SEC_READONLY);
bfd_set_section_alignment (stdoutput, sec, 3);
}
#endif /* OBJ_ELF */
subseg_set (text_section, 0);
#ifdef RELOC_OP_P
/* Create literal lookup hash table. */
alpha_literal_hash = hash_new ();
#endif
}
/* The public interface to the instruction assembler. */
void
md_assemble (str)
char *str;
{
char opname[32]; /* current maximum is 13 */
expressionS tok[MAX_INSN_ARGS];
int ntok, trunclen;
size_t opnamelen;
/* split off the opcode */
opnamelen = strspn (str, "abcdefghijklmnopqrstuvwxyz_/46819");
trunclen = (opnamelen < sizeof (opname) - 1
? opnamelen
: sizeof (opname) - 1);
memcpy (opname, str, trunclen);
opname[trunclen] = '\0';
/* tokenize the rest of the line */
if ((ntok = tokenize_arguments (str + opnamelen, tok, MAX_INSN_ARGS)) < 0)
{
if (ntok != TOKENIZE_ERROR_REPORT)
as_bad (_("syntax error"));
return;
}
/* finish it off */
assemble_tokens (opname, tok, ntok, alpha_macros_on);
}
/* Round up a section's size to the appropriate boundary. */
valueT
md_section_align (seg, size)
segT seg;
valueT size;
{
int align = bfd_get_section_alignment (stdoutput, seg);
valueT mask = ((valueT) 1 << align) - 1;
return (size + mask) & ~mask;
}
/* Turn a string in input_line_pointer into a floating point constant
of type TYPE, and store the appropriate bytes in *LITP. The number
of LITTLENUMS emitted is stored in *SIZEP. An error message is
returned, or NULL on OK. */
/* Equal to MAX_PRECISION in atof-ieee.c */
#define MAX_LITTLENUMS 6
extern char *vax_md_atof PARAMS ((int, char *, int *));
char *
md_atof (type, litP, sizeP)
char type;
char *litP;
int *sizeP;
{
int prec;
LITTLENUM_TYPE words[MAX_LITTLENUMS];
LITTLENUM_TYPE *wordP;
char *t;
switch (type)
{
/* VAX floats */
case 'G':
/* VAX md_atof doesn't like "G" for some reason. */
type = 'g';
case 'F':
case 'D':
return vax_md_atof (type, litP, sizeP);
/* IEEE floats */
case 'f':
prec = 2;
break;
case 'd':
prec = 4;
break;
case 'x':
case 'X':
prec = 6;
break;
case 'p':
case 'P':
prec = 6;
break;
default:
*sizeP = 0;
return _("Bad call to MD_ATOF()");
}
t = atof_ieee (input_line_pointer, type, words);
if (t)
input_line_pointer = t;
*sizeP = prec * sizeof (LITTLENUM_TYPE);
for (wordP = words + prec - 1; prec--;)
{
md_number_to_chars (litP, (long) (*wordP--), sizeof (LITTLENUM_TYPE));
litP += sizeof (LITTLENUM_TYPE);
}
return 0;
}
/* Take care of the target-specific command-line options. */
int
md_parse_option (c, arg)
int c;
char *arg;
{
switch (c)
{
case 'F':
alpha_nofloats_on = 1;
break;
case OPTION_32ADDR:
alpha_addr32_on = 1;
break;
case 'g':
alpha_debug = 1;
break;
case 'G':
g_switch_value = atoi (arg);
break;
case 'm':
{
const struct cpu_type *p;
for (p = cpu_types; p->name; ++p)
if (strcmp (arg, p->name) == 0)
{
alpha_target_name = p->name, alpha_target = p->flags;
goto found;
}
as_warn (_("Unknown CPU identifier `%s'"), arg);
found:;
}
break;
#ifdef OBJ_EVAX
case '+': /* For g++. Hash any name > 63 chars long. */
alpha_flag_hash_long_names = 1;
break;
case 'H': /* Show new symbol after hash truncation */
alpha_flag_show_after_trunc = 1;
break;
case 'h': /* for gnu-c/vax compatibility. */
break;
#endif
case OPTION_RELAX:
alpha_flag_relax = 1;
break;
#ifdef OBJ_ELF
case OPTION_MDEBUG:
alpha_flag_mdebug = 1;
break;
case OPTION_NO_MDEBUG:
alpha_flag_mdebug = 0;
break;
#endif
default:
return 0;
}
return 1;
}
/* Print a description of the command-line options that we accept. */
void
md_show_usage (stream)
FILE *stream;
{
fputs (_("\
Alpha options:\n\
-32addr treat addresses as 32-bit values\n\
-F lack floating point instructions support\n\
-mev4 | -mev45 | -mev5 | -mev56 | -mpca56 | -mev6 | -mall\n\
specify variant of Alpha architecture\n\
-m21064 | -m21066 | -m21164 | -m21164a | -m21164pc | -m21264\n\
these variants include PALcode opcodes\n"),
stream);
#ifdef OBJ_EVAX
fputs (_("\
VMS options:\n\
-+ hash encode (don't truncate) names longer than 64 characters\n\
-H show new symbol after hash truncation\n"),
stream);
#endif
}
/* Decide from what point a pc-relative relocation is relative to,
relative to the pc-relative fixup. Er, relatively speaking. */
long
md_pcrel_from (fixP)
fixS *fixP;
{
valueT addr = fixP->fx_where + fixP->fx_frag->fr_address;
switch (fixP->fx_r_type)
{
case BFD_RELOC_ALPHA_GPDISP:
case BFD_RELOC_ALPHA_GPDISP_HI16:
case BFD_RELOC_ALPHA_GPDISP_LO16:
return addr;
default:
return fixP->fx_size + addr;
}
}
/* Attempt to simplify or even eliminate a fixup. The return value is
ignored; perhaps it was once meaningful, but now it is historical.
To indicate that a fixup has been eliminated, set fixP->fx_done.
For ELF, here it is that we transform the GPDISP_HI16 reloc we used
internally into the GPDISP reloc used externally. We had to do
this so that we'd have the GPDISP_LO16 reloc as a tag to compute
the distance to the "lda" instruction for setting the addend to
GPDISP. */
int
md_apply_fix (fixP, valueP)
fixS *fixP;
valueT *valueP;
{
char * const fixpos = fixP->fx_frag->fr_literal + fixP->fx_where;
valueT value = *valueP;
unsigned image, size;
switch (fixP->fx_r_type)
{
/* The GPDISP relocations are processed internally with a symbol
referring to the current function; we need to drop in a value
which, when added to the address of the start of the function,
gives the desired GP. */
case BFD_RELOC_ALPHA_GPDISP_HI16:
{
fixS *next = fixP->fx_next;
assert (next->fx_r_type == BFD_RELOC_ALPHA_GPDISP_LO16);
fixP->fx_offset = (next->fx_frag->fr_address + next->fx_where
- fixP->fx_frag->fr_address - fixP->fx_where);
value = (value - sign_extend_16 (value)) >> 16;
}
#ifdef OBJ_ELF
fixP->fx_r_type = BFD_RELOC_ALPHA_GPDISP;
#endif
goto do_reloc_gp;
case BFD_RELOC_ALPHA_GPDISP_LO16:
value = sign_extend_16 (value);
fixP->fx_offset = 0;
#ifdef OBJ_ELF
fixP->fx_done = 1;
#endif
do_reloc_gp:
fixP->fx_addsy = section_symbol (now_seg);
md_number_to_chars (fixpos, value, 2);
break;
case BFD_RELOC_16:
if (fixP->fx_pcrel)
fixP->fx_r_type = BFD_RELOC_16_PCREL;
size = 2;
goto do_reloc_xx;
case BFD_RELOC_32:
if (fixP->fx_pcrel)
fixP->fx_r_type = BFD_RELOC_32_PCREL;
size = 4;
goto do_reloc_xx;
case BFD_RELOC_64:
if (fixP->fx_pcrel)
fixP->fx_r_type = BFD_RELOC_64_PCREL;
size = 8;
do_reloc_xx:
if (fixP->fx_pcrel == 0 && fixP->fx_addsy == 0)
{
md_number_to_chars (fixpos, value, size);
goto done;
}
return 1;
#ifdef OBJ_ECOFF
case BFD_RELOC_GPREL32:
assert (fixP->fx_subsy == alpha_gp_symbol);
fixP->fx_subsy = 0;
/* FIXME: inherited this obliviousness of `value' -- why? */
md_number_to_chars (fixpos, -alpha_gp_value, 4);
break;
#endif
#ifdef OBJ_ELF
case BFD_RELOC_GPREL32:
return 1;
#endif
case BFD_RELOC_23_PCREL_S2:
if (fixP->fx_pcrel == 0 && fixP->fx_addsy == 0)
{
image = bfd_getl32 (fixpos);
image = (image & ~0x1FFFFF) | ((value >> 2) & 0x1FFFFF);
goto write_done;
}
return 1;
case BFD_RELOC_ALPHA_HINT:
if (fixP->fx_pcrel == 0 && fixP->fx_addsy == 0)
{
image = bfd_getl32 (fixpos);
image = (image & ~0x3FFF) | ((value >> 2) & 0x3FFF);
goto write_done;
}
return 1;
#ifdef OBJ_ECOFF
case BFD_RELOC_ALPHA_LITERAL:
md_number_to_chars (fixpos, value, 2);
return 1;
case BFD_RELOC_ALPHA_LITUSE:
return 1;
#endif
#ifdef OBJ_ELF
case BFD_RELOC_ALPHA_ELF_LITERAL:
case BFD_RELOC_ALPHA_LITUSE:
return 1;
#endif
#ifdef OBJ_EVAX
case BFD_RELOC_ALPHA_LINKAGE:
case BFD_RELOC_ALPHA_CODEADDR:
return 1;
#endif
#ifdef RELOC_OP_P
case BFD_RELOC_ALPHA_USER_LITERAL:
case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
return 1;
case BFD_RELOC_ALPHA_USER_GPDISP:
case BFD_RELOC_ALPHA_USER_GPRELHIGH:
case BFD_RELOC_ALPHA_USER_GPRELLOW:
abort ();
#endif
case BFD_RELOC_VTABLE_INHERIT:
case BFD_RELOC_VTABLE_ENTRY:
return 1;
default:
{
const struct alpha_operand *operand;
if ((int) fixP->fx_r_type >= 0)
as_fatal (_("unhandled relocation type %s"),
bfd_get_reloc_code_name (fixP->fx_r_type));
assert (-(int) fixP->fx_r_type < (int) alpha_num_operands);
operand = &alpha_operands[-(int) fixP->fx_r_type];
/* The rest of these fixups only exist internally during symbol
resolution and have no representation in the object file.
Therefore they must be completely resolved as constants. */
if (fixP->fx_addsy != 0
&& S_GET_SEGMENT (fixP->fx_addsy) != absolute_section)
as_bad_where (fixP->fx_file, fixP->fx_line,
_("non-absolute expression in constant field"));
image = bfd_getl32 (fixpos);
image = insert_operand (image, operand, (offsetT) value,
fixP->fx_file, fixP->fx_line);
}
goto write_done;
}
if (fixP->fx_addsy != 0 || fixP->fx_pcrel != 0)
return 1;
else
{
as_warn_where (fixP->fx_file, fixP->fx_line,
_("type %d reloc done?\n"), (int) fixP->fx_r_type);
goto done;
}
write_done:
md_number_to_chars (fixpos, image, 4);
done:
fixP->fx_done = 1;
return 0;
}
/*
* Look for a register name in the given symbol.
*/
symbolS *
md_undefined_symbol (name)
char *name;
{
if (*name == '$')
{
int is_float = 0, num;
switch (*++name)
{
case 'f':
if (name[1] == 'p' && name[2] == '\0')
return alpha_register_table[AXP_REG_FP];
is_float = 32;
/* FALLTHRU */
case 'r':
if (!isdigit (*++name))
break;
/* FALLTHRU */
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
if (name[1] == '\0')
num = name[0] - '0';
else if (name[0] != '0' && isdigit (name[1]) && name[2] == '\0')
{
num = (name[0] - '0') * 10 + name[1] - '0';
if (num >= 32)
break;
}
else
break;
if (!alpha_noat_on && (num + is_float) == AXP_REG_AT)
as_warn (_("Used $at without \".set noat\""));
return alpha_register_table[num + is_float];
case 'a':
if (name[1] == 't' && name[2] == '\0')
{
if (!alpha_noat_on)
as_warn (_("Used $at without \".set noat\""));
return alpha_register_table[AXP_REG_AT];
}
break;
case 'g':
if (name[1] == 'p' && name[2] == '\0')
return alpha_register_table[alpha_gp_register];
break;
case 's':
if (name[1] == 'p' && name[2] == '\0')
return alpha_register_table[AXP_REG_SP];
break;
}
}
return NULL;
}
#ifdef OBJ_ECOFF
/* @@@ Magic ECOFF bits. */
void
alpha_frob_ecoff_data ()
{
select_gp_value ();
/* $zero and $f31 are read-only */
alpha_gprmask &= ~1;
alpha_fprmask &= ~1;
}
#endif
/* Hook to remember a recently defined label so that the auto-align
code can adjust the symbol after we know what alignment will be
required. */
void
alpha_define_label (sym)
symbolS *sym;
{
alpha_insn_label = sym;
}
/* Return true if we must always emit a reloc for a type and false if
there is some hope of resolving it a assembly time. */
int
alpha_force_relocation (f)
fixS *f;
{
if (alpha_flag_relax)
return 1;
switch (f->fx_r_type)
{
case BFD_RELOC_ALPHA_GPDISP_HI16:
case BFD_RELOC_ALPHA_GPDISP_LO16:
case BFD_RELOC_ALPHA_GPDISP:
#ifdef OBJ_ECOFF
case BFD_RELOC_ALPHA_LITERAL:
#endif
#ifdef OBJ_ELF
case BFD_RELOC_ALPHA_ELF_LITERAL:
#endif
case BFD_RELOC_ALPHA_LITUSE:
case BFD_RELOC_GPREL32:
#ifdef OBJ_EVAX
case BFD_RELOC_ALPHA_LINKAGE:
case BFD_RELOC_ALPHA_CODEADDR:
#endif
#ifdef RELOC_OP_P
case BFD_RELOC_ALPHA_USER_LITERAL:
case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
case BFD_RELOC_ALPHA_USER_GPDISP:
case BFD_RELOC_ALPHA_USER_GPRELHIGH:
case BFD_RELOC_ALPHA_USER_GPRELLOW:
#endif
case BFD_RELOC_VTABLE_INHERIT:
case BFD_RELOC_VTABLE_ENTRY:
return 1;
case BFD_RELOC_23_PCREL_S2:
case BFD_RELOC_32:
case BFD_RELOC_64:
case BFD_RELOC_ALPHA_HINT:
return 0;
default:
assert ((int) f->fx_r_type < 0
&& -(int) f->fx_r_type < (int) alpha_num_operands);
return 0;
}
}
/* Return true if we can partially resolve a relocation now. */
int
alpha_fix_adjustable (f)
fixS *f;
{
#ifdef OBJ_ELF
/* Prevent all adjustments to global symbols */
if (S_IS_EXTERN (f->fx_addsy) || S_IS_WEAK (f->fx_addsy))
return 0;
#endif
/* Are there any relocation types for which we must generate a reloc
but we can adjust the values contained within it? */
switch (f->fx_r_type)
{
case BFD_RELOC_ALPHA_GPDISP_HI16:
case BFD_RELOC_ALPHA_GPDISP_LO16:
case BFD_RELOC_ALPHA_GPDISP:
return 0;
#ifdef OBJ_ECOFF
case BFD_RELOC_ALPHA_LITERAL:
#endif
#ifdef OBJ_ELF
case BFD_RELOC_ALPHA_ELF_LITERAL:
#endif
#ifdef RELOC_OP_P
case BFD_RELOC_ALPHA_USER_LITERAL:
#endif
#ifdef OBJ_EVAX
case BFD_RELOC_ALPHA_LINKAGE:
case BFD_RELOC_ALPHA_CODEADDR:
#endif
return 1;
case BFD_RELOC_ALPHA_LITUSE:
#ifdef RELOC_OP_P
case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
case BFD_RELOC_ALPHA_USER_GPDISP:
case BFD_RELOC_ALPHA_USER_GPRELHIGH:
case BFD_RELOC_ALPHA_USER_GPRELLOW:
#endif
case BFD_RELOC_VTABLE_ENTRY:
case BFD_RELOC_VTABLE_INHERIT:
return 0;
case BFD_RELOC_GPREL32:
case BFD_RELOC_23_PCREL_S2:
case BFD_RELOC_32:
case BFD_RELOC_64:
case BFD_RELOC_ALPHA_HINT:
return 1;
default:
assert ((int) f->fx_r_type < 0
&& - (int) f->fx_r_type < (int) alpha_num_operands);
return 1;
}
/*NOTREACHED*/
}
/* Generate the BFD reloc to be stuck in the object file from the
fixup used internally in the assembler. */
arelent *
tc_gen_reloc (sec, fixp)
asection *sec ATTRIBUTE_UNUSED;
fixS *fixp;
{
arelent *reloc;
reloc = (arelent *) xmalloc (sizeof (arelent));
reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
*reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
/* Make sure none of our internal relocations make it this far.
They'd better have been fully resolved by this point. */
assert ((int) fixp->fx_r_type > 0);
reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
if (reloc->howto == NULL)
{
as_bad_where (fixp->fx_file, fixp->fx_line,
_("cannot represent `%s' relocation in object file"),
bfd_get_reloc_code_name (fixp->fx_r_type));
return NULL;
}
if (!fixp->fx_pcrel != !reloc->howto->pc_relative)
{
as_fatal (_("internal error? cannot generate `%s' relocation"),
bfd_get_reloc_code_name (fixp->fx_r_type));
}
assert (!fixp->fx_pcrel == !reloc->howto->pc_relative);
#ifdef OBJ_ECOFF
if (fixp->fx_r_type == BFD_RELOC_ALPHA_LITERAL)
{
/* fake out bfd_perform_relocation. sigh */
reloc->addend = -alpha_gp_value;
}
else
#endif
{
reloc->addend = fixp->fx_offset;
#ifdef OBJ_ELF
/*
* Ohhh, this is ugly. The problem is that if this is a local global
* symbol, the relocation will entirely be performed at link time, not
* at assembly time. bfd_perform_reloc doesn't know about this sort
* of thing, and as a result we need to fake it out here.
*/
if ((S_IS_EXTERN (fixp->fx_addsy) || S_IS_WEAK (fixp->fx_addsy))
&& !S_IS_COMMON (fixp->fx_addsy))
reloc->addend -= symbol_get_bfdsym (fixp->fx_addsy)->value;
#endif
}
return reloc;
}
/* Parse a register name off of the input_line and return a register
number. Gets md_undefined_symbol above to do the register name
matching for us.
Only called as a part of processing the ECOFF .frame directive. */
int
tc_get_register (frame)
int frame ATTRIBUTE_UNUSED;
{
int framereg = AXP_REG_SP;
SKIP_WHITESPACE ();
if (*input_line_pointer == '$')
{
char *s = input_line_pointer;
char c = get_symbol_end ();
symbolS *sym = md_undefined_symbol (s);
*strchr (s, '\0') = c;
if (sym && (framereg = S_GET_VALUE (sym)) <= 31)
goto found;
}
as_warn (_("frame reg expected, using $%d."), framereg);
found:
note_gpreg (framereg);
return framereg;
}
/* This is called before the symbol table is processed. In order to
work with gcc when using mips-tfile, we must keep all local labels.
However, in other cases, we want to discard them. If we were
called with -g, but we didn't see any debugging information, it may
mean that gcc is smuggling debugging information through to
mips-tfile, in which case we must generate all local labels. */
#ifdef OBJ_ECOFF
void
alpha_frob_file_before_adjust ()
{
if (alpha_debug != 0
&& ! ecoff_debugging_seen)
flag_keep_locals = 1;
}
#endif /* OBJ_ECOFF */
#ifdef RELOC_OP_P
/* Before the relocations are written, reorder them, so that user
supplied !lituse relocations follow the appropriate !literal
relocations. Also convert the gas-internal relocations to the
appropriate linker relocations. */
void
alpha_adjust_symtab ()
{
if (alpha_literal_hash)
{
#ifdef DEBUG2_ALPHA
fprintf (stderr, "alpha_adjust_symtab called\n");
#endif
/* Go over each section, reordering the relocations so that all
of the explicit LITUSE's are adjacent to the explicit
LITERAL's. */
bfd_map_over_sections (stdoutput, alpha_adjust_symtab_relocs,
(char *) 0);
}
}
/* Inner function to move LITUSE's next to the LITERAL. */
static void
alpha_adjust_symtab_relocs (abfd, sec, ptr)
bfd *abfd ATTRIBUTE_UNUSED;
asection *sec;
PTR ptr ATTRIBUTE_UNUSED;
{
segment_info_type *seginfo = seg_info (sec);
fixS **prevP;
fixS *fixp;
fixS *next;
fixS *lituse;
int n_lituses = 0;
#ifdef DEBUG2_ALPHA
int n = 0;
int n_literals = 0;
int n_dup_literals = 0;
#endif
/* If seginfo is NULL, we did not create this section; don't do
anything with it. By using a pointer to a pointer, we can update
the links in place. */
if (seginfo == NULL)
return;
/* If there are no relocations, skip the section. */
if (! seginfo->fix_root)
return;
/* First rebuild the fixup chain without the expicit lituse's. */
prevP = &(seginfo->fix_root);
for (fixp = seginfo->fix_root; fixp; fixp = next)
{
next = fixp->fx_next;
fixp->fx_next = (fixS *) 0;
#ifdef DEBUG2_ALPHA
n++;
#endif
switch (fixp->fx_r_type)
{
default:
*prevP = fixp;
prevP = &(fixp->fx_next);
#ifdef DEBUG2_ALPHA
fprintf (stderr,
"alpha_adjust_symtab_relocs: 0x%lx, other relocation %s\n",
(long) fixp,
bfd_get_reloc_code_name (fixp->fx_r_type));
#endif
break;
case BFD_RELOC_ALPHA_USER_LITERAL:
*prevP = fixp;
prevP = &(fixp->fx_next);
/* prevent assembler from trying to adjust the offset */
#ifdef DEBUG2_ALPHA
n_literals++;
if (fixp->tc_fix_data.info->n_literals != 1)
n_dup_literals++;
fprintf (stderr,
"alpha_adjust_symtab_relocs: 0x%lx, !literal!%.6d, # literals = %2d\n",
(long) fixp,
fixp->tc_fix_data.info->sequence,
fixp->tc_fix_data.info->n_literals);
#endif
break;
/* do not link in lituse's */
case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
n_lituses++;
if (fixp->tc_fix_data.info->n_literals == 0)
as_bad_where (fixp->fx_file, fixp->fx_line,
_("No !literal!%d was found"),
fixp->tc_fix_data.info->sequence);
#ifdef DEBUG2_ALPHA
fprintf (stderr,
"alpha_adjust_symtab_relocs: 0x%lx, !lituse !%.6d, # lituses = %2d, next_lituse = 0x%lx\n",
(long) fixp,
fixp->tc_fix_data.info->sequence,
fixp->tc_fix_data.info->n_lituses,
(long) fixp->tc_fix_data.next_lituse);
#endif
break;
}
}
/* If there were any lituses, go and add them to the chain, unless there is
more than one !literal for a given sequence number. They are linked
through the next_lituse field in reverse order, so as we go through the
next_lituse chain, we effectively reverse the chain once again. If there
was more than one !literal, we fall back to loading up the address w/o
optimization. Also, if the !literals/!lituses are spread in different
segments (happens in the Linux kernel semaphores), suppress the
optimization. */
if (n_lituses)
{
for (fixp = seginfo->fix_root; fixp; fixp = fixp->fx_next)
{
switch (fixp->fx_r_type)
{
default:
break;
case BFD_RELOC_ALPHA_USER_LITERAL:
#ifdef OBJ_ELF
fixp->fx_r_type = BFD_RELOC_ALPHA_ELF_LITERAL;
#else
fixp->fx_r_type = BFD_RELOC_ALPHA_LITERAL; /* XXX check this */
#endif
if (fixp->tc_fix_data.info->n_literals == 1
&& ! fixp->tc_fix_data.info->multi_section_p)
{
for (lituse = fixp->tc_fix_data.info->lituse;
lituse != (fixS *) 0;
lituse = lituse->tc_fix_data.next_lituse)
{
lituse->fx_next = fixp->fx_next;
fixp->fx_next = lituse;
}
}
break;
case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
fixp->fx_r_type = BFD_RELOC_ALPHA_LITUSE;
break;
}
}
}
#ifdef DEBUG2_ALPHA
fprintf (stderr, "alpha_adjust_symtab_relocs: %s, %d literal%s, %d duplicate literal%s, %d lituse%s\n\n",
sec->name,
n_literals, (n_literals == 1) ? "" : "s",
n_dup_literals, (n_dup_literals == 1) ? "" : "s",
n_lituses, (n_lituses == 1) ? "" : "s");
#endif
}
#endif /* RELOC_OP_P */
#ifdef DEBUG_ALPHA
static void
debug_exp (tok, ntok)
expressionS tok[];
int ntok;
{
int i;
fprintf (stderr, "debug_exp: %d tokens", ntok);
for (i = 0; i < ntok; i++)
{
expressionS *t = &tok[i];
const char *name;
switch (t->X_op)
{
default: name = "unknown"; break;
case O_illegal: name = "O_illegal"; break;
case O_absent: name = "O_absent"; break;
case O_constant: name = "O_constant"; break;
case O_symbol: name = "O_symbol"; break;
case O_symbol_rva: name = "O_symbol_rva"; break;
case O_register: name = "O_register"; break;
case O_big: name = "O_big"; break;
case O_uminus: name = "O_uminus"; break;
case O_bit_not: name = "O_bit_not"; break;
case O_logical_not: name = "O_logical_not"; break;
case O_multiply: name = "O_multiply"; break;
case O_divide: name = "O_divide"; break;
case O_modulus: name = "O_modulus"; break;
case O_left_shift: name = "O_left_shift"; break;
case O_right_shift: name = "O_right_shift"; break;
case O_bit_inclusive_or: name = "O_bit_inclusive_or"; break;
case O_bit_or_not: name = "O_bit_or_not"; break;
case O_bit_exclusive_or: name = "O_bit_exclusive_or"; break;
case O_bit_and: name = "O_bit_and"; break;
case O_add: name = "O_add"; break;
case O_subtract: name = "O_subtract"; break;
case O_eq: name = "O_eq"; break;
case O_ne: name = "O_ne"; break;
case O_lt: name = "O_lt"; break;
case O_le: name = "O_le"; break;
case O_ge: name = "O_ge"; break;
case O_gt: name = "O_gt"; break;
case O_logical_and: name = "O_logical_and"; break;
case O_logical_or: name = "O_logical_or"; break;
case O_index: name = "O_index"; break;
case O_pregister: name = "O_pregister"; break;
case O_cpregister: name = "O_cpregister"; break;
case O_literal: name = "O_literal"; break;
case O_lituse_base: name = "O_lituse_base"; break;
case O_lituse_bytoff: name = "O_lituse_bytoff"; break;
case O_lituse_jsr: name = "O_lituse_jsr"; break;
case O_gpdisp: name = "O_gpdisp"; break;
case O_gprelhigh: name = "O_gprelhigh"; break;
case O_gprellow: name = "O_gprellow"; break;
case O_md10: name = "O_md10"; break;
case O_md11: name = "O_md11"; break;
case O_md12: name = "O_md12"; break;
case O_md13: name = "O_md13"; break;
case O_md14: name = "O_md14"; break;
case O_md15: name = "O_md15"; break;
case O_md16: name = "O_md16"; break;
}
fprintf (stderr, ", %s(%s, %s, %d)", name,
(t->X_add_symbol) ? S_GET_NAME (t->X_add_symbol) : "--",
(t->X_op_symbol) ? S_GET_NAME (t->X_op_symbol) : "--",
(int) t->X_add_number);
}
fprintf (stderr, "\n");
fflush (stderr);
}
#endif
/* Parse the arguments to an opcode. */
static int
tokenize_arguments (str, tok, ntok)
char *str;
expressionS tok[];
int ntok;
{
expressionS *end_tok = tok + ntok;
char *old_input_line_pointer;
int saw_comma = 0, saw_arg = 0;
#ifdef DEBUG_ALPHA
expressionS *orig_tok = tok;
#endif
#ifdef RELOC_OP_P
char *p;
const struct alpha_reloc_op_tag *r;
int c, i;
size_t len;
int reloc_found_p = 0;
#endif
memset (tok, 0, sizeof (*tok) * ntok);
/* Save and restore input_line_pointer around this function */
old_input_line_pointer = input_line_pointer;
input_line_pointer = str;
while (tok < end_tok && *input_line_pointer)
{
SKIP_WHITESPACE ();
switch (*input_line_pointer)
{
case '\0':
goto fini;
#ifdef RELOC_OP_P
case '!':
/* A relocation operand can be placed after the normal operand on an
assembly language statement, and has the following form:
!relocation_type!sequence_number. */
if (reloc_found_p)
{ /* only support one relocation op per insn */
as_bad (_("More than one relocation op per insn"));
goto err_report;
}
if (!saw_arg)
goto err;
for (p = ++input_line_pointer;
((c = *p) != '!' && c != ';' && c != '#' && c != ','
&& !is_end_of_line[c]);
p++)
;
/* Parse !relocation_type */
len = p - input_line_pointer;
if (len == 0)
{
as_bad (_("No relocation operand"));
goto err_report;
}
if (c != '!')
{
as_bad (_("No !sequence-number after !%s"), input_line_pointer);
goto err_report;
}
r = &alpha_reloc_op[0];
for (i = alpha_num_reloc_op - 1; i >= 0; i--, r++)
{
if (len == r->length
&& memcmp (input_line_pointer, r->name, len) == 0)
break;
}
if (i < 0)
{
as_bad (_("Unknown relocation operand: !%s"),
input_line_pointer);
goto err_report;
}
input_line_pointer = ++p;
/* Parse !sequence_number */
memset (tok, '\0', sizeof (expressionS));
expression (tok);
if (tok->X_op != O_constant
|| ! ALPHA_RELOC_SEQUENCE_OK (tok->X_add_number))
{
as_bad (_("Bad sequence number: !%s!%s"),
r->name, input_line_pointer);
goto err_report;
}
tok->X_op = r->op;
reloc_found_p = 1;
++tok;
break;
#endif
case ',':
++input_line_pointer;
if (saw_comma || !saw_arg)
goto err;
saw_comma = 1;
break;
case '(':
{
char *hold = input_line_pointer++;
/* First try for parenthesized register ... */
expression (tok);
if (*input_line_pointer == ')' && tok->X_op == O_register)
{
tok->X_op = (saw_comma ? O_cpregister : O_pregister);
saw_comma = 0;
saw_arg = 1;
++input_line_pointer;
++tok;
break;
}
/* ... then fall through to plain expression */
input_line_pointer = hold;
}
default:
if (saw_arg && !saw_comma)
goto err;
expression (tok);
if (tok->X_op == O_illegal || tok->X_op == O_absent)
goto err;
saw_comma = 0;
saw_arg = 1;
++tok;
break;
}
}
fini:
if (saw_comma)
goto err;
input_line_pointer = old_input_line_pointer;
#ifdef DEBUG_ALPHA
debug_exp (orig_tok, ntok - (end_tok - tok));
#endif
return ntok - (end_tok - tok);
err:
input_line_pointer = old_input_line_pointer;
return TOKENIZE_ERROR;
#ifdef RELOC_OP_P
err_report:
input_line_pointer = old_input_line_pointer;
return TOKENIZE_ERROR_REPORT;
#endif
}
/* Search forward through all variants of an opcode looking for a
syntax match. */
static const struct alpha_opcode *
find_opcode_match (first_opcode, tok, pntok, pcpumatch)
const struct alpha_opcode *first_opcode;
const expressionS *tok;
int *pntok;
int *pcpumatch;
{
const struct alpha_opcode *opcode = first_opcode;
int ntok = *pntok;
int got_cpu_match = 0;
do
{
const unsigned char *opidx;
int tokidx = 0;
/* Don't match opcodes that don't exist on this architecture */
if (!(opcode->flags & alpha_target))
goto match_failed;
got_cpu_match = 1;
for (opidx = opcode->operands; *opidx; ++opidx)
{
const struct alpha_operand *operand = &alpha_operands[*opidx];
/* only take input from real operands */
if (operand->flags & AXP_OPERAND_FAKE)
continue;
/* when we expect input, make sure we have it */
if (tokidx >= ntok)
{
if ((operand->flags & AXP_OPERAND_OPTIONAL_MASK) == 0)
goto match_failed;
continue;
}
/* match operand type with expression type */
switch (operand->flags & AXP_OPERAND_TYPECHECK_MASK)
{
case AXP_OPERAND_IR:
if (tok[tokidx].X_op != O_register
|| !is_ir_num (tok[tokidx].X_add_number))
goto match_failed;
break;
case AXP_OPERAND_FPR:
if (tok[tokidx].X_op != O_register
|| !is_fpr_num (tok[tokidx].X_add_number))
goto match_failed;
break;
case AXP_OPERAND_IR | AXP_OPERAND_PARENS:
if (tok[tokidx].X_op != O_pregister
|| !is_ir_num (tok[tokidx].X_add_number))
goto match_failed;
break;
case AXP_OPERAND_IR | AXP_OPERAND_PARENS | AXP_OPERAND_COMMA:
if (tok[tokidx].X_op != O_cpregister
|| !is_ir_num (tok[tokidx].X_add_number))
goto match_failed;
break;
case AXP_OPERAND_RELATIVE:
case AXP_OPERAND_SIGNED:
case AXP_OPERAND_UNSIGNED:
switch (tok[tokidx].X_op)
{
case O_illegal:
case O_absent:
case O_register:
case O_pregister:
case O_cpregister:
goto match_failed;
default:
break;
}
break;
default:
/* everything else should have been fake */
abort ();
}
++tokidx;
}
/* possible match -- did we use all of our input? */
if (tokidx == ntok)
{
*pntok = ntok;
return opcode;
}
match_failed:;
}
while (++opcode - alpha_opcodes < alpha_num_opcodes
&& !strcmp (opcode->name, first_opcode->name));
if (*pcpumatch)
*pcpumatch = got_cpu_match;
return NULL;
}
/* Search forward through all variants of a macro looking for a syntax
match. */
static const struct alpha_macro *
find_macro_match (first_macro, tok, pntok)
const struct alpha_macro *first_macro;
const expressionS *tok;
int *pntok;
{
const struct alpha_macro *macro = first_macro;
int ntok = *pntok;
do
{
const enum alpha_macro_arg *arg = macro->argsets;
int tokidx = 0;
while (*arg)
{
switch (*arg)
{
case MACRO_EOA:
if (tokidx == ntok)
return macro;
else
tokidx = 0;
break;
/* index register */
case MACRO_IR:
if (tokidx >= ntok || tok[tokidx].X_op != O_register
|| !is_ir_num (tok[tokidx].X_add_number))
goto match_failed;
++tokidx;
break;
/* parenthesized index register */
case MACRO_PIR:
if (tokidx >= ntok || tok[tokidx].X_op != O_pregister
|| !is_ir_num (tok[tokidx].X_add_number))
goto match_failed;
++tokidx;
break;
/* optional parenthesized index register */
case MACRO_OPIR:
if (tokidx < ntok && tok[tokidx].X_op == O_pregister
&& is_ir_num (tok[tokidx].X_add_number))
++tokidx;
break;
/* leading comma with a parenthesized index register */
case MACRO_CPIR:
if (tokidx >= ntok || tok[tokidx].X_op != O_cpregister
|| !is_ir_num (tok[tokidx].X_add_number))
goto match_failed;
++tokidx;
break;
/* floating point register */
case MACRO_FPR:
if (tokidx >= ntok || tok[tokidx].X_op != O_register
|| !is_fpr_num (tok[tokidx].X_add_number))
goto match_failed;
++tokidx;
break;
/* normal expression */
case MACRO_EXP:
if (tokidx >= ntok)
goto match_failed;
switch (tok[tokidx].X_op)
{
case O_illegal:
case O_absent:
case O_register:
case O_pregister:
case O_cpregister:
#ifdef RELOC_OP_P
case O_literal:
case O_lituse_base:
case O_lituse_bytoff:
case O_lituse_jsr:
case O_gpdisp:
case O_gprelhigh:
case O_gprellow:
#endif
goto match_failed;
default:
break;
}
++tokidx;
break;
/* optional !literal!<number> */
case MACRO_LITERAL:
#ifdef RELOC_OP_P
if (tokidx < ntok && tok[tokidx].X_op == O_literal)
tokidx++;
#endif
break;
/* optional !lituse_base!<number> */
case MACRO_BASE:
#ifdef RELOC_OP_P
if (tokidx < ntok && tok[tokidx].X_op == O_lituse_base)
tokidx++;
#endif
break;
/* optional !lituse_bytoff!<number> */
case MACRO_BYTOFF:
#ifdef RELOC_OP_P
if (tokidx < ntok && tok[tokidx].X_op == O_lituse_bytoff)
tokidx++;
#endif
break;
/* optional !lituse_jsr!<number> */
case MACRO_JSR:
#ifdef RELOC_OP_P
if (tokidx < ntok && tok[tokidx].X_op == O_lituse_jsr)
tokidx++;
#endif
break;
match_failed:
while (*arg != MACRO_EOA)
++arg;
tokidx = 0;
break;
}
++arg;
}
}
while (++macro - alpha_macros < alpha_num_macros
&& !strcmp (macro->name, first_macro->name));
return NULL;
}
/* Insert an operand value into an instruction. */
static unsigned
insert_operand (insn, operand, val, file, line)
unsigned insn;
const struct alpha_operand *operand;
offsetT val;
char *file;
unsigned line;
{
if (operand->bits != 32 && !(operand->flags & AXP_OPERAND_NOOVERFLOW))
{
offsetT min, max;
if (operand->flags & AXP_OPERAND_SIGNED)
{
max = (1 << (operand->bits - 1)) - 1;
min = -(1 << (operand->bits - 1));
}
else
{
max = (1 << operand->bits) - 1;
min = 0;
}
if (val < min || val > max)
{
const char *err =
_("operand out of range (%s not between %d and %d)");
char buf[sizeof (val) * 3 + 2];
sprint_value (buf, val);
if (file)
as_warn_where (file, line, err, buf, min, max);
else
as_warn (err, buf, min, max);
}
}
if (operand->insert)
{
const char *errmsg = NULL;
insn = (*operand->insert) (insn, val, &errmsg);
if (errmsg)
as_warn (errmsg);
}
else
insn |= ((val & ((1 << operand->bits) - 1)) << operand->shift);
return insn;
}
/*
* Turn an opcode description and a set of arguments into
* an instruction and a fixup.
*/
static void
assemble_insn (opcode, tok, ntok, insn)
const struct alpha_opcode *opcode;
const expressionS *tok;
int ntok;
struct alpha_insn *insn;
{
const unsigned char *argidx;
unsigned image;
int tokidx = 0;
memset (insn, 0, sizeof (*insn));
image = opcode->opcode;
for (argidx = opcode->operands; *argidx; ++argidx)
{
const struct alpha_operand *operand = &alpha_operands[*argidx];
const expressionS *t = (const expressionS *) 0;
if (operand->flags & AXP_OPERAND_FAKE)
{
/* fake operands take no value and generate no fixup */
image = insert_operand (image, operand, 0, NULL, 0);
continue;
}
if (tokidx >= ntok)
{
switch (operand->flags & AXP_OPERAND_OPTIONAL_MASK)
{
case AXP_OPERAND_DEFAULT_FIRST:
t = &tok[0];
break;
case AXP_OPERAND_DEFAULT_SECOND:
t = &tok[1];
break;
case AXP_OPERAND_DEFAULT_ZERO:
{
static expressionS zero_exp;
t = &zero_exp;
zero_exp.X_op = O_constant;
zero_exp.X_unsigned = 1;
}
break;
default:
abort ();
}
}
else
t = &tok[tokidx++];
switch (t->X_op)
{
case O_register:
case O_pregister:
case O_cpregister:
image = insert_operand (image, operand, regno (t->X_add_number),
NULL, 0);
break;
case O_constant:
image = insert_operand (image, operand, t->X_add_number, NULL, 0);
break;
default:
{
struct alpha_fixup *fixup;
if (insn->nfixups >= MAX_INSN_FIXUPS)
as_fatal (_("too many fixups"));
fixup = &insn->fixups[insn->nfixups++];
fixup->exp = *t;
fixup->reloc = operand->default_reloc;
}
break;
}
}
insn->insn = image;
}
/*
* Actually output an instruction with its fixup.
*/
static void
emit_insn (insn)
struct alpha_insn *insn;
{
char *f;
int i;
/* Take care of alignment duties. */
if (alpha_auto_align_on && alpha_current_align < 2)
alpha_align (2, (char *) NULL, alpha_insn_label, 0);
if (alpha_current_align > 2)
alpha_current_align = 2;
alpha_insn_label = NULL;
/* Write out the instruction. */
f = frag_more (4);
md_number_to_chars (f, insn->insn, 4);
#ifdef OBJ_ELF
dwarf2_emit_insn (4);
#endif
/* Apply the fixups in order */
for (i = 0; i < insn->nfixups; ++i)
{
const struct alpha_operand *operand = (const struct alpha_operand *) 0;
struct alpha_fixup *fixup = &insn->fixups[i];
int size, pcrel;
fixS *fixP;
#ifdef RELOC_OP_P
char buffer[ALPHA_RELOC_DIGITS];
struct alpha_literal_tag *info;
#endif
/* Some fixups are only used internally and so have no howto */
if ((int) fixup->reloc < 0)
{
operand = &alpha_operands[-(int) fixup->reloc];
size = 4;
pcrel = ((operand->flags & AXP_OPERAND_RELATIVE) != 0);
}
else
switch (fixup->reloc)
{
#ifdef OBJ_ELF
/* These relocation types are only used internally. */
case BFD_RELOC_ALPHA_GPDISP_HI16:
case BFD_RELOC_ALPHA_GPDISP_LO16:
size = 2;
pcrel = 0;
break;
#endif
#ifdef RELOC_OP_P
/* and these also are internal only relocations */
case BFD_RELOC_ALPHA_USER_LITERAL:
case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
case BFD_RELOC_ALPHA_USER_GPDISP:
case BFD_RELOC_ALPHA_USER_GPRELHIGH:
case BFD_RELOC_ALPHA_USER_GPRELLOW:
size = 2;
pcrel = 0;
break;
#endif
default:
{
reloc_howto_type *reloc_howto
= bfd_reloc_type_lookup (stdoutput, fixup->reloc);
assert (reloc_howto);
size = bfd_get_reloc_size (reloc_howto);
pcrel = reloc_howto->pc_relative;
}
assert (size >= 1 && size <= 4);
break;
}
fixP = fix_new_exp (frag_now, f - frag_now->fr_literal, size,
&fixup->exp, pcrel, fixup->reloc);
/* Turn off complaints that the addend is too large for some fixups,
and copy in the sequence number for the explicit relocations. */
switch (fixup->reloc)
{
case BFD_RELOC_ALPHA_GPDISP_LO16:
#ifdef OBJ_ECOFF
case BFD_RELOC_ALPHA_LITERAL:
#endif
#ifdef OBJ_ELF
case BFD_RELOC_ALPHA_ELF_LITERAL:
#endif
case BFD_RELOC_GPREL32:
fixP->fx_no_overflow = 1;
break;
#ifdef RELOC_OP_P
case BFD_RELOC_ALPHA_USER_LITERAL:
fixP->fx_no_overflow = 1;
sprintf (buffer, "!%u", insn->sequence[i]);
info = ((struct alpha_literal_tag *)
hash_find (alpha_literal_hash, buffer));
if (! info)
{
size_t len = strlen (buffer);
const char *errmsg;
info = ((struct alpha_literal_tag *)
xcalloc (sizeof (struct alpha_literal_tag) + len, 1));
info->segment = now_seg;
info->sequence = insn->sequence[i];
strcpy (info->string, buffer);
errmsg = hash_insert (alpha_literal_hash, info->string, (PTR) info);
if (errmsg)
as_bad (errmsg);
}
++info->n_literals;
if (info->segment != now_seg)
info->multi_section_p = 1;
fixP->tc_fix_data.info = info;
break;
case BFD_RELOC_ALPHA_USER_LITUSE_BASE:
case BFD_RELOC_ALPHA_USER_LITUSE_BYTOFF:
case BFD_RELOC_ALPHA_USER_LITUSE_JSR:
sprintf (buffer, "!%u", insn->sequence[i]);
info = ((struct alpha_literal_tag *)
hash_find (alpha_literal_hash, buffer));
if (! info)
{
size_t len = strlen (buffer);
const char *errmsg;
info = ((struct alpha_literal_tag *)
xcalloc (sizeof (struct alpha_literal_tag) + len, 1));
info->segment = now_seg;
info->sequence = insn->sequence[i];
strcpy (info->string, buffer);
errmsg = hash_insert (alpha_literal_hash, info->string, (PTR) info);
if (errmsg)
as_bad (errmsg);
}
info->n_lituses++;
fixP->tc_fix_data.info = info;
fixP->tc_fix_data.next_lituse = info->lituse;
info->lituse = fixP;
if (info->segment != now_seg)
info->multi_section_p = 1;
break;
#endif
default:
if ((int) fixup->reloc < 0)
{
if (operand->flags & AXP_OPERAND_NOOVERFLOW)
fixP->fx_no_overflow = 1;
}
break;
}
}
}
/* Given an opcode name and a pre-tokenized set of arguments, assemble
the insn, but do not emit it.
Note that this implies no macros allowed, since we can't store more
than one insn in an insn structure. */
static void
assemble_tokens_to_insn (opname, tok, ntok, insn)
const char *opname;
const expressionS *tok;
int ntok;
struct alpha_insn *insn;
{
const struct alpha_opcode *opcode;
/* search opcodes */
opcode = (const struct alpha_opcode *) hash_find (alpha_opcode_hash, opname);
if (opcode)
{
int cpumatch;
opcode = find_opcode_match (opcode, tok, &ntok, &cpumatch);
if (opcode)
{
assemble_insn (opcode, tok, ntok, insn);
return;
}
else if (cpumatch)
as_bad (_("inappropriate arguments for opcode `%s'"), opname);
else
as_bad (_("opcode `%s' not supported for target %s"), opname,
alpha_target_name);
}
else
as_bad (_("unknown opcode `%s'"), opname);
}
/* Given an opcode name and a pre-tokenized set of arguments, take the
opcode all the way through emission. */
static void
assemble_tokens (opname, tok, ntok, local_macros_on)
const char *opname;
const expressionS *tok;
int ntok;
int local_macros_on;
{
int found_something = 0;
const struct alpha_opcode *opcode;
const struct alpha_macro *macro;
int cpumatch = 1;
/* search macros */
if (local_macros_on)
{
macro = ((const struct alpha_macro *)
hash_find (alpha_macro_hash, opname));
if (macro)
{
found_something = 1;
macro = find_macro_match (macro, tok, &ntok);
if (macro)
{
(*macro->emit) (tok, ntok, macro->arg);
return;
}
}
}
#ifdef RELOC_OP_P
if (ntok && USER_RELOC_P (tok[ntok - 1].X_op))
{
const expressionS *reloc_exp = &tok[ntok - 1];
const struct alpha_reloc_op_tag *r = ALPHA_RELOC_TABLE (reloc_exp->X_op);
as_bad (_("Cannot use !%s!%d with %s"), r->name,
(int) reloc_exp->X_add_number, opname);
ntok--;
}
#endif
/* search opcodes */
opcode = (const struct alpha_opcode *) hash_find (alpha_opcode_hash, opname);
if (opcode)
{
found_something = 1;
opcode = find_opcode_match (opcode, tok, &ntok, &cpumatch);
if (opcode)
{
struct alpha_insn insn;
assemble_insn (opcode, tok, ntok, &insn);
emit_insn (&insn);
return;
}
}
if (found_something)
if (cpumatch)
as_bad (_("inappropriate arguments for opcode `%s'"), opname);
else
as_bad (_("opcode `%s' not supported for target %s"), opname,
alpha_target_name);
else
as_bad (_("unknown opcode `%s'"), opname);
}
/* Some instruction sets indexed by lg(size) */
static const char * const sextX_op[] = { "sextb", "sextw", "sextl", NULL };
static const char * const insXl_op[] = { "insbl", "inswl", "insll", "insql" };
static const char * const insXh_op[] = { NULL, "inswh", "inslh", "insqh" };
static const char * const extXl_op[] = { "extbl", "extwl", "extll", "extql" };
static const char * const extXh_op[] = { NULL, "extwh", "extlh", "extqh" };
static const char * const mskXl_op[] = { "mskbl", "mskwl", "mskll", "mskql" };
static const char * const mskXh_op[] = { NULL, "mskwh", "msklh", "mskqh" };
static const char * const stX_op[] = { "stb", "stw", "stl", "stq" };
static const char * const ldX_op[] = { "ldb", "ldw", "ldll", "ldq" };
static const char * const ldXu_op[] = { "ldbu", "ldwu", NULL, NULL };
/* Implement the ldgp macro. */
static void
emit_ldgp (tok, ntok, unused)
const expressionS *tok;
int ntok ATTRIBUTE_UNUSED;
const PTR unused ATTRIBUTE_UNUSED;
{
#ifdef OBJ_AOUT
FIXME
#endif
#if defined(OBJ_ECOFF) || defined(OBJ_ELF)
/* from "ldgp r1,n(r2)", generate "ldah r1,X(R2); lda r1,Y(r1)"
with appropriate constants and relocations. */
struct alpha_insn insn;