1997-04-05 05:07:02 +08:00
|
|
|
|
/* Assembler interface for targets using CGEN. -*- C -*-
|
|
|
|
|
CGEN: Cpu tools GENerator
|
|
|
|
|
|
1998-07-22 04:59:23 +08:00
|
|
|
|
THIS FILE IS USED TO GENERATE m32r-asm.c.
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-02-24 05:20:37 +08:00
|
|
|
|
Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
|
|
|
|
This file is part of the GNU Binutils and GDB, the GNU debugger.
|
|
|
|
|
|
|
|
|
|
This program 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.
|
|
|
|
|
|
|
|
|
|
This program 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
|
1998-07-22 04:59:23 +08:00
|
|
|
|
along with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-01-15 09:48:51 +08:00
|
|
|
|
#include "sysdep.h"
|
1997-04-05 05:07:02 +08:00
|
|
|
|
#include <ctype.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "ansidecl.h"
|
|
|
|
|
#include "bfd.h"
|
1998-02-24 05:20:37 +08:00
|
|
|
|
#include "symcat.h"
|
1997-04-05 05:07:02 +08:00
|
|
|
|
#include "m32r-opc.h"
|
1998-05-23 07:03:45 +08:00
|
|
|
|
#include "opintl.h"
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-11-07 09:22:51 +08:00
|
|
|
|
#undef min
|
|
|
|
|
#define min(a,b) ((a) < (b) ? (a) : (b))
|
|
|
|
|
#undef max
|
|
|
|
|
#define max(a,b) ((a) > (b) ? (a) : (b))
|
|
|
|
|
|
|
|
|
|
#undef INLINE
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#define INLINE __inline__
|
|
|
|
|
#else
|
|
|
|
|
#define INLINE
|
|
|
|
|
#endif
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1999-01-06 08:21:27 +08:00
|
|
|
|
/* Used by the ifield rtx function. */
|
|
|
|
|
#define FLD(f) (fields->f)
|
|
|
|
|
|
1998-04-28 04:10:40 +08:00
|
|
|
|
static const char * insert_normal
|
1999-01-06 08:21:27 +08:00
|
|
|
|
PARAMS ((CGEN_OPCODE_DESC, long, unsigned int, unsigned int, unsigned int,
|
|
|
|
|
unsigned int, unsigned int, unsigned int, CGEN_INSN_BYTES_PTR));
|
1998-01-15 09:48:51 +08:00
|
|
|
|
static const char * parse_insn_normal
|
1998-11-07 09:22:51 +08:00
|
|
|
|
PARAMS ((CGEN_OPCODE_DESC, const CGEN_INSN *,
|
|
|
|
|
const char **, CGEN_FIELDS *));
|
1998-02-24 05:20:37 +08:00
|
|
|
|
static const char * insert_insn_normal
|
1998-11-07 09:22:51 +08:00
|
|
|
|
PARAMS ((CGEN_OPCODE_DESC, const CGEN_INSN *,
|
|
|
|
|
CGEN_FIELDS *, CGEN_INSN_BYTES_PTR, bfd_vma));
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-04-28 04:10:40 +08:00
|
|
|
|
/* -- assembler routines inserted here */
|
|
|
|
|
/* -- asm.c */
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-04-28 04:10:40 +08:00
|
|
|
|
/* Handle '#' prefixes (i.e. skip over them). */
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-02-24 05:20:37 +08:00
|
|
|
|
static const char *
|
1998-11-07 09:22:51 +08:00
|
|
|
|
parse_hash (od, strp, opindex, valuep)
|
|
|
|
|
CGEN_OPCODE_DESC od;
|
1998-04-28 04:10:40 +08:00
|
|
|
|
const char **strp;
|
|
|
|
|
int opindex;
|
|
|
|
|
unsigned long *valuep;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
{
|
1998-04-28 04:10:40 +08:00
|
|
|
|
if (**strp == '#')
|
|
|
|
|
++*strp;
|
1998-02-24 05:20:37 +08:00
|
|
|
|
return NULL;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
}
|
1998-01-16 08:26:51 +08:00
|
|
|
|
|
|
|
|
|
/* Handle shigh(), high(). */
|
|
|
|
|
|
|
|
|
|
static const char *
|
1998-11-07 09:22:51 +08:00
|
|
|
|
parse_hi16 (od, strp, opindex, valuep)
|
|
|
|
|
CGEN_OPCODE_DESC od;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
const char **strp;
|
|
|
|
|
int opindex;
|
|
|
|
|
unsigned long *valuep;
|
|
|
|
|
{
|
|
|
|
|
const char *errmsg;
|
|
|
|
|
enum cgen_parse_operand_result result_type;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
bfd_vma value;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
|
|
|
|
|
if (**strp == '#')
|
|
|
|
|
++*strp;
|
|
|
|
|
|
1998-05-23 07:03:45 +08:00
|
|
|
|
if (strncasecmp (*strp, "high(", 5) == 0)
|
1998-01-16 08:26:51 +08:00
|
|
|
|
{
|
|
|
|
|
*strp += 5;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_address (od, strp, opindex, BFD_RELOC_M32R_HI16_ULO,
|
|
|
|
|
&result_type, &value);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (**strp != ')')
|
|
|
|
|
return "missing `)'";
|
|
|
|
|
++*strp;
|
|
|
|
|
if (errmsg == NULL
|
|
|
|
|
&& result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
|
1998-11-07 09:22:51 +08:00
|
|
|
|
value >>= 16;
|
|
|
|
|
*valuep = value;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
return errmsg;
|
|
|
|
|
}
|
1998-05-23 07:03:45 +08:00
|
|
|
|
else if (strncasecmp (*strp, "shigh(", 6) == 0)
|
1998-01-16 08:26:51 +08:00
|
|
|
|
{
|
|
|
|
|
*strp += 6;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_address (od, strp, opindex, BFD_RELOC_M32R_HI16_SLO,
|
|
|
|
|
&result_type, &value);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (**strp != ')')
|
|
|
|
|
return "missing `)'";
|
|
|
|
|
++*strp;
|
|
|
|
|
if (errmsg == NULL
|
|
|
|
|
&& result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
|
1998-11-07 09:22:51 +08:00
|
|
|
|
value = (value >> 16) + (value & 0x8000 ? 1 : 0);
|
|
|
|
|
*valuep = value;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
return errmsg;
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-07 09:22:51 +08:00
|
|
|
|
return cgen_parse_unsigned_integer (od, strp, opindex, valuep);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handle low() in a signed context. Also handle sda().
|
|
|
|
|
The signedness of the value doesn't matter to low(), but this also
|
|
|
|
|
handles the case where low() isn't present. */
|
|
|
|
|
|
|
|
|
|
static const char *
|
1998-11-07 09:22:51 +08:00
|
|
|
|
parse_slo16 (od, strp, opindex, valuep)
|
|
|
|
|
CGEN_OPCODE_DESC od;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
const char **strp;
|
|
|
|
|
int opindex;
|
|
|
|
|
long *valuep;
|
|
|
|
|
{
|
|
|
|
|
const char *errmsg;
|
|
|
|
|
enum cgen_parse_operand_result result_type;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
bfd_vma value;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
|
|
|
|
|
if (**strp == '#')
|
|
|
|
|
++*strp;
|
|
|
|
|
|
1998-05-23 07:03:45 +08:00
|
|
|
|
if (strncasecmp (*strp, "low(", 4) == 0)
|
1998-01-16 08:26:51 +08:00
|
|
|
|
{
|
|
|
|
|
*strp += 4;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_address (od, strp, opindex, BFD_RELOC_M32R_LO16,
|
|
|
|
|
&result_type, &value);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (**strp != ')')
|
|
|
|
|
return "missing `)'";
|
|
|
|
|
++*strp;
|
1998-02-24 05:20:37 +08:00
|
|
|
|
if (errmsg == NULL
|
|
|
|
|
&& result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
|
1998-11-07 09:22:51 +08:00
|
|
|
|
value &= 0xffff;
|
|
|
|
|
*valuep = value;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
return errmsg;
|
|
|
|
|
}
|
|
|
|
|
|
1998-05-23 07:03:45 +08:00
|
|
|
|
if (strncasecmp (*strp, "sda(", 4) == 0)
|
1998-01-16 08:26:51 +08:00
|
|
|
|
{
|
|
|
|
|
*strp += 4;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_address (od, strp, opindex, BFD_RELOC_M32R_SDA16,
|
|
|
|
|
NULL, &value);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (**strp != ')')
|
|
|
|
|
return "missing `)'";
|
|
|
|
|
++*strp;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
*valuep = value;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
return errmsg;
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-07 09:22:51 +08:00
|
|
|
|
return cgen_parse_signed_integer (od, strp, opindex, valuep);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Handle low() in an unsigned context.
|
|
|
|
|
The signedness of the value doesn't matter to low(), but this also
|
|
|
|
|
handles the case where low() isn't present. */
|
|
|
|
|
|
|
|
|
|
static const char *
|
1998-11-07 09:22:51 +08:00
|
|
|
|
parse_ulo16 (od, strp, opindex, valuep)
|
|
|
|
|
CGEN_OPCODE_DESC od;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
const char **strp;
|
|
|
|
|
int opindex;
|
|
|
|
|
unsigned long *valuep;
|
|
|
|
|
{
|
|
|
|
|
const char *errmsg;
|
|
|
|
|
enum cgen_parse_operand_result result_type;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
bfd_vma value;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
|
|
|
|
|
if (**strp == '#')
|
|
|
|
|
++*strp;
|
|
|
|
|
|
1998-05-23 07:03:45 +08:00
|
|
|
|
if (strncasecmp (*strp, "low(", 4) == 0)
|
1998-01-16 08:26:51 +08:00
|
|
|
|
{
|
|
|
|
|
*strp += 4;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_address (od, strp, opindex, BFD_RELOC_M32R_LO16,
|
|
|
|
|
&result_type, &value);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (**strp != ')')
|
|
|
|
|
return "missing `)'";
|
|
|
|
|
++*strp;
|
1998-02-24 05:20:37 +08:00
|
|
|
|
if (errmsg == NULL
|
|
|
|
|
&& result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
|
1998-11-07 09:22:51 +08:00
|
|
|
|
value &= 0xffff;
|
|
|
|
|
*valuep = value;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
return errmsg;
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-07 09:22:51 +08:00
|
|
|
|
return cgen_parse_unsigned_integer (od, strp, opindex, valuep);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* -- */
|
|
|
|
|
|
|
|
|
|
/* Main entry point for operand parsing.
|
|
|
|
|
|
|
|
|
|
This function is basically just a big switch statement. Earlier versions
|
|
|
|
|
used tables to look up the function to use, but
|
|
|
|
|
- if the table contains both assembler and disassembler functions then
|
|
|
|
|
the disassembler contains much of the assembler and vice-versa,
|
|
|
|
|
- there's a lot of inlining possibilities as things grow,
|
|
|
|
|
- using a switch statement avoids the function call overhead.
|
|
|
|
|
|
|
|
|
|
This function could be moved into `parse_insn_normal', but keeping it
|
|
|
|
|
separate makes clear the interface between `parse_insn_normal' and each of
|
|
|
|
|
the handlers.
|
|
|
|
|
*/
|
|
|
|
|
|
1998-02-24 05:20:37 +08:00
|
|
|
|
const char *
|
1998-11-07 09:22:51 +08:00
|
|
|
|
m32r_cgen_parse_operand (od, opindex, strp, fields)
|
|
|
|
|
CGEN_OPCODE_DESC od;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
int opindex;
|
|
|
|
|
const char ** strp;
|
|
|
|
|
CGEN_FIELDS * fields;
|
|
|
|
|
{
|
|
|
|
|
const char * errmsg;
|
|
|
|
|
|
|
|
|
|
switch (opindex)
|
|
|
|
|
{
|
|
|
|
|
case M32R_OPERAND_SR :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_keyword (od, strp, & m32r_cgen_opval_h_gr, & fields->f_r2);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_DR :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_keyword (od, strp, & m32r_cgen_opval_h_gr, & fields->f_r1);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_SRC1 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_keyword (od, strp, & m32r_cgen_opval_h_gr, & fields->f_r1);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_SRC2 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_keyword (od, strp, & m32r_cgen_opval_h_gr, & fields->f_r2);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_SCR :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_keyword (od, strp, & m32r_cgen_opval_h_cr, & fields->f_r2);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_DCR :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_keyword (od, strp, & m32r_cgen_opval_h_cr, & fields->f_r1);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_SIMM8 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_signed_integer (od, strp, M32R_OPERAND_SIMM8, &fields->f_simm8);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_SIMM16 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_signed_integer (od, strp, M32R_OPERAND_SIMM16, &fields->f_simm16);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_UIMM4 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_unsigned_integer (od, strp, M32R_OPERAND_UIMM4, &fields->f_uimm4);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_UIMM5 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_unsigned_integer (od, strp, M32R_OPERAND_UIMM5, &fields->f_uimm5);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_UIMM16 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_unsigned_integer (od, strp, M32R_OPERAND_UIMM16, &fields->f_uimm16);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
1998-02-12 11:13:21 +08:00
|
|
|
|
/* start-sanitize-m32rx */
|
|
|
|
|
case M32R_OPERAND_IMM1 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_unsigned_integer (od, strp, M32R_OPERAND_IMM1, &fields->f_imm1);
|
1998-02-12 11:13:21 +08:00
|
|
|
|
break;
|
|
|
|
|
/* end-sanitize-m32rx */
|
|
|
|
|
/* start-sanitize-m32rx */
|
|
|
|
|
case M32R_OPERAND_ACCD :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_keyword (od, strp, & m32r_cgen_opval_h_accums, & fields->f_accd);
|
1998-02-12 11:13:21 +08:00
|
|
|
|
break;
|
|
|
|
|
/* end-sanitize-m32rx */
|
|
|
|
|
/* start-sanitize-m32rx */
|
|
|
|
|
case M32R_OPERAND_ACCS :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_keyword (od, strp, & m32r_cgen_opval_h_accums, & fields->f_accs);
|
1998-02-12 11:13:21 +08:00
|
|
|
|
break;
|
|
|
|
|
/* end-sanitize-m32rx */
|
|
|
|
|
/* start-sanitize-m32rx */
|
|
|
|
|
case M32R_OPERAND_ACC :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = cgen_parse_keyword (od, strp, & m32r_cgen_opval_h_accums, & fields->f_acc);
|
1998-02-12 11:13:21 +08:00
|
|
|
|
break;
|
|
|
|
|
/* end-sanitize-m32rx */
|
1998-04-28 04:10:40 +08:00
|
|
|
|
case M32R_OPERAND_HASH :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = parse_hash (od, strp, M32R_OPERAND_HASH, &fields->f_nil);
|
1998-04-28 04:10:40 +08:00
|
|
|
|
break;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
case M32R_OPERAND_HI16 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = parse_hi16 (od, strp, M32R_OPERAND_HI16, &fields->f_hi16);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_SLO16 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = parse_slo16 (od, strp, M32R_OPERAND_SLO16, &fields->f_simm16);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_ULO16 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = parse_ulo16 (od, strp, M32R_OPERAND_ULO16, &fields->f_uimm16);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_UIMM24 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
{
|
|
|
|
|
bfd_vma value;
|
|
|
|
|
errmsg = cgen_parse_address (od, strp, M32R_OPERAND_UIMM24, 0, NULL, & value);
|
|
|
|
|
fields->f_uimm24 = value;
|
|
|
|
|
}
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_DISP8 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
{
|
|
|
|
|
bfd_vma value;
|
|
|
|
|
errmsg = cgen_parse_address (od, strp, M32R_OPERAND_DISP8, 0, NULL, & value);
|
|
|
|
|
fields->f_disp8 = value;
|
|
|
|
|
}
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_DISP16 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
{
|
|
|
|
|
bfd_vma value;
|
|
|
|
|
errmsg = cgen_parse_address (od, strp, M32R_OPERAND_DISP16, 0, NULL, & value);
|
|
|
|
|
fields->f_disp16 = value;
|
|
|
|
|
}
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_DISP24 :
|
1998-11-07 09:22:51 +08:00
|
|
|
|
{
|
|
|
|
|
bfd_vma value;
|
|
|
|
|
errmsg = cgen_parse_address (od, strp, M32R_OPERAND_DISP24, 0, NULL, & value);
|
|
|
|
|
fields->f_disp24 = value;
|
|
|
|
|
}
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default :
|
1998-05-23 07:03:45 +08:00
|
|
|
|
/* xgettext:c-format */
|
|
|
|
|
fprintf (stderr, _("Unrecognized field %d while parsing.\n"), opindex);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
abort ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return errmsg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Main entry point for operand insertion.
|
|
|
|
|
|
|
|
|
|
This function is basically just a big switch statement. Earlier versions
|
|
|
|
|
used tables to look up the function to use, but
|
|
|
|
|
- if the table contains both assembler and disassembler functions then
|
|
|
|
|
the disassembler contains much of the assembler and vice-versa,
|
|
|
|
|
- there's a lot of inlining possibilities as things grow,
|
|
|
|
|
- using a switch statement avoids the function call overhead.
|
|
|
|
|
|
|
|
|
|
This function could be moved into `parse_insn_normal', but keeping it
|
|
|
|
|
separate makes clear the interface between `parse_insn_normal' and each of
|
|
|
|
|
the handlers. It's also needed by GAS to insert operands that couldn't be
|
|
|
|
|
resolved during parsing.
|
|
|
|
|
*/
|
|
|
|
|
|
1998-02-24 05:20:37 +08:00
|
|
|
|
const char *
|
1998-11-07 09:22:51 +08:00
|
|
|
|
m32r_cgen_insert_operand (od, opindex, fields, buffer, pc)
|
|
|
|
|
CGEN_OPCODE_DESC od;
|
1998-01-20 12:16:37 +08:00
|
|
|
|
int opindex;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
CGEN_FIELDS * fields;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
CGEN_INSN_BYTES_PTR buffer;
|
1998-07-22 04:59:23 +08:00
|
|
|
|
bfd_vma pc;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
{
|
1998-02-24 05:20:37 +08:00
|
|
|
|
const char * errmsg;
|
1999-01-06 08:21:27 +08:00
|
|
|
|
unsigned int total_length = CGEN_FIELDS_BITSIZE (fields);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
|
|
|
|
|
switch (opindex)
|
|
|
|
|
{
|
|
|
|
|
case M32R_OPERAND_SR :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_r2, 0|(1<<CGEN_OPERAND_UNSIGNED), 0, 12, 4, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_DR :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_r1, 0|(1<<CGEN_OPERAND_UNSIGNED), 0, 4, 4, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_SRC1 :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_r1, 0|(1<<CGEN_OPERAND_UNSIGNED), 0, 4, 4, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_SRC2 :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_r2, 0|(1<<CGEN_OPERAND_UNSIGNED), 0, 12, 4, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_SCR :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_r2, 0|(1<<CGEN_OPERAND_UNSIGNED), 0, 12, 4, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_DCR :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_r1, 0|(1<<CGEN_OPERAND_UNSIGNED), 0, 4, 4, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_SIMM8 :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_simm8, 0|(1<<CGEN_OPERAND_HASH_PREFIX), 0, 8, 8, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_SIMM16 :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_simm16, 0|(1<<CGEN_OPERAND_HASH_PREFIX), 0, 16, 16, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_UIMM4 :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_uimm4, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 0, 12, 4, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_UIMM5 :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_uimm5, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 0, 11, 5, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_UIMM16 :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_uimm16, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 0, 16, 16, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
1998-02-12 11:13:21 +08:00
|
|
|
|
/* start-sanitize-m32rx */
|
|
|
|
|
case M32R_OPERAND_IMM1 :
|
1998-02-24 05:20:37 +08:00
|
|
|
|
{
|
1998-07-22 04:59:23 +08:00
|
|
|
|
long value = fields->f_imm1;
|
|
|
|
|
value = ((value) - (1));
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_UNSIGNED), 0, 15, 1, 32, total_length, buffer);
|
1998-02-24 05:20:37 +08:00
|
|
|
|
}
|
1998-02-12 11:13:21 +08:00
|
|
|
|
break;
|
|
|
|
|
/* end-sanitize-m32rx */
|
|
|
|
|
/* start-sanitize-m32rx */
|
|
|
|
|
case M32R_OPERAND_ACCD :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_accd, 0|(1<<CGEN_OPERAND_UNSIGNED), 0, 4, 2, 32, total_length, buffer);
|
1998-02-12 11:13:21 +08:00
|
|
|
|
break;
|
|
|
|
|
/* end-sanitize-m32rx */
|
|
|
|
|
/* start-sanitize-m32rx */
|
|
|
|
|
case M32R_OPERAND_ACCS :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_accs, 0|(1<<CGEN_OPERAND_UNSIGNED), 0, 12, 2, 32, total_length, buffer);
|
1998-02-12 11:13:21 +08:00
|
|
|
|
break;
|
|
|
|
|
/* end-sanitize-m32rx */
|
|
|
|
|
/* start-sanitize-m32rx */
|
|
|
|
|
case M32R_OPERAND_ACC :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_acc, 0|(1<<CGEN_OPERAND_UNSIGNED), 0, 8, 1, 32, total_length, buffer);
|
1998-02-12 11:13:21 +08:00
|
|
|
|
break;
|
|
|
|
|
/* end-sanitize-m32rx */
|
1998-04-28 04:10:40 +08:00
|
|
|
|
case M32R_OPERAND_HASH :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_nil, 0, 0, 0, 0, 0, total_length, buffer);
|
1998-04-28 04:10:40 +08:00
|
|
|
|
break;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
case M32R_OPERAND_HI16 :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_hi16, 0|(1<<CGEN_OPERAND_SIGN_OPT)|(1<<CGEN_OPERAND_UNSIGNED), 0, 16, 16, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_SLO16 :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_simm16, 0, 0, 16, 16, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_ULO16 :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_uimm16, 0|(1<<CGEN_OPERAND_UNSIGNED), 0, 16, 16, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_UIMM24 :
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, fields->f_uimm24, 0|(1<<CGEN_OPERAND_HASH_PREFIX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_ABS_ADDR)|(1<<CGEN_OPERAND_UNSIGNED), 0, 8, 24, 32, total_length, buffer);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_DISP8 :
|
1998-02-24 05:20:37 +08:00
|
|
|
|
{
|
1998-07-22 04:59:23 +08:00
|
|
|
|
long value = fields->f_disp8;
|
1998-07-22 07:46:56 +08:00
|
|
|
|
value = ((int) (((value) - (((pc) & (-4))))) >> (2));
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), 0, 8, 8, 32, total_length, buffer);
|
1998-02-24 05:20:37 +08:00
|
|
|
|
}
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_DISP16 :
|
1998-02-24 05:20:37 +08:00
|
|
|
|
{
|
1998-07-22 04:59:23 +08:00
|
|
|
|
long value = fields->f_disp16;
|
1998-07-22 07:46:56 +08:00
|
|
|
|
value = ((int) (((value) - (pc))) >> (2));
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), 0, 16, 16, 32, total_length, buffer);
|
1998-02-24 05:20:37 +08:00
|
|
|
|
}
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case M32R_OPERAND_DISP24 :
|
1998-02-24 05:20:37 +08:00
|
|
|
|
{
|
1998-07-22 04:59:23 +08:00
|
|
|
|
long value = fields->f_disp24;
|
1998-07-22 07:46:56 +08:00
|
|
|
|
value = ((int) (((value) - (pc))) >> (2));
|
1999-01-06 08:21:27 +08:00
|
|
|
|
errmsg = insert_normal (od, value, 0|(1<<CGEN_OPERAND_RELAX)|(1<<CGEN_OPERAND_RELOC)|(1<<CGEN_OPERAND_PCREL_ADDR), 0, 8, 24, 32, total_length, buffer);
|
1998-02-24 05:20:37 +08:00
|
|
|
|
}
|
1998-01-16 08:26:51 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default :
|
1998-05-23 07:03:45 +08:00
|
|
|
|
/* xgettext:c-format */
|
|
|
|
|
fprintf (stderr, _("Unrecognized field %d while building insn.\n"),
|
1998-01-16 08:26:51 +08:00
|
|
|
|
opindex);
|
|
|
|
|
abort ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return errmsg;
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-07 09:22:51 +08:00
|
|
|
|
cgen_parse_fn * const m32r_cgen_parse_handlers[] =
|
1998-01-20 12:16:37 +08:00
|
|
|
|
{
|
|
|
|
|
0, /* default */
|
1998-01-16 08:26:51 +08:00
|
|
|
|
parse_insn_normal,
|
|
|
|
|
};
|
|
|
|
|
|
1998-11-07 09:22:51 +08:00
|
|
|
|
cgen_insert_fn * const m32r_cgen_insert_handlers[] =
|
1998-01-20 12:16:37 +08:00
|
|
|
|
{
|
|
|
|
|
0, /* default */
|
1998-01-16 08:26:51 +08:00
|
|
|
|
insert_insn_normal,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
1998-11-07 09:22:51 +08:00
|
|
|
|
m32r_cgen_init_asm (od)
|
|
|
|
|
CGEN_OPCODE_DESC od;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
1998-04-28 04:10:40 +08:00
|
|
|
|
|
1998-11-07 09:22:51 +08:00
|
|
|
|
#if ! CGEN_INT_INSN_P
|
|
|
|
|
|
|
|
|
|
/* Subroutine of insert_normal. */
|
|
|
|
|
|
|
|
|
|
static INLINE void
|
|
|
|
|
insert_1 (od, value, start, length, word_length, bufp)
|
|
|
|
|
CGEN_OPCODE_DESC od;
|
|
|
|
|
unsigned long value;
|
|
|
|
|
int start,length,word_length;
|
|
|
|
|
unsigned char *bufp;
|
|
|
|
|
{
|
|
|
|
|
unsigned long x,mask;
|
|
|
|
|
int shift;
|
|
|
|
|
int big_p = CGEN_OPCODE_INSN_ENDIAN (od) == CGEN_ENDIAN_BIG;
|
|
|
|
|
|
|
|
|
|
switch (word_length)
|
|
|
|
|
{
|
|
|
|
|
case 8:
|
|
|
|
|
x = *bufp;
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
if (big_p)
|
|
|
|
|
x = bfd_getb16 (bufp);
|
|
|
|
|
else
|
|
|
|
|
x = bfd_getl16 (bufp);
|
|
|
|
|
break;
|
|
|
|
|
case 24:
|
|
|
|
|
/* ??? This may need reworking as these cases don't necessarily
|
|
|
|
|
want the first byte and the last two bytes handled like this. */
|
|
|
|
|
if (big_p)
|
1999-01-06 08:21:27 +08:00
|
|
|
|
x = (bufp[0] << 16) | bfd_getb16 (bufp + 1);
|
1998-11-07 09:22:51 +08:00
|
|
|
|
else
|
1999-01-06 08:21:27 +08:00
|
|
|
|
x = bfd_getl16 (bufp) | (bufp[2] << 16);
|
1998-11-07 09:22:51 +08:00
|
|
|
|
break;
|
|
|
|
|
case 32:
|
|
|
|
|
if (big_p)
|
|
|
|
|
x = bfd_getb32 (bufp);
|
|
|
|
|
else
|
|
|
|
|
x = bfd_getl32 (bufp);
|
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
abort ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Written this way to avoid undefined behaviour. */
|
|
|
|
|
mask = (((1L << (length - 1)) - 1) << 1) | 1;
|
|
|
|
|
if (CGEN_INSN_LSB0_P)
|
1999-01-06 08:21:27 +08:00
|
|
|
|
shift = (start + 1) - length;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
else
|
|
|
|
|
shift = (word_length - (start + length));
|
|
|
|
|
x = (x & ~(mask << shift)) | ((value & mask) << shift);
|
|
|
|
|
|
|
|
|
|
switch (word_length)
|
|
|
|
|
{
|
|
|
|
|
case 8:
|
|
|
|
|
*bufp = x;
|
|
|
|
|
break;
|
|
|
|
|
case 16:
|
|
|
|
|
if (big_p)
|
|
|
|
|
bfd_putb16 (x, bufp);
|
|
|
|
|
else
|
|
|
|
|
bfd_putl16 (x, bufp);
|
|
|
|
|
break;
|
|
|
|
|
case 24:
|
|
|
|
|
/* ??? This may need reworking as these cases don't necessarily
|
|
|
|
|
want the first byte and the last two bytes handled like this. */
|
|
|
|
|
if (big_p)
|
|
|
|
|
{
|
1999-01-06 08:21:27 +08:00
|
|
|
|
bufp[0] = x >> 16;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
bfd_putb16 (x, bufp + 1);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bfd_putl16 (x, bufp);
|
1999-01-06 08:21:27 +08:00
|
|
|
|
bufp[2] = x >> 16;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 32:
|
|
|
|
|
if (big_p)
|
|
|
|
|
bfd_putb32 (x, bufp);
|
|
|
|
|
else
|
|
|
|
|
bfd_putl32 (x, bufp);
|
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
abort ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* ! CGEN_INT_INSN_P */
|
|
|
|
|
|
1998-04-28 04:10:40 +08:00
|
|
|
|
/* Default insertion routine.
|
|
|
|
|
|
|
|
|
|
ATTRS is a mask of the boolean attributes.
|
1999-01-06 08:21:27 +08:00
|
|
|
|
WORD_OFFSET is the offset in bits from the start of the insn of the value.
|
|
|
|
|
WORD_LENGTH is the length of the word in bits in which the value resides.
|
|
|
|
|
START is the starting bit number in the word, architecture origin.
|
1998-04-28 04:10:40 +08:00
|
|
|
|
LENGTH is the length of VALUE in bits.
|
1999-01-06 08:21:27 +08:00
|
|
|
|
TOTAL_LENGTH is the total length of the insn in bits.
|
1998-04-28 04:10:40 +08:00
|
|
|
|
|
|
|
|
|
The result is an error message or NULL if success. */
|
|
|
|
|
|
|
|
|
|
/* ??? This duplicates functionality with bfd's howto table and
|
|
|
|
|
bfd_install_relocation. */
|
1998-11-07 09:22:51 +08:00
|
|
|
|
/* ??? This doesn't handle bfd_vma's. Create another function when
|
|
|
|
|
necessary. */
|
1998-04-28 04:10:40 +08:00
|
|
|
|
|
|
|
|
|
static const char *
|
1999-01-06 08:21:27 +08:00
|
|
|
|
insert_normal (od, value, attrs, word_offset, start, length, word_length,
|
|
|
|
|
total_length, buffer)
|
1998-11-07 09:22:51 +08:00
|
|
|
|
CGEN_OPCODE_DESC od;
|
1998-04-28 04:10:40 +08:00
|
|
|
|
long value;
|
|
|
|
|
unsigned int attrs;
|
1999-01-06 08:21:27 +08:00
|
|
|
|
unsigned int word_offset, start, length, word_length, total_length;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
CGEN_INSN_BYTES_PTR buffer;
|
1998-04-28 04:10:40 +08:00
|
|
|
|
{
|
1998-11-07 09:22:51 +08:00
|
|
|
|
static char errbuf[100];
|
|
|
|
|
/* Written this way to avoid undefined behaviour. */
|
|
|
|
|
unsigned long mask = (((1L << (length - 1)) - 1) << 1) | 1;
|
1998-05-23 07:03:45 +08:00
|
|
|
|
|
|
|
|
|
/* If LENGTH is zero, this operand doesn't contribute to the value. */
|
|
|
|
|
if (length == 0)
|
|
|
|
|
return NULL;
|
1998-04-28 04:10:40 +08:00
|
|
|
|
|
1999-01-06 08:21:27 +08:00
|
|
|
|
if (CGEN_INT_INSN_P
|
|
|
|
|
&& word_offset != 0)
|
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
|
|
if (word_length > 32)
|
|
|
|
|
abort ();
|
|
|
|
|
|
|
|
|
|
/* For architectures with insns smaller than the insn-base-bitsize,
|
|
|
|
|
word_length may be too big. */
|
|
|
|
|
#if CGEN_MIN_INSN_BITSIZE < CGEN_BASE_INSN_BITSIZE
|
|
|
|
|
if (word_offset == 0
|
|
|
|
|
&& word_length > total_length)
|
|
|
|
|
word_length = total_length;
|
|
|
|
|
#endif
|
|
|
|
|
|
1998-04-28 04:10:40 +08:00
|
|
|
|
/* Ensure VALUE will fit. */
|
1999-01-06 08:21:27 +08:00
|
|
|
|
if (CGEN_BOOL_ATTR (attrs, CGEN_OPERAND_UNSIGNED))
|
1998-04-28 04:10:40 +08:00
|
|
|
|
{
|
1998-11-07 09:22:51 +08:00
|
|
|
|
unsigned long maxval = mask;
|
|
|
|
|
if ((unsigned long) value > maxval)
|
1998-04-28 04:10:40 +08:00
|
|
|
|
{
|
1998-05-23 07:03:45 +08:00
|
|
|
|
/* xgettext:c-format */
|
1998-11-07 09:22:51 +08:00
|
|
|
|
sprintf (errbuf,
|
|
|
|
|
_("operand out of range (%lu not between 0 and %lu)"),
|
|
|
|
|
value, maxval);
|
|
|
|
|
return errbuf;
|
1998-04-28 04:10:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-11-07 09:22:51 +08:00
|
|
|
|
long minval = - (1L << (length - 1));
|
|
|
|
|
long maxval = (1L << (length - 1)) - 1;
|
|
|
|
|
if (value < minval || value > maxval)
|
1998-04-28 04:10:40 +08:00
|
|
|
|
{
|
1998-05-23 07:03:45 +08:00
|
|
|
|
sprintf
|
|
|
|
|
/* xgettext:c-format */
|
1998-11-07 09:22:51 +08:00
|
|
|
|
(errbuf, _("operand out of range (%ld not between %ld and %ld)"),
|
|
|
|
|
value, minval, maxval);
|
|
|
|
|
return errbuf;
|
1998-04-28 04:10:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1998-11-07 09:22:51 +08:00
|
|
|
|
#if CGEN_INT_INSN_P
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
int shift;
|
|
|
|
|
|
|
|
|
|
if (CGEN_INSN_LSB0_P)
|
1999-01-06 08:21:27 +08:00
|
|
|
|
shift = (start + 1) - length;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
else
|
1999-01-06 08:21:27 +08:00
|
|
|
|
shift = word_length - (start + length);
|
1998-11-07 09:22:51 +08:00
|
|
|
|
*buffer = (*buffer & ~(mask << shift)) | ((value & mask) << shift);
|
|
|
|
|
}
|
|
|
|
|
|
1999-01-06 08:21:27 +08:00
|
|
|
|
#else /* ! CGEN_INT_INSN_P */
|
1998-04-28 04:10:40 +08:00
|
|
|
|
|
1999-01-06 08:21:27 +08:00
|
|
|
|
{
|
|
|
|
|
unsigned char *bufp = (unsigned char *) buffer + word_offset / 8;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
|
1999-01-06 08:21:27 +08:00
|
|
|
|
insert_1 (od, value, start, length, word_length, bufp);
|
|
|
|
|
}
|
1998-11-07 09:22:51 +08:00
|
|
|
|
|
|
|
|
|
#endif /* ! CGEN_INT_INSN_P */
|
1998-04-28 04:10:40 +08:00
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
|
|
|
|
/* Default insn parser.
|
|
|
|
|
|
|
|
|
|
The syntax string is scanned and operands are parsed and stored in FIELDS.
|
|
|
|
|
Relocs are queued as we go via other callbacks.
|
|
|
|
|
|
|
|
|
|
??? Note that this is currently an all-or-nothing parser. If we fail to
|
|
|
|
|
parse the instruction, we return 0 and the caller will start over from
|
|
|
|
|
the beginning. Backtracking will be necessary in parsing subexpressions,
|
|
|
|
|
but that can be handled there. Not handling backtracking here may get
|
|
|
|
|
expensive in the case of the m68k. Deal with later.
|
|
|
|
|
|
|
|
|
|
Returns NULL for success, an error message for failure.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
static const char *
|
1998-11-07 09:22:51 +08:00
|
|
|
|
parse_insn_normal (od, insn, strp, fields)
|
|
|
|
|
CGEN_OPCODE_DESC od;
|
1998-02-24 05:20:37 +08:00
|
|
|
|
const CGEN_INSN * insn;
|
|
|
|
|
const char ** strp;
|
|
|
|
|
CGEN_FIELDS * fields;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
{
|
1998-02-24 05:20:37 +08:00
|
|
|
|
const CGEN_SYNTAX * syntax = CGEN_INSN_SYNTAX (insn);
|
|
|
|
|
const char * str = *strp;
|
|
|
|
|
const char * errmsg;
|
|
|
|
|
const char * p;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
const unsigned char * syn;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
#ifdef CGEN_MNEMONIC_OPERANDS
|
1998-07-22 04:59:23 +08:00
|
|
|
|
/* FIXME: wip */
|
1998-02-24 05:20:37 +08:00
|
|
|
|
int past_opcode_p;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
1998-01-15 09:48:51 +08:00
|
|
|
|
/* For now we assume the mnemonic is first (there are no leading operands).
|
1998-11-07 09:22:51 +08:00
|
|
|
|
We can parse it without needing to set up operand parsing.
|
|
|
|
|
GAS's input scrubber will ensure mnemonics are lowercase, but we may
|
|
|
|
|
not be called from GAS. */
|
1998-01-15 09:48:51 +08:00
|
|
|
|
p = CGEN_INSN_MNEMONIC (insn);
|
1998-11-07 09:22:51 +08:00
|
|
|
|
while (*p && tolower (*p) == tolower (*str))
|
|
|
|
|
++p, ++str;
|
1998-05-23 07:03:45 +08:00
|
|
|
|
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (* p || (* str && !isspace (* str)))
|
1998-05-23 07:03:45 +08:00
|
|
|
|
return _("unrecognized instruction");
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-11-07 09:22:51 +08:00
|
|
|
|
CGEN_INIT_PARSE (od);
|
|
|
|
|
cgen_init_parse_operand (od);
|
1997-04-05 05:07:02 +08:00
|
|
|
|
#ifdef CGEN_MNEMONIC_OPERANDS
|
|
|
|
|
past_opcode_p = 0;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* We don't check for (*str != '\0') here because we want to parse
|
|
|
|
|
any trailing fake arguments in the syntax string. */
|
1998-11-07 09:22:51 +08:00
|
|
|
|
syn = CGEN_SYNTAX_STRING (syntax);
|
1998-02-24 05:20:37 +08:00
|
|
|
|
|
1998-01-15 09:48:51 +08:00
|
|
|
|
/* Mnemonics come first for now, ensure valid string. */
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (! CGEN_SYNTAX_MNEMONIC_P (* syn))
|
1998-01-15 09:48:51 +08:00
|
|
|
|
abort ();
|
1998-02-24 05:20:37 +08:00
|
|
|
|
|
1998-01-15 09:48:51 +08:00
|
|
|
|
++syn;
|
1998-02-24 05:20:37 +08:00
|
|
|
|
|
1998-01-16 08:26:51 +08:00
|
|
|
|
while (* syn != 0)
|
1997-04-05 05:07:02 +08:00
|
|
|
|
{
|
|
|
|
|
/* Non operand chars must match exactly. */
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (CGEN_SYNTAX_CHAR_P (* syn))
|
1997-04-05 05:07:02 +08:00
|
|
|
|
{
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (*str == CGEN_SYNTAX_CHAR (* syn))
|
1997-04-05 05:07:02 +08:00
|
|
|
|
{
|
|
|
|
|
#ifdef CGEN_MNEMONIC_OPERANDS
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (* syn == ' ')
|
1997-04-05 05:07:02 +08:00
|
|
|
|
past_opcode_p = 1;
|
|
|
|
|
#endif
|
1998-01-16 08:26:51 +08:00
|
|
|
|
++ syn;
|
|
|
|
|
++ str;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Syntax char didn't match. Can't be this insn. */
|
1998-02-24 05:20:37 +08:00
|
|
|
|
/* FIXME: would like to return something like
|
|
|
|
|
"expected char `c'" */
|
1998-05-23 07:03:45 +08:00
|
|
|
|
return _("syntax error");
|
1997-04-05 05:07:02 +08:00
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We have an operand of some sort. */
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = m32r_cgen_parse_operand (od, CGEN_SYNTAX_FIELD (*syn),
|
|
|
|
|
&str, fields);
|
1997-04-05 05:07:02 +08:00
|
|
|
|
if (errmsg)
|
|
|
|
|
return errmsg;
|
|
|
|
|
|
|
|
|
|
/* Done with this operand, continue with next one. */
|
1998-01-16 08:26:51 +08:00
|
|
|
|
++ syn;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we're at the end of the syntax string, we're done. */
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (* syn == '\0')
|
1997-04-05 05:07:02 +08:00
|
|
|
|
{
|
|
|
|
|
/* FIXME: For the moment we assume a valid `str' can only contain
|
|
|
|
|
blanks now. IE: We needn't try again with a longer version of
|
|
|
|
|
the insn and it is assumed that longer versions of insns appear
|
|
|
|
|
before shorter ones (eg: lsr r2,r3,1 vs lsr r2,r3). */
|
1998-01-16 08:26:51 +08:00
|
|
|
|
while (isspace (* str))
|
|
|
|
|
++ str;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (* str != '\0')
|
1998-05-23 07:03:45 +08:00
|
|
|
|
return _("junk at end of line"); /* FIXME: would like to include `str' */
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We couldn't parse it. */
|
1998-11-07 09:22:51 +08:00
|
|
|
|
return _("unrecognized instruction");
|
1997-04-05 05:07:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Default insn builder (insert handler).
|
1998-11-07 09:22:51 +08:00
|
|
|
|
The instruction is recorded in CGEN_INT_INSN_P byte order
|
|
|
|
|
(meaning that if CGEN_INT_INSN_P BUFFER is an int * and thus the value is
|
|
|
|
|
recorded in host byte order, otherwise BUFFER is an array of bytes and the
|
|
|
|
|
value is recorded in target byte order).
|
1998-02-24 05:20:37 +08:00
|
|
|
|
The result is an error message or NULL if success. */
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-02-24 05:20:37 +08:00
|
|
|
|
static const char *
|
1998-11-07 09:22:51 +08:00
|
|
|
|
insert_insn_normal (od, insn, fields, buffer, pc)
|
|
|
|
|
CGEN_OPCODE_DESC od;
|
1998-02-24 05:20:37 +08:00
|
|
|
|
const CGEN_INSN * insn;
|
|
|
|
|
CGEN_FIELDS * fields;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
CGEN_INSN_BYTES_PTR buffer;
|
1998-07-22 04:59:23 +08:00
|
|
|
|
bfd_vma pc;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
{
|
1998-02-24 05:20:37 +08:00
|
|
|
|
const CGEN_SYNTAX * syntax = CGEN_INSN_SYNTAX (insn);
|
1998-11-07 09:22:51 +08:00
|
|
|
|
unsigned long value;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
const unsigned char * syn;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-11-07 09:22:51 +08:00
|
|
|
|
CGEN_INIT_INSERT (od);
|
1999-01-06 08:21:27 +08:00
|
|
|
|
value = CGEN_INSN_BASE_VALUE (insn);
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
|
|
|
|
/* If we're recording insns as numbers (rather than a string of bytes),
|
|
|
|
|
target byte order handling is deferred until later. */
|
1998-11-07 09:22:51 +08:00
|
|
|
|
|
|
|
|
|
#if CGEN_INT_INSN_P
|
|
|
|
|
|
1997-04-05 05:07:02 +08:00
|
|
|
|
*buffer = value;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
|
1997-04-05 05:07:02 +08:00
|
|
|
|
#else
|
1998-11-07 09:22:51 +08:00
|
|
|
|
|
1999-01-06 08:21:27 +08:00
|
|
|
|
cgen_put_insn_value (od, buffer, min (CGEN_BASE_INSN_BITSIZE,
|
1998-11-07 09:22:51 +08:00
|
|
|
|
CGEN_FIELDS_BITSIZE (fields)),
|
|
|
|
|
value);
|
|
|
|
|
|
|
|
|
|
#endif /* ! CGEN_INT_INSN_P */
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1999-01-06 08:21:27 +08:00
|
|
|
|
/* ??? It would be better to scan the format's fields.
|
|
|
|
|
Still need to be able to insert a value based on the operand though;
|
|
|
|
|
e.g. storing a branch displacement that got resolved later.
|
|
|
|
|
Needs more thought first. */
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-01-16 08:26:51 +08:00
|
|
|
|
for (syn = CGEN_SYNTAX_STRING (syntax); * syn != '\0'; ++ syn)
|
1997-04-05 05:07:02 +08:00
|
|
|
|
{
|
1998-02-24 05:20:37 +08:00
|
|
|
|
const char *errmsg;
|
|
|
|
|
|
1998-01-16 08:26:51 +08:00
|
|
|
|
if (CGEN_SYNTAX_CHAR_P (* syn))
|
1997-04-05 05:07:02 +08:00
|
|
|
|
continue;
|
|
|
|
|
|
1998-11-07 09:22:51 +08:00
|
|
|
|
errmsg = m32r_cgen_insert_operand (od, CGEN_SYNTAX_FIELD (*syn),
|
|
|
|
|
fields, buffer, pc);
|
1998-02-24 05:20:37 +08:00
|
|
|
|
if (errmsg)
|
|
|
|
|
return errmsg;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
}
|
1998-02-24 05:20:37 +08:00
|
|
|
|
|
|
|
|
|
return NULL;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Main entry point.
|
|
|
|
|
This routine is called for each instruction to be assembled.
|
|
|
|
|
STR points to the insn to be assembled.
|
|
|
|
|
We assume all necessary tables have been initialized.
|
1998-11-07 09:22:51 +08:00
|
|
|
|
The assembled instruction, less any fixups, is stored in BUF.
|
|
|
|
|
Remember that if CGEN_INT_INSN_P then BUF is an int and thus the value
|
|
|
|
|
still needs to be converted to target byte order, otherwise BUF is an array
|
|
|
|
|
of bytes in target byte order.
|
1997-04-05 05:07:02 +08:00
|
|
|
|
The result is a pointer to the insn's entry in the opcode table,
|
|
|
|
|
or NULL if an error occured (an error message will have already been
|
1998-04-28 04:10:40 +08:00
|
|
|
|
printed).
|
|
|
|
|
|
|
|
|
|
Note that when processing (non-alias) macro-insns,
|
|
|
|
|
this function recurses. */
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-01-15 09:48:51 +08:00
|
|
|
|
const CGEN_INSN *
|
1998-11-07 09:22:51 +08:00
|
|
|
|
m32r_cgen_assemble_insn (od, str, fields, buf, errmsg)
|
|
|
|
|
CGEN_OPCODE_DESC od;
|
1998-02-24 05:20:37 +08:00
|
|
|
|
const char * str;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
CGEN_FIELDS * fields;
|
1998-11-07 09:22:51 +08:00
|
|
|
|
CGEN_INSN_BYTES_PTR buf;
|
1998-02-24 05:20:37 +08:00
|
|
|
|
char ** errmsg;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
{
|
1998-02-24 05:20:37 +08:00
|
|
|
|
const char * start;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
CGEN_INSN_LIST * ilist;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
|
|
|
|
/* Skip leading white space. */
|
1998-01-16 08:26:51 +08:00
|
|
|
|
while (isspace (* str))
|
|
|
|
|
++ str;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
|
|
|
|
/* The instructions are stored in hashed lists.
|
|
|
|
|
Get the first in the list. */
|
1998-11-07 09:22:51 +08:00
|
|
|
|
ilist = CGEN_ASM_LOOKUP_INSN (od, str);
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
|
|
|
|
/* Keep looking until we find a match. */
|
|
|
|
|
|
|
|
|
|
start = str;
|
|
|
|
|
for ( ; ilist != NULL ; ilist = CGEN_ASM_NEXT_INSN (ilist))
|
|
|
|
|
{
|
1998-01-15 09:48:51 +08:00
|
|
|
|
const CGEN_INSN *insn = ilist->insn;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
|
|
|
|
#if 0 /* not needed as unsupported opcodes shouldn't be in the hash lists */
|
|
|
|
|
/* Is this insn supported by the selected cpu? */
|
1998-11-07 09:22:51 +08:00
|
|
|
|
if (! m32r_cgen_insn_supported (od, insn))
|
1997-04-05 05:07:02 +08:00
|
|
|
|
continue;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* If the RELAX attribute is set, this is an insn that shouldn't be
|
|
|
|
|
chosen immediately. Instead, it is used during assembler/linker
|
|
|
|
|
relaxation if possible. */
|
|
|
|
|
if (CGEN_INSN_ATTR (insn, CGEN_INSN_RELAX) != 0)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
str = start;
|
|
|
|
|
|
1999-01-06 08:21:27 +08:00
|
|
|
|
/* Allow parse/insert handlers to obtain length of insn. */
|
1997-04-05 05:07:02 +08:00
|
|
|
|
CGEN_FIELDS_BITSIZE (fields) = CGEN_INSN_BITSIZE (insn);
|
|
|
|
|
|
1998-11-07 09:22:51 +08:00
|
|
|
|
if (! CGEN_PARSE_FN (insn) (od, insn, & str, fields))
|
1997-04-05 05:07:02 +08:00
|
|
|
|
{
|
1998-07-22 04:59:23 +08:00
|
|
|
|
/* ??? 0 is passed for `pc' */
|
1998-11-07 09:22:51 +08:00
|
|
|
|
if (CGEN_INSERT_FN (insn) (od, insn, fields, buf, (bfd_vma) 0) != NULL)
|
1998-02-24 05:20:37 +08:00
|
|
|
|
continue;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
/* It is up to the caller to actually output the insn and any
|
|
|
|
|
queued relocs. */
|
|
|
|
|
return insn;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try the next entry. */
|
|
|
|
|
}
|
|
|
|
|
|
1997-04-11 05:58:28 +08:00
|
|
|
|
/* FIXME: We can return a better error message than this.
|
|
|
|
|
Need to track why it failed and pick the right one. */
|
|
|
|
|
{
|
|
|
|
|
static char errbuf[100];
|
1998-05-23 07:03:45 +08:00
|
|
|
|
if (strlen (start) > 50)
|
|
|
|
|
/* xgettext:c-format */
|
|
|
|
|
sprintf (errbuf, _("bad instruction `%.50s...'"), start);
|
|
|
|
|
else
|
|
|
|
|
/* xgettext:c-format */
|
|
|
|
|
sprintf (errbuf, _("bad instruction `%.50s'"), start);
|
|
|
|
|
|
1997-04-11 05:58:28 +08:00
|
|
|
|
*errmsg = errbuf;
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
1997-04-05 05:07:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
1997-04-11 05:58:28 +08:00
|
|
|
|
#if 0 /* This calls back to GAS which we can't do without care. */
|
|
|
|
|
|
1997-04-05 05:07:02 +08:00
|
|
|
|
/* Record each member of OPVALS in the assembler's symbol table.
|
1997-04-11 05:58:28 +08:00
|
|
|
|
This lets GAS parse registers for us.
|
|
|
|
|
??? Interesting idea but not currently used. */
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-01-15 09:48:51 +08:00
|
|
|
|
/* Record each member of OPVALS in the assembler's symbol table.
|
|
|
|
|
FIXME: Not currently used. */
|
|
|
|
|
|
1997-04-05 05:07:02 +08:00
|
|
|
|
void
|
1998-11-07 09:22:51 +08:00
|
|
|
|
m32r_cgen_asm_hash_keywords (od, opvals)
|
|
|
|
|
CGEN_OPCODE_DESC od;
|
1998-01-16 08:26:51 +08:00
|
|
|
|
CGEN_KEYWORD * opvals;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
{
|
1998-01-15 09:48:51 +08:00
|
|
|
|
CGEN_KEYWORD_SEARCH search = cgen_keyword_search_init (opvals, NULL);
|
1998-01-16 08:26:51 +08:00
|
|
|
|
const CGEN_KEYWORD_ENTRY * ke;
|
1997-04-05 05:07:02 +08:00
|
|
|
|
|
1998-01-16 08:26:51 +08:00
|
|
|
|
while ((ke = cgen_keyword_search_next (& search)) != NULL)
|
1997-04-05 05:07:02 +08:00
|
|
|
|
{
|
|
|
|
|
#if 0 /* Unnecessary, should be done in the search routine. */
|
|
|
|
|
if (! m32r_cgen_opval_supported (ke))
|
|
|
|
|
continue;
|
|
|
|
|
#endif
|
1998-11-07 09:22:51 +08:00
|
|
|
|
cgen_asm_record_register (od, ke->name, ke->value);
|
1997-04-05 05:07:02 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
1997-04-11 05:58:28 +08:00
|
|
|
|
|
|
|
|
|
#endif /* 0 */
|