2018-10-30 18:43:02 -07:00
|
|
|
using ChocolArm64.Instructions;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2018-10-30 18:43:02 -07:00
|
|
|
namespace ChocolArm64.Decoders
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-10-30 18:43:02 -07:00
|
|
|
class OpCodeMemImm64 : OpCodeMem64
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
|
|
|
public long Imm { get; protected set; }
|
|
|
|
public bool WBack { get; protected set; }
|
|
|
|
public bool PostIdx { get; protected set; }
|
|
|
|
protected bool Unscaled { get; private set; }
|
|
|
|
|
|
|
|
private enum MemOp
|
|
|
|
{
|
|
|
|
Unscaled = 0,
|
|
|
|
PostIndexed = 1,
|
|
|
|
Unprivileged = 2,
|
|
|
|
PreIndexed = 3,
|
|
|
|
Unsigned
|
|
|
|
}
|
|
|
|
|
2018-10-30 18:43:02 -07:00
|
|
|
public OpCodeMemImm64(Inst inst, long position, int opCode) : base(inst, position, opCode)
|
2018-02-04 15:08:20 -08:00
|
|
|
{
|
2018-10-30 18:43:02 -07:00
|
|
|
Extend64 = ((opCode >> 22) & 3) == 2;
|
|
|
|
WBack = ((opCode >> 24) & 1) == 0;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
|
|
|
//The type is not valid for the Unsigned Immediate 12-bits encoding,
|
|
|
|
//because the bits 11:10 are used for the larger Immediate offset.
|
2018-10-30 18:43:02 -07:00
|
|
|
MemOp type = WBack ? (MemOp)((opCode >> 10) & 3) : MemOp.Unsigned;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
2018-10-30 18:43:02 -07:00
|
|
|
PostIdx = type == MemOp.PostIndexed;
|
|
|
|
Unscaled = type == MemOp.Unscaled ||
|
|
|
|
type == MemOp.Unprivileged;
|
2018-02-04 15:08:20 -08:00
|
|
|
|
|
|
|
//Unscaled and Unprivileged doesn't write back,
|
|
|
|
//but they do use the 9-bits Signed Immediate.
|
|
|
|
if (Unscaled)
|
|
|
|
{
|
|
|
|
WBack = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (WBack || Unscaled)
|
|
|
|
{
|
|
|
|
//9-bits Signed Immediate.
|
2018-12-10 16:58:52 -08:00
|
|
|
Imm = (opCode << 11) >> 23;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//12-bits Unsigned Immediate.
|
2018-10-30 18:43:02 -07:00
|
|
|
Imm = ((opCode >> 10) & 0xfff) << Size;
|
2018-02-04 15:08:20 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|