#include "sysdep.h"
#include "ansidecl.h"
#include "bfd.h"
#include "symcat.h"
#include "openrisc-desc.h"
#include "openrisc-opc.h"
#include "libiberty.h"
static int asm_hash_insn_p (const CGEN_INSN *);
static unsigned int asm_hash_insn (const char *);
static int dis_hash_insn_p (const CGEN_INSN *);
static unsigned int dis_hash_insn (const char *, CGEN_INSN_INT);
#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
#define F(f) & openrisc_cgen_ifld_table[OPENRISC_##f]
#else
#define F(f) & openrisc_cgen_ifld_table[OPENRISC_f]
#endif
static const CGEN_IFMT ifmt_empty ATTRIBUTE_UNUSED = {
0, 0, 0x0, { { 0 } }
};
static const CGEN_IFMT ifmt_l_j ATTRIBUTE_UNUSED = {
32, 32, 0xfc000000, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_ABS26) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_jr ATTRIBUTE_UNUSED = {
32, 32, 0xffe00000, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_OP3) }, { F (F_OP4) }, { F (F_R2) }, { F (F_UIMM16) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_bal ATTRIBUTE_UNUSED = {
32, 32, 0xfc000000, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_DISP26) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_movhi ATTRIBUTE_UNUSED = {
32, 32, 0xfc000000, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_R1) }, { F (F_R2) }, { F (F_SIMM16) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_mfsr ATTRIBUTE_UNUSED = {
32, 32, 0xfc000000, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_R1) }, { F (F_R2) }, { F (F_UIMM16) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_mtsr ATTRIBUTE_UNUSED = {
32, 32, 0xfc0007ff, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_R1) }, { F (F_R2) }, { F (F_R3) }, { F (F_I16_1) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_lw ATTRIBUTE_UNUSED = {
32, 32, 0xfc000000, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_R1) }, { F (F_R2) }, { F (F_SIMM16) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_sw ATTRIBUTE_UNUSED = {
32, 32, 0xfc000000, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_R1) }, { F (F_R3) }, { F (F_I16NC) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_sll ATTRIBUTE_UNUSED = {
32, 32, 0xfc0007ff, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_R1) }, { F (F_R2) }, { F (F_R3) }, { F (F_F_10_3) }, { F (F_OP6) }, { F (F_F_4_1) }, { F (F_OP7) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_slli ATTRIBUTE_UNUSED = {
32, 32, 0xfc00ffe0, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_R1) }, { F (F_R2) }, { F (F_F_15_8) }, { F (F_OP6) }, { F (F_UIMM5) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_add ATTRIBUTE_UNUSED = {
32, 32, 0xfc0007ff, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_R1) }, { F (F_R2) }, { F (F_R3) }, { F (F_F_10_7) }, { F (F_OP7) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_addi ATTRIBUTE_UNUSED = {
32, 32, 0xfc000000, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_R1) }, { F (F_R2) }, { F (F_LO16) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_sfgts ATTRIBUTE_UNUSED = {
32, 32, 0xffe007ff, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_OP5) }, { F (F_R2) }, { F (F_R3) }, { F (F_F_10_11) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_sfgtsi ATTRIBUTE_UNUSED = {
32, 32, 0xffe00000, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_OP5) }, { F (F_R2) }, { F (F_SIMM16) }, { 0 } }
};
static const CGEN_IFMT ifmt_l_sfgtui ATTRIBUTE_UNUSED = {
32, 32, 0xffe00000, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_OP5) }, { F (F_R2) }, { F (F_UIMM16) }, { 0 } }
};
#undef F
#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
#define A(a) (1 << CGEN_INSN_##a)
#else
#define A(a) (1 << CGEN_INSN_a)
#endif
#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
#define OPERAND(op) OPENRISC_OPERAND_##op
#else
#define OPERAND(op) OPENRISC_OPERAND_op
#endif
#define MNEM CGEN_SYNTAX_MNEMONIC
#define OP(field) CGEN_SYNTAX_MAKE_FIELD (OPERAND (field))
static const CGEN_OPCODE openrisc_cgen_insn_opcode_table[MAX_INSNS] =
{
{ { 0, 0, 0, 0 }, {{0}}, 0, {0}},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (ABS_26), 0 } },
& ifmt_l_j, { 0x0 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (ABS_26), 0 } },
& ifmt_l_j, { 0x4000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), 0 } },
& ifmt_l_jr, { 0x14000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), 0 } },
& ifmt_l_jr, { 0x14200000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (DISP_26), 0 } },
& ifmt_l_bal, { 0x8000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (DISP_26), 0 } },
& ifmt_l_bal, { 0xc000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (DISP_26), 0 } },
& ifmt_l_bal, { 0x10000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (UIMM_16), 0 } },
& ifmt_l_jr, { 0x17000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), 0 } },
& ifmt_l_jr, { 0x14400000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (UIMM_16), 0 } },
& ifmt_l_jr, { 0x16000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, 0 } },
& ifmt_l_jr, { 0x15000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (HI16), 0 } },
& ifmt_l_movhi, { 0x18000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), 0 } },
& ifmt_l_mfsr, { 0x1c000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_mtsr, { 0x40000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (SIMM_16), '(', OP (RA), ')', 0 } },
& ifmt_l_lw, { 0x80000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (SIMM_16), '(', OP (RA), ')', 0 } },
& ifmt_l_lw, { 0x84000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (SIMM_16), '(', OP (RA), ')', 0 } },
& ifmt_l_lw, { 0x88000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (SIMM_16), '(', OP (RA), ')', 0 } },
& ifmt_l_lw, { 0x8c000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (SIMM_16), '(', OP (RA), ')', 0 } },
& ifmt_l_lw, { 0x90000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (UI16NC), '(', OP (RA), ')', ',', OP (RB), 0 } },
& ifmt_l_sw, { 0xd4000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (UI16NC), '(', OP (RA), ')', ',', OP (RB), 0 } },
& ifmt_l_sw, { 0xd8000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (UI16NC), '(', OP (RA), ')', ',', OP (RB), 0 } },
& ifmt_l_sw, { 0xdc000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sll, { 0xe0000008 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (UIMM_5), 0 } },
& ifmt_l_slli, { 0xb4000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sll, { 0xe0000028 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (UIMM_5), 0 } },
& ifmt_l_slli, { 0xb4000020 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sll, { 0xe0000048 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (UIMM_5), 0 } },
& ifmt_l_slli, { 0xb4000040 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sll, { 0xe0000088 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (UIMM_5), 0 } },
& ifmt_l_slli, { 0xb4000080 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_add, { 0xe0000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (LO16), 0 } },
& ifmt_l_addi, { 0x94000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_add, { 0xe0000002 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (LO16), 0 } },
& ifmt_l_addi, { 0x9c000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_add, { 0xe0000003 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (LO16), 0 } },
& ifmt_l_addi, { 0xa0000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_add, { 0xe0000004 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (LO16), 0 } },
& ifmt_l_addi, { 0xa4000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_add, { 0xe0000005 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (LO16), 0 } },
& ifmt_l_addi, { 0xa8000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_add, { 0xe0000006 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (LO16), 0 } },
& ifmt_l_addi, { 0xac000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_add, { 0xe0000009 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RD), ',', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_add, { 0xe000000a }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sfgts, { 0xe4c00000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sfgts, { 0xe4400000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sfgts, { 0xe4e00000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sfgts, { 0xe4600000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sfgts, { 0xe5000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sfgts, { 0xe4800000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sfgts, { 0xe5200000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sfgts, { 0xe4a00000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (SIMM_16), 0 } },
& ifmt_l_sfgtsi, { 0xb8c00000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (UIMM_16), 0 } },
& ifmt_l_sfgtui, { 0xb8400000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (SIMM_16), 0 } },
& ifmt_l_sfgtsi, { 0xb8e00000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (UIMM_16), 0 } },
& ifmt_l_sfgtui, { 0xb8600000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (SIMM_16), 0 } },
& ifmt_l_sfgtsi, { 0xb9000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (UIMM_16), 0 } },
& ifmt_l_sfgtui, { 0xb8800000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (SIMM_16), 0 } },
& ifmt_l_sfgtsi, { 0xb9200000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (UIMM_16), 0 } },
& ifmt_l_sfgtui, { 0xb8a00000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sfgts, { 0xe4000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (SIMM_16), 0 } },
& ifmt_l_sfgtsi, { 0xb8000000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (RB), 0 } },
& ifmt_l_sfgts, { 0xe4200000 }
},
{
{ 0, 0, 0, 0 },
{ { MNEM, ' ', OP (RA), ',', OP (SIMM_16), 0 } },
& ifmt_l_sfgtsi, { 0xb8200000 }
},
};
#undef A
#undef OPERAND
#undef MNEM
#undef OP
#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
#define F(f) & openrisc_cgen_ifld_table[OPENRISC_##f]
#else
#define F(f) & openrisc_cgen_ifld_table[OPENRISC_f]
#endif
static const CGEN_IFMT ifmt_l_ret ATTRIBUTE_UNUSED = {
32, 32, 0xffffffff, { { F (F_CLASS) }, { F (F_SUB) }, { F (F_OP3) }, { F (F_OP4) }, { F (F_R2) }, { F (F_UIMM16) }, { 0 } }
};
#undef F
#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
#define A(a) (1 << CGEN_INSN_##a)
#else
#define A(a) (1 << CGEN_INSN_a)
#endif
#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
#define OPERAND(op) OPENRISC_OPERAND_##op
#else
#define OPERAND(op) OPENRISC_OPERAND_op
#endif
#define MNEM CGEN_SYNTAX_MNEMONIC
#define OP(field) CGEN_SYNTAX_MAKE_FIELD (OPERAND (field))
static const CGEN_IBASE openrisc_cgen_macro_insn_table[] =
{
{
-1, "l-ret", "l.ret", 32,
{ 0|A(ALIAS), { (1<<MACH_BASE) } }
},
};
static const CGEN_OPCODE openrisc_cgen_macro_insn_opcode_table[] =
{
{
{ 0, 0, 0, 0 },
{ { MNEM, 0 } },
& ifmt_l_ret, { 0x140b0000 }
},
};
#undef A
#undef OPERAND
#undef MNEM
#undef OP
#ifndef CGEN_ASM_HASH_P
#define CGEN_ASM_HASH_P(insn) 1
#endif
#ifndef CGEN_DIS_HASH_P
#define CGEN_DIS_HASH_P(insn) 1
#endif
static int
asm_hash_insn_p (insn)
const CGEN_INSN *insn ATTRIBUTE_UNUSED;
{
return CGEN_ASM_HASH_P (insn);
}
static int
dis_hash_insn_p (insn)
const CGEN_INSN *insn;
{
if (CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_NO_DIS))
return 0;
return CGEN_DIS_HASH_P (insn);
}
#ifndef CGEN_ASM_HASH
#define CGEN_ASM_HASH_SIZE 127
#ifdef CGEN_MNEMONIC_OPERANDS
#define CGEN_ASM_HASH(mnem) (*(unsigned char *) (mnem) % CGEN_ASM_HASH_SIZE)
#else
#define CGEN_ASM_HASH(mnem) (*(unsigned char *) (mnem) % CGEN_ASM_HASH_SIZE)
#endif
#endif
#ifndef CGEN_DIS_HASH
#define CGEN_DIS_HASH_SIZE 256
#define CGEN_DIS_HASH(buf, value) (*(unsigned char *) (buf))
#endif
static unsigned int
asm_hash_insn (mnem)
const char * mnem;
{
return CGEN_ASM_HASH (mnem);
}
static unsigned int
dis_hash_insn (buf, value)
const char * buf ATTRIBUTE_UNUSED;
CGEN_INSN_INT value ATTRIBUTE_UNUSED;
{
return CGEN_DIS_HASH (buf, value);
}
static void
set_fields_bitsize (CGEN_FIELDS *fields, int size)
{
CGEN_FIELDS_BITSIZE (fields) = size;
}
void
openrisc_cgen_init_opcode_table (CGEN_CPU_DESC cd)
{
int i;
int num_macros = (sizeof (openrisc_cgen_macro_insn_table) /
sizeof (openrisc_cgen_macro_insn_table[0]));
const CGEN_IBASE *ib = & openrisc_cgen_macro_insn_table[0];
const CGEN_OPCODE *oc = & openrisc_cgen_macro_insn_opcode_table[0];
CGEN_INSN *insns = xmalloc (num_macros * sizeof (CGEN_INSN));
memset (insns, 0, num_macros * sizeof (CGEN_INSN));
for (i = 0; i < num_macros; ++i)
{
insns[i].base = &ib[i];
insns[i].opcode = &oc[i];
openrisc_cgen_build_insn_regex (& insns[i]);
}
cd->macro_insn_table.init_entries = insns;
cd->macro_insn_table.entry_size = sizeof (CGEN_IBASE);
cd->macro_insn_table.num_init_entries = num_macros;
oc = & openrisc_cgen_insn_opcode_table[0];
insns = (CGEN_INSN *) cd->insn_table.init_entries;
for (i = 0; i < MAX_INSNS; ++i)
{
insns[i].opcode = &oc[i];
openrisc_cgen_build_insn_regex (& insns[i]);
}
cd->sizeof_fields = sizeof (CGEN_FIELDS);
cd->set_fields_bitsize = set_fields_bitsize;
cd->asm_hash_p = asm_hash_insn_p;
cd->asm_hash = asm_hash_insn;
cd->asm_hash_size = CGEN_ASM_HASH_SIZE;
cd->dis_hash_p = dis_hash_insn_p;
cd->dis_hash = dis_hash_insn;
cd->dis_hash_size = CGEN_DIS_HASH_SIZE;
}