2001-05-02 20:14:31 +02:00
|
|
|
|
/* tc-openrisc.c -- Assembler for the OpenRISC family.
|
2009-07-24 13:45:01 +02:00
|
|
|
|
Copyright 2001, 2002, 2003, 2005, 2006, 2007, 2009
|
|
|
|
|
Free Software Foundation.
|
2001-05-02 20:14:31 +02:00
|
|
|
|
Contributed by Johan Rydberg, jrydberg@opencores.org
|
|
|
|
|
|
|
|
|
|
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
|
2007-07-03 13:01:12 +02:00
|
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
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
|
2005-05-05 11:13:19 +02:00
|
|
|
|
the Free Software Foundation, 51 Franklin Street - Fifth Floor,
|
|
|
|
|
Boston, MA 02110-1301, USA. */
|
2001-05-02 20:14:31 +02:00
|
|
|
|
|
|
|
|
|
#include "as.h"
|
|
|
|
|
#include "subsegs.h"
|
|
|
|
|
#include "symcat.h"
|
|
|
|
|
#include "opcodes/openrisc-desc.h"
|
|
|
|
|
#include "opcodes/openrisc-opc.h"
|
|
|
|
|
#include "cgen.h"
|
|
|
|
|
|
|
|
|
|
/* Structure to hold all of the different components describing
|
|
|
|
|
an individual instruction. */
|
|
|
|
|
typedef struct openrisc_insn openrisc_insn;
|
|
|
|
|
|
|
|
|
|
struct openrisc_insn
|
|
|
|
|
{
|
|
|
|
|
const CGEN_INSN * insn;
|
|
|
|
|
const CGEN_INSN * orig_insn;
|
|
|
|
|
CGEN_FIELDS fields;
|
|
|
|
|
#if CGEN_INT_INSN_P
|
|
|
|
|
CGEN_INSN_INT buffer [1];
|
|
|
|
|
#define INSN_VALUE(buf) (*(buf))
|
|
|
|
|
#else
|
|
|
|
|
unsigned char buffer [CGEN_MAX_INSN_SIZE];
|
|
|
|
|
#define INSN_VALUE(buf) (buf)
|
|
|
|
|
#endif
|
|
|
|
|
char * addr;
|
|
|
|
|
fragS * frag;
|
|
|
|
|
int num_fixups;
|
|
|
|
|
fixS * fixups [GAS_CGEN_MAX_FIXUPS];
|
|
|
|
|
int indices [MAX_OPERAND_INSTANCES];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const char comment_chars[] = "#";
|
|
|
|
|
const char line_comment_chars[] = "#";
|
|
|
|
|
const char line_separator_chars[] = ";";
|
|
|
|
|
const char EXP_CHARS[] = "eE";
|
|
|
|
|
const char FLT_CHARS[] = "dD";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define OPENRISC_SHORTOPTS "m:"
|
|
|
|
|
const char * md_shortopts = OPENRISC_SHORTOPTS;
|
|
|
|
|
|
|
|
|
|
struct option md_longopts[] =
|
|
|
|
|
{
|
|
|
|
|
{NULL, no_argument, NULL, 0}
|
|
|
|
|
};
|
|
|
|
|
size_t md_longopts_size = sizeof (md_longopts);
|
|
|
|
|
|
|
|
|
|
unsigned long openrisc_machine = 0; /* default */
|
|
|
|
|
|
|
|
|
|
int
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_parse_option (int c ATTRIBUTE_UNUSED, char * arg ATTRIBUTE_UNUSED)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_show_usage (FILE * stream ATTRIBUTE_UNUSED)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2005-03-24 21:40:28 +01:00
|
|
|
|
ignore_pseudo (int val ATTRIBUTE_UNUSED)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
discard_rest_of_line ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char openrisc_comment_chars [] = ";#";
|
|
|
|
|
|
|
|
|
|
/* The target specific pseudo-ops which we support. */
|
|
|
|
|
const pseudo_typeS md_pseudo_table[] =
|
|
|
|
|
{
|
|
|
|
|
{ "word", cons, 4 },
|
|
|
|
|
{ "proc", ignore_pseudo, 0 },
|
|
|
|
|
{ "endproc", ignore_pseudo, 0 },
|
|
|
|
|
{ NULL, NULL, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_begin (void)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
/* Initialize the `cgen' interface. */
|
|
|
|
|
|
|
|
|
|
/* Set the machine number and endian. */
|
|
|
|
|
gas_cgen_cpu_desc = openrisc_cgen_cpu_open (CGEN_CPU_OPEN_MACHS, 0,
|
|
|
|
|
CGEN_CPU_OPEN_ENDIAN,
|
|
|
|
|
CGEN_ENDIAN_BIG,
|
|
|
|
|
CGEN_CPU_OPEN_END);
|
|
|
|
|
openrisc_cgen_init_asm (gas_cgen_cpu_desc);
|
|
|
|
|
|
|
|
|
|
/* This is a callback from cgen to gas to parse operands. */
|
|
|
|
|
cgen_set_parse_operand_fn (gas_cgen_cpu_desc, gas_cgen_parse_operand);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_assemble (char * str)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
static int last_insn_had_delay_slot = 0;
|
|
|
|
|
openrisc_insn insn;
|
|
|
|
|
char * errmsg;
|
|
|
|
|
|
|
|
|
|
/* Initialize GAS's cgen interface for a new instruction. */
|
|
|
|
|
gas_cgen_init_parse ();
|
|
|
|
|
|
|
|
|
|
insn.insn = openrisc_cgen_assemble_insn
|
|
|
|
|
(gas_cgen_cpu_desc, str, & insn.fields, insn.buffer, & errmsg);
|
|
|
|
|
|
|
|
|
|
if (!insn.insn)
|
|
|
|
|
{
|
2009-07-24 13:45:01 +02:00
|
|
|
|
as_bad ("%s", errmsg);
|
2001-05-02 20:14:31 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Doesn't really matter what we pass for RELAX_P here. */
|
|
|
|
|
gas_cgen_finish_insn (insn.insn, insn.buffer,
|
|
|
|
|
CGEN_FIELDS_BITSIZE (& insn.fields), 1, NULL);
|
|
|
|
|
|
|
|
|
|
last_insn_had_delay_slot
|
|
|
|
|
= CGEN_INSN_ATTR_VALUE (insn.insn, CGEN_INSN_DELAY_SLOT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* The syntax in the manual says constants begin with '#'.
|
|
|
|
|
We just ignore it. */
|
|
|
|
|
|
|
|
|
|
void
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_operand (expressionS * expressionP)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
if (* input_line_pointer == '#')
|
|
|
|
|
{
|
|
|
|
|
input_line_pointer ++;
|
|
|
|
|
expression (expressionP);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
valueT
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_section_align (segT segment, valueT size)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
int align = bfd_get_section_alignment (stdoutput, segment);
|
|
|
|
|
return ((size + (1 << align) - 1) & (-1 << align));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
symbolS *
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Interface to relax_segment. */
|
|
|
|
|
|
|
|
|
|
/* FIXME: Look through this. */
|
|
|
|
|
|
|
|
|
|
const relax_typeS md_relax_table[] =
|
|
|
|
|
{
|
|
|
|
|
/* The fields are:
|
|
|
|
|
1) most positive reach of this state,
|
|
|
|
|
2) most negative reach of this state,
|
|
|
|
|
3) how many bytes this mode will add to the size of the current frag
|
|
|
|
|
4) which index into the table to try if we can't fit into this one. */
|
|
|
|
|
|
|
|
|
|
/* The first entry must be unused because an `rlx_more' value of zero ends
|
|
|
|
|
each list. */
|
|
|
|
|
{1, 1, 0, 0},
|
|
|
|
|
|
|
|
|
|
/* The displacement used by GAS is from the end of the 2 byte insn,
|
|
|
|
|
so we subtract 2 from the following. */
|
|
|
|
|
/* 16 bit insn, 8 bit disp -> 10 bit range.
|
|
|
|
|
This doesn't handle a branch in the right slot at the border:
|
|
|
|
|
the "& -4" isn't taken into account. It's not important enough to
|
|
|
|
|
complicate things over it, so we subtract an extra 2 (or + 2 in -ve
|
|
|
|
|
case). */
|
|
|
|
|
{511 - 2 - 2, -512 - 2 + 2, 0, 2 },
|
|
|
|
|
/* 32 bit insn, 24 bit disp -> 26 bit range. */
|
|
|
|
|
{0x2000000 - 1 - 2, -0x2000000 - 2, 2, 0 },
|
|
|
|
|
/* Same thing, but with leading nop for alignment. */
|
|
|
|
|
{0x2000000 - 1 - 2, -0x2000000 - 2, 4, 0 }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Return an initial guess of the length by which a fragment must grow to
|
|
|
|
|
hold a branch to reach its destination.
|
|
|
|
|
Also updates fr_type/fr_subtype as necessary.
|
|
|
|
|
|
|
|
|
|
Called just before doing relaxation.
|
|
|
|
|
Any symbol that is now undefined will not become defined.
|
|
|
|
|
The guess for fr_var is ACTUALLY the growth beyond fr_fix.
|
|
|
|
|
Whatever we do to grow fr_fix or fr_var contributes to our returned value.
|
|
|
|
|
Although it may not be explicit in the frag, pretend fr_var starts with a
|
|
|
|
|
0 value. */
|
|
|
|
|
|
|
|
|
|
int
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_estimate_size_before_relax (fragS * fragP, segT segment)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
/* The only thing we have to handle here are symbols outside of the
|
|
|
|
|
current segment. They may be undefined or in a different segment in
|
|
|
|
|
which case linker scripts may place them anywhere.
|
|
|
|
|
However, we can't finish the fragment here and emit the reloc as insn
|
|
|
|
|
alignment requirements may move the insn about. */
|
|
|
|
|
|
|
|
|
|
if (S_GET_SEGMENT (fragP->fr_symbol) != segment)
|
|
|
|
|
{
|
|
|
|
|
/* The symbol is undefined in this segment.
|
|
|
|
|
Change the relaxation subtype to the max allowable and leave
|
|
|
|
|
all further handling to md_convert_frag. */
|
|
|
|
|
fragP->fr_subtype = 2;
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
const CGEN_INSN * insn;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
/* Update the recorded insn.
|
|
|
|
|
Fortunately we don't have to look very far.
|
|
|
|
|
FIXME: Change this to record in the instruction the next higher
|
|
|
|
|
relaxable insn to use. */
|
|
|
|
|
for (i = 0, insn = fragP->fr_cgen.insn; i < 4; i++, insn++)
|
|
|
|
|
{
|
|
|
|
|
if ((strcmp (CGEN_INSN_MNEMONIC (insn),
|
|
|
|
|
CGEN_INSN_MNEMONIC (fragP->fr_cgen.insn))
|
|
|
|
|
== 0)
|
opcodes:
* cgen-asm.in (@arch@_cgen_assemble_insn): CGEN_INSN_RELAX renamed to
CGEN_INSN_RELAXED.
* fr30-asm.c,fr30-desc.c,fr30-desc.h: Regenerate.
* frv-asm.c,frv-desc.c,frv-desc.h: Regenerate.
* ip2k-asm.c,ip2k-desc.c,ip2k-desc.h: Regenerate.
* iq2000-asm.c,iq2000-desc.c,iq2000-desc.h: Regenerate.
* m32r-asm.c,m32r-desc.c,m32r-desc.h,m32r-opc.c: Regenerate.
* openrisc-asm.c,openrisc-desc.c,openrisc-desc.h: Regenerate.
* xstormy16-asm.c,xstormy16-desc.c,xstormy16-desc.h: Regenerate.
gas:
* cgen.c (gas_cgen_finish_insn): CGEN_INSN_RELAX renamed to
CGEN_INSN_RELAXED.
* config/tc-fr30.c (md_estimate_size_before_relax): Ditto.
* config/tc-m32r.c (md_estimate_size_before_relax): Ditto.
* config/tc-openrisc.c (md_estimate_size_before_relax): Ditto.
2003-06-11 00:08:45 +02:00
|
|
|
|
&& CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_RELAXED))
|
2001-05-02 20:14:31 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (i == 4)
|
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
|
|
fragP->fr_cgen.insn = insn;
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2001-05-10 13:32:52 +02:00
|
|
|
|
return md_relax_table[fragP->fr_subtype].rlx_length;
|
2001-05-02 20:14:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* *fragP has been relaxed to its final size, and now needs to have
|
|
|
|
|
the bytes inside it modified to conform to the new size.
|
|
|
|
|
|
|
|
|
|
Called after relaxation is finished.
|
|
|
|
|
fragP->fr_type == rs_machine_dependent.
|
|
|
|
|
fragP->fr_subtype is the subtype of what the address relaxed to. */
|
|
|
|
|
|
|
|
|
|
void
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_convert_frag (bfd * abfd ATTRIBUTE_UNUSED,
|
|
|
|
|
segT sec ATTRIBUTE_UNUSED,
|
|
|
|
|
fragS * fragP ATTRIBUTE_UNUSED)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
/* FIXME */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Functions concerning relocs. */
|
|
|
|
|
|
|
|
|
|
/* The location from which a PC relative jump should be calculated,
|
|
|
|
|
given a PC relative reloc. */
|
|
|
|
|
|
|
|
|
|
long
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_pcrel_from_section (fixS * fixP, segT sec)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
if (fixP->fx_addsy != (symbolS *) NULL
|
|
|
|
|
&& (! S_IS_DEFINED (fixP->fx_addsy)
|
|
|
|
|
|| S_GET_SEGMENT (fixP->fx_addsy) != sec))
|
2005-03-24 21:40:28 +01:00
|
|
|
|
/* The symbol is undefined (or is defined but not in this section).
|
|
|
|
|
Let the linker figure it out. */
|
|
|
|
|
return 0;
|
2001-05-02 20:14:31 +02:00
|
|
|
|
|
|
|
|
|
return (fixP->fx_frag->fr_address + fixP->fx_where) & ~1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Return the bfd reloc type for OPERAND of INSN at fixup FIXP.
|
|
|
|
|
Returns BFD_RELOC_NONE if no reloc type can be found.
|
|
|
|
|
*FIXP may be modified if desired. */
|
|
|
|
|
|
|
|
|
|
bfd_reloc_code_real_type
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_cgen_lookup_reloc (const CGEN_INSN * insn ATTRIBUTE_UNUSED,
|
|
|
|
|
const CGEN_OPERAND * operand,
|
|
|
|
|
fixS * fixP)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
bfd_reloc_code_real_type type;
|
|
|
|
|
|
|
|
|
|
switch (operand->type)
|
|
|
|
|
{
|
2002-05-11 11:53:52 +02:00
|
|
|
|
case OPENRISC_OPERAND_ABS_26:
|
|
|
|
|
fixP->fx_pcrel = 0;
|
2001-05-02 20:14:31 +02:00
|
|
|
|
type = BFD_RELOC_OPENRISC_ABS_26;
|
|
|
|
|
goto emit;
|
2002-05-11 11:53:52 +02:00
|
|
|
|
case OPENRISC_OPERAND_DISP_26:
|
|
|
|
|
fixP->fx_pcrel = 1;
|
2001-05-02 20:14:31 +02:00
|
|
|
|
type = BFD_RELOC_OPENRISC_REL_26;
|
|
|
|
|
goto emit;
|
|
|
|
|
|
|
|
|
|
case OPENRISC_OPERAND_HI16:
|
|
|
|
|
type = BFD_RELOC_HI16;
|
|
|
|
|
goto emit;
|
|
|
|
|
|
|
|
|
|
case OPENRISC_OPERAND_LO16:
|
|
|
|
|
type = BFD_RELOC_LO16;
|
|
|
|
|
goto emit;
|
|
|
|
|
|
|
|
|
|
emit:
|
|
|
|
|
return type;
|
|
|
|
|
|
|
|
|
|
default : /* avoid -Wall warning */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BFD_RELOC_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Write a value out to the object file, using the appropriate endianness. */
|
|
|
|
|
|
|
|
|
|
void
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_number_to_chars (char * buf, valueT val, int n)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
|
|
|
|
number_to_chars_bigendian (buf, val, n);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
|
|
char *
|
2005-03-24 21:40:28 +01:00
|
|
|
|
md_atof (int type, char * litP, int * sizeP)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
2007-10-17 18:45:56 +02:00
|
|
|
|
return ieee_md_atof (type, litP, sizeP, TRUE);
|
2001-05-02 20:14:31 +02:00
|
|
|
|
}
|
|
|
|
|
|
2002-11-30 09:39:46 +01:00
|
|
|
|
bfd_boolean
|
2005-03-24 21:40:28 +01:00
|
|
|
|
openrisc_fix_adjustable (fixS * fixP)
|
2001-05-02 20:14:31 +02:00
|
|
|
|
{
|
2005-03-24 21:40:28 +01:00
|
|
|
|
/* We need the symbol name for the VTABLE entries. */
|
2001-05-02 20:14:31 +02:00
|
|
|
|
if (fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
|
|
|
|
|
|| fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
|
2002-05-11 11:53:52 +02:00
|
|
|
|
return 0;
|
2001-05-02 20:14:31 +02:00
|
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
|
}
|