/* -*- c -*- */
+/* Copyright (C) 2012-2015 Free Software Foundation, Inc.
+ Contributed by Red Hat.
+ Written by DJ Delorie.
+
+ This file is part of the GNU opcodes library.
+
+ This library 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 3, or (at your option)
+ any later version.
+
+ It 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 this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
+ MA 02110-1301, USA. */
+
+#include "sysdep.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-
-#include "config.h"
#include "ansidecl.h"
#include "opcode/rx.h"
{
RX_Byte,
RX_Word,
- RX_Long
+ RX_Long,
+ RX_Bad_Size /* Bogus instructions can have a size field set to 3. */
};
static int sbwl[] =
{
RX_SByte,
RX_SWord,
- RX_Long
+ RX_Long,
+ RX_Bad_Size /* Bogus instructions can have a size field set to 3. */
};
-static int ubwl[] =
+static int ubw[] =
{
RX_UByte,
RX_UWord,
- RX_Long
+ RX_Bad_Size,/* Bogus instructions can have a size field set to 2. */
+ RX_Bad_Size /* Bogus instructions can have a size field set to 3. */
};
static int memex[] =
rx->op[n].size = s )
/* This is for the BWL and BW bitfields. */
-static int SCALE[] = { 1, 2, 4 };
+static int SCALE[] = { 1, 2, 4, 0 };
/* This is for the prefix size enum. */
static int PSCALE[] = { 4, 1, 1, 1, 2, 2, 2, 3, 4 };
#define BWL(sz) rx->op[0].size = rx->op[1].size = rx->op[2].size = rx->size = bwl[sz]
#define sBWL(sz) rx->op[0].size = rx->op[1].size = rx->op[2].size = rx->size = sbwl[sz]
-#define uBWL(sz) rx->op[0].size = rx->op[1].size = rx->op[2].size = rx->size = ubwl[sz]
+#define uBW(sz) rx->op[0].size = rx->op[1].size = rx->op[2].size = rx->size = ubw[sz]
#define P(t, n) rx->op[n].size = (t!=3) ? RX_UByte : RX_Long;
#define F(f) store_flags(rx, f)
ld->rx->op[n].type = RX_Operand_Register;
break;
case 0:
- ld->rx->op[n].type = RX_Operand_Indirect;
+ ld->rx->op[n].type = RX_Operand_Zero_Indirect;
ld->rx->op[n].addend = 0;
break;
case 1:
#define xZ 2
#define xC 1
-#define F_____
+#define F_____
#define F___ZC rx->flags_0 = rx->flags_s = xZ|xC;
#define F__SZ_ rx->flags_0 = rx->flags_s = xS|xZ;
#define F__SZC rx->flags_0 = rx->flags_s = xS|xZ|xC;
ID(mov); DR(rdst); SC(IMM (1)); F_____;
/** 1111 10sd rdst im sz mov%s #%1, %0 */
- ID(mov); sBWL (sz); DD(sd, rdst, sz); SC(IMMex(im)); F_____;
+ ID(mov); DD(sd, rdst, sz);
+ if ((im == 1 && sz == 0)
+ || (im == 2 && sz == 1)
+ || (im == 0 && sz == 2))
+ {
+ BWL (sz);
+ SC(IMM(im));
+ }
+ else
+ {
+ sBWL (sz);
+ SC(IMMex(im));
+ }
+ F_____;
/** 0110 0110 immm rdst mov%s #%1, %0 */
ID(mov); DR(rdst); SC(immm); F_____;
ID(mov); sBWL (sz); DIs(dst, d*16+sppp, sz); SC(IMM(1)); F_____;
/** 11sz sd ss rsrc rdst mov%s %1, %0 */
- if (ss == 3 && sz == 2 && rsrc == 0 && rdst == 0)
+ if (sd == 3 && ss == 3 && sz == 2 && rsrc == 0 && rdst == 0)
{
ID(nop2);
+ SYNTAX ("nop\t; mov.l\tr0, r0");
}
else
{
ID(movbir); sBWL(sz); DR(rdst); SRR(isrc); S2R(bsrc); F_____;
/** 1111 1110 11sz isrc bsrc rdst movu%s [%1, %2], %0 */
- ID(movbi); uBWL(sz); DR(rdst); SRR(isrc); S2R(bsrc); F_____;
+ ID(movbi); uBW(sz); DR(rdst); SRR(isrc); S2R(bsrc); F_____;
/** 1111 1101 0010 0p sz rdst rsrc mov%s %1, %0 */
ID(mov); sBWL (sz); SR(rsrc); F_____;
OP(1, p ? RX_Operand_Predec : RX_Operand_Postinc, rsrc, 0);
/** 1011 w dsp a src b dst movu%s %1, %0 */
- ID(mov); uBWL(w); DR(dst); SIs(src, dsp*4+a*2+b, w); F_____;
+ ID(mov); uBW(w); DR(dst); SIs(src, dsp*4+a*2+b, w); F_____;
/** 0101 1 s ss rsrc rdst movu%s %1, %0 */
- ID(mov); uBWL(s); SD(ss, rsrc, s); DR(rdst); F_____;
+ ID(mov); uBW(s); SD(ss, rsrc, s); DR(rdst); F_____;
/** 1111 1101 0011 1p sz rsrc rdst movu%s %1, %0 */
- ID(mov); uBWL (sz); DR(rdst); F_____;
+ ID(mov); uBW (sz); DR(rdst); F_____;
OP(1, p ? RX_Operand_Predec : RX_Operand_Postinc, rsrc, 0);
/*----------------------------------------------------------------------*/
/** 0110 1110 dsta dstb pushm %1-%2 */
ID(pushm); SR(dsta); S2R(dstb); F_____;
-
+
/** 0111 1110 1011 rdst pop %0 */
ID(mov); OP(1, RX_Operand_Postinc, 0, 0); DR(rdst); F_____;
-
+
/** 0111 1110 10sz rsrc push%s %1 */
ID(mov); BWL(sz); OP(0, RX_Operand_Predec, 0, 0); SR(rsrc); F_____;
/* MAX */
/** 1111 1101 0111 im00 0100rdst max #%1, %0 */
- ID(max); DR(rdst); SC(IMMex(im));
+ int val = IMMex (im);
+ if (im == 0 && (unsigned) val == 0x80000000 && rdst == 0)
+ {
+ ID (nop7);
+ SYNTAX("nop\t; max\t#0x80000000, r0");
+ }
+ else
+ {
+ ID(max);
+ }
+ DR(rdst); SC(val);
/** 1111 1100 0001 00ss rsrc rdst max %1%S1, %0 */
if (ss == 3 && rsrc == 0 && rdst == 0)
{
ID(nop3);
+ SYNTAX("nop\t; max\tr0, r0");
}
else
{
/* MUL */
/** 0110 0011 immm rdst mul #%1, %0 */
- ID(mul); DR(rdst); SC(immm); F_____;
+ if (immm == 1 && rdst == 0)
+ {
+ ID(nop2);
+ SYNTAX ("nop\t; mul\t#1, r0");
+ }
+ else
+ {
+ ID(mul);
+ }
+ DR(rdst); SC(immm); F_____;
/** 0111 01im 0001rdst mul #%1, %0 */
- ID(mul); DR(rdst); SC(IMMex(im)); F_____;
+ int val = IMMex(im);
+ if (val == 1 && rdst == 0)
+ {
+ SYNTAX("nop\t; mul\t#1, r0");
+ switch (im)
+ {
+ case 2: ID(nop4); break;
+ case 3: ID(nop5); break;
+ case 0: ID(nop6); break;
+ default:
+ ID(mul);
+ SYNTAX("mul #%1, %0");
+ break;
+ }
+ }
+ else
+ {
+ ID(mul);
+ }
+ DR(rdst); SC(val); F_____;
/** 0100 11ss rsrc rdst mul %1%S1, %0 */
ID(mul); SP(ss, rsrc); DR(rdst); F_____;
/** 1111 1100 0110 00sd rdst rsrc bset %1, %0%S0 */
ID(bset); BWL(BSIZE); SR(rsrc); DD(sd, rdst, BSIZE); F_____;
+ if (sd == 3) /* bset reg,reg */
+ BWL(LSIZE);
/** 0111 100b ittt rdst bset #%1, %0 */
ID(bset); BWL(LSIZE); SC(b*16+ittt); DR(rdst); F_____;
/** 1111 1100 0110 01sd rdst rsrc bclr %1, %0%S0 */
ID(bclr); BWL(BSIZE); SR(rsrc); DD(sd, rdst, BSIZE); F_____;
+ if (sd == 3) /* bset reg,reg */
+ BWL(LSIZE);
/** 0111 101b ittt rdst bclr #%1, %0 */
ID(bclr); BWL(LSIZE); SC(b*16+ittt); DR(rdst); F_____;
/** 1111 1100 0110 10sd rdst rsrc btst %2, %1%S1 */
ID(btst); BWL(BSIZE); S2R(rsrc); SD(sd, rdst, BSIZE); F___ZC;
+ if (sd == 3) /* bset reg,reg */
+ BWL(LSIZE);
/** 0111 110b ittt rdst btst #%2, %1 */
ID(btst); BWL(LSIZE); S2C(b*16+ittt); SR(rdst); F___ZC;
/** 1111 1100 0110 11sd rdst rsrc bnot %1, %0%S0 */
ID(bnot); BWL(BSIZE); SR(rsrc); DD(sd, rdst, BSIZE);
+ if (sd == 3) /* bset reg,reg */
+ BWL(LSIZE);
/** 1111 1101 111bittt 1111 rdst bnot #%1, %0 */
ID(bnot); BWL(LSIZE); SC(bittt); DR(rdst);