136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//===- SparcDisassembler.cpp - Disassembler for Sparc -----------*- C++ -*-===//
236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//
336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//                     The LLVM Compiler Infrastructure
436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//
536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// This file is distributed under the University of Illinois Open Source
636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// License. See LICENSE.TXT for details.
736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//
836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//===----------------------------------------------------------------------===//
936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//
1036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines// This file is part of the Sparc Disassembler.
1136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//
1236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines//===----------------------------------------------------------------------===//
1336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
1436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "Sparc.h"
1536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "SparcRegisterInfo.h"
1636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "SparcSubtarget.h"
1736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/MC/MCDisassembler.h"
1836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/MC/MCFixedLenDisassembler.h"
1936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "llvm/Support/TargetRegistry.h"
2036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
2136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesusing namespace llvm;
2236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
23dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines#define DEBUG_TYPE "sparc-disassembler"
24dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines
2536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinestypedef MCDisassembler::DecodeStatus DecodeStatus;
2636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
2736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesnamespace {
2836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
2937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines/// A disassembler class for Sparc.
3036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesclass SparcDisassembler : public MCDisassembler {
3136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinespublic:
3237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  SparcDisassembler(const MCSubtargetInfo &STI, MCContext &Ctx)
3337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines      : MCDisassembler(STI, Ctx) {}
3436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  virtual ~SparcDisassembler() {}
3536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
3637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size,
3737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                              ArrayRef<uint8_t> Bytes, uint64_t Address,
3837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                              raw_ostream &VStream,
3937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                              raw_ostream &CStream) const override;
4036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines};
4136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
4236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
4336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
4436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesnamespace llvm {
4536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  extern Target TheSparcTarget, TheSparcV9Target;
4636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
4736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
4836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic MCDisassembler *createSparcDisassembler(
4936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                       const Target &T,
50dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                       const MCSubtargetInfo &STI,
51dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines                       MCContext &Ctx) {
52dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines  return new SparcDisassembler(STI, Ctx);
5336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
5436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
5536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
5636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesextern "C" void LLVMInitializeSparcDisassembler() {
5736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Register the disassembler.
5836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  TargetRegistry::RegisterMCDisassembler(TheSparcTarget,
5936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                         createSparcDisassembler);
6036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  TargetRegistry::RegisterMCDisassembler(TheSparcV9Target,
6136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                         createSparcDisassembler);
6236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
6336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
6436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
6536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
6636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic const unsigned IntRegDecoderTable[] = {
6736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::G0,  SP::G1,  SP::G2,  SP::G3,
6836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::G4,  SP::G5,  SP::G6,  SP::G7,
6936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::O0,  SP::O1,  SP::O2,  SP::O3,
7036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::O4,  SP::O5,  SP::O6,  SP::O7,
7136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::L0,  SP::L1,  SP::L2,  SP::L3,
7236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::L4,  SP::L5,  SP::L6,  SP::L7,
7336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::I0,  SP::I1,  SP::I2,  SP::I3,
7436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::I4,  SP::I5,  SP::I6,  SP::I7 };
7536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
7636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic const unsigned FPRegDecoderTable[] = {
7736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::F0,   SP::F1,   SP::F2,   SP::F3,
7836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::F4,   SP::F5,   SP::F6,   SP::F7,
7936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::F8,   SP::F9,   SP::F10,  SP::F11,
8036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::F12,  SP::F13,  SP::F14,  SP::F15,
8136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::F16,  SP::F17,  SP::F18,  SP::F19,
8236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::F20,  SP::F21,  SP::F22,  SP::F23,
8336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::F24,  SP::F25,  SP::F26,  SP::F27,
8436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::F28,  SP::F29,  SP::F30,  SP::F31 };
8536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
8636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic const unsigned DFPRegDecoderTable[] = {
8736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::D0,   SP::D16,  SP::D1,   SP::D17,
8836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::D2,   SP::D18,  SP::D3,   SP::D19,
8936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::D4,   SP::D20,  SP::D5,   SP::D21,
9036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::D6,   SP::D22,  SP::D7,   SP::D23,
9136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::D8,   SP::D24,  SP::D9,   SP::D25,
9236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::D10,  SP::D26,  SP::D11,  SP::D27,
9336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::D12,  SP::D28,  SP::D13,  SP::D29,
9436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::D14,  SP::D30,  SP::D15,  SP::D31 };
9536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
9636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic const unsigned QFPRegDecoderTable[] = {
9736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::Q0,  SP::Q8,   ~0U,  ~0U,
9836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::Q1,  SP::Q9,   ~0U,  ~0U,
9936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::Q2,  SP::Q10,  ~0U,  ~0U,
10036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::Q3,  SP::Q11,  ~0U,  ~0U,
10136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::Q4,  SP::Q12,  ~0U,  ~0U,
10236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::Q5,  SP::Q13,  ~0U,  ~0U,
10336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::Q6,  SP::Q14,  ~0U,  ~0U,
10436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::Q7,  SP::Q15,  ~0U,  ~0U } ;
10536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
10636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic const unsigned FCCRegDecoderTable[] = {
10736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  SP::FCC0, SP::FCC1, SP::FCC2, SP::FCC3 };
10836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
10936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeIntRegsRegisterClass(MCInst &Inst,
11036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               unsigned RegNo,
11136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               uint64_t Address,
11236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               const void *Decoder) {
11336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (RegNo > 31)
11436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return MCDisassembler::Fail;
11536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned Reg = IntRegDecoderTable[RegNo];
11636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Inst.addOperand(MCOperand::CreateReg(Reg));
11736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
11836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
11936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
12036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeI64RegsRegisterClass(MCInst &Inst,
12136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               unsigned RegNo,
12236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               uint64_t Address,
12336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               const void *Decoder) {
12436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (RegNo > 31)
12536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return MCDisassembler::Fail;
12636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned Reg = IntRegDecoderTable[RegNo];
12736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Inst.addOperand(MCOperand::CreateReg(Reg));
12836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
12936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
13036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
13136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
13236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeFPRegsRegisterClass(MCInst &Inst,
13336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                              unsigned RegNo,
13436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                              uint64_t Address,
13536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                              const void *Decoder) {
13636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (RegNo > 31)
13736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return MCDisassembler::Fail;
13836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned Reg = FPRegDecoderTable[RegNo];
13936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Inst.addOperand(MCOperand::CreateReg(Reg));
14036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
14136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
14236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
14336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
14436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeDFPRegsRegisterClass(MCInst &Inst,
14536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               unsigned RegNo,
14636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               uint64_t Address,
14736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               const void *Decoder) {
14836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (RegNo > 31)
14936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return MCDisassembler::Fail;
15036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned Reg = DFPRegDecoderTable[RegNo];
15136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Inst.addOperand(MCOperand::CreateReg(Reg));
15236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
15336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
15436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
15536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
15636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeQFPRegsRegisterClass(MCInst &Inst,
15736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               unsigned RegNo,
15836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               uint64_t Address,
15936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               const void *Decoder) {
16036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (RegNo > 31)
16136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return MCDisassembler::Fail;
16236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
16336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned Reg = QFPRegDecoderTable[RegNo];
16436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (Reg == ~0U)
16536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return MCDisassembler::Fail;
16636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Inst.addOperand(MCOperand::CreateReg(Reg));
16736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
16836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
16936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
17036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeFCCRegsRegisterClass(MCInst &Inst, unsigned RegNo,
17136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               uint64_t Address,
17236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                               const void *Decoder) {
17336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (RegNo > 3)
17436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return MCDisassembler::Fail;
17536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  Inst.addOperand(MCOperand::CreateReg(FCCRegDecoderTable[RegNo]));
17636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
17736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
17836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
17936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
18036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeLoadInt(MCInst &Inst, unsigned insn, uint64_t Address,
18136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                  const void *Decoder);
18236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeLoadFP(MCInst &Inst, unsigned insn, uint64_t Address,
18336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                 const void *Decoder);
18436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeLoadDFP(MCInst &Inst, unsigned insn, uint64_t Address,
18536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                  const void *Decoder);
18636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeLoadQFP(MCInst &Inst, unsigned insn, uint64_t Address,
18736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                  const void *Decoder);
18836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeStoreInt(MCInst &Inst, unsigned insn,
18936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                   uint64_t Address, const void *Decoder);
19036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeStoreFP(MCInst &Inst, unsigned insn,
19136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                  uint64_t Address, const void *Decoder);
19236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeStoreDFP(MCInst &Inst, unsigned insn,
19336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                   uint64_t Address, const void *Decoder);
19436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeStoreQFP(MCInst &Inst, unsigned insn,
19536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                   uint64_t Address, const void *Decoder);
19636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeCall(MCInst &Inst, unsigned insn,
19736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                               uint64_t Address, const void *Decoder);
19836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeSIMM13(MCInst &Inst, unsigned insn,
19936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                 uint64_t Address, const void *Decoder);
20036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeJMPL(MCInst &Inst, unsigned insn, uint64_t Address,
20136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                               const void *Decoder);
20236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeReturn(MCInst &MI, unsigned insn, uint64_t Address,
20336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                 const void *Decoder);
20436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeSWAP(MCInst &Inst, unsigned insn, uint64_t Address,
20536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                               const void *Decoder);
20636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
20736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines#include "SparcGenDisassemblerTables.inc"
20836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
20937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines/// Read four bytes from the ArrayRef and return 32 bit word.
21037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hinesstatic DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address,
21137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                                      uint64_t &Size, uint32_t &Insn) {
21236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // We want to read exactly 4 Bytes of data.
21337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  if (Bytes.size() < 4) {
21437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines    Size = 0;
21536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return MCDisassembler::Fail;
21636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
21736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
21836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Encoded as a big-endian 32-bit word in the stream.
21937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Insn =
22037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines      (Bytes[3] << 0) | (Bytes[2] << 8) | (Bytes[1] << 16) | (Bytes[0] << 24);
22136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
22236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
22336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
22436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
22537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen HinesDecodeStatus SparcDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
22637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                                               ArrayRef<uint8_t> Bytes,
22737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                                               uint64_t Address,
22837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                                               raw_ostream &VStream,
22937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines                                               raw_ostream &CStream) const {
23036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  uint32_t Insn;
23136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
23237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  DecodeStatus Result = readInstruction32(Bytes, Address, Size, Insn);
23336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (Result == MCDisassembler::Fail)
23436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return MCDisassembler::Fail;
23536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
23636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
23736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Calling the auto-generated decoder function.
23837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines  Result =
23937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines      decodeInstruction(DecoderTableSparc32, Instr, Insn, Address, this, STI);
24036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
24136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (Result != MCDisassembler::Fail) {
24236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    Size = 4;
24336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return Result;
24436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
24536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
24636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Fail;
24736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
24836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
24936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
25036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinestypedef DecodeStatus (*DecodeFunc)(MCInst &MI, unsigned insn, uint64_t Address,
25136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                   const void *Decoder);
25236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
25336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeMem(MCInst &MI, unsigned insn, uint64_t Address,
25436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                              const void *Decoder,
25536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                              bool isLoad, DecodeFunc DecodeRD) {
25636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned rd = fieldFromInstruction(insn, 25, 5);
25736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned rs1 = fieldFromInstruction(insn, 14, 5);
25836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  bool isImm = fieldFromInstruction(insn, 13, 1);
25936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned rs2 = 0;
26036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned simm13 = 0;
26136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (isImm)
26236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13));
26336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  else
26436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    rs2 = fieldFromInstruction(insn, 0, 5);
26536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
26636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  DecodeStatus status;
26736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (isLoad) {
26836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    status = DecodeRD(MI, rd, Address, Decoder);
26936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    if (status != MCDisassembler::Success)
27036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      return status;
27136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
27236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
27336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Decode rs1.
27436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
27536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (status != MCDisassembler::Success)
27636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return status;
27736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
27836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Decode imm|rs2.
27936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (isImm)
28036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MI.addOperand(MCOperand::CreateImm(simm13));
28136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  else {
28236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
28336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    if (status != MCDisassembler::Success)
28436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      return status;
28536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
28636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
28736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (!isLoad) {
28836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    status = DecodeRD(MI, rd, Address, Decoder);
28936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    if (status != MCDisassembler::Success)
29036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      return status;
29136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
29236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
29336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
29436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
29536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeLoadInt(MCInst &Inst, unsigned insn, uint64_t Address,
29636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                  const void *Decoder) {
29736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return DecodeMem(Inst, insn, Address, Decoder, true,
29836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                   DecodeIntRegsRegisterClass);
29936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
30036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
30136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeLoadFP(MCInst &Inst, unsigned insn, uint64_t Address,
30236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                 const void *Decoder) {
30336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return DecodeMem(Inst, insn, Address, Decoder, true,
30436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                   DecodeFPRegsRegisterClass);
30536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
30636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
30736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeLoadDFP(MCInst &Inst, unsigned insn, uint64_t Address,
30836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                  const void *Decoder) {
30936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return DecodeMem(Inst, insn, Address, Decoder, true,
31036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                   DecodeDFPRegsRegisterClass);
31136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
31236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
31336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeLoadQFP(MCInst &Inst, unsigned insn, uint64_t Address,
31436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                  const void *Decoder) {
31536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return DecodeMem(Inst, insn, Address, Decoder, true,
31636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                   DecodeQFPRegsRegisterClass);
31736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
31836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
31936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeStoreInt(MCInst &Inst, unsigned insn,
32036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                   uint64_t Address, const void *Decoder) {
32136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return DecodeMem(Inst, insn, Address, Decoder, false,
32236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                   DecodeIntRegsRegisterClass);
32336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
32436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
32536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeStoreFP(MCInst &Inst, unsigned insn, uint64_t Address,
32636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                  const void *Decoder) {
32736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return DecodeMem(Inst, insn, Address, Decoder, false,
32836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                   DecodeFPRegsRegisterClass);
32936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
33036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
33136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeStoreDFP(MCInst &Inst, unsigned insn,
33236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                   uint64_t Address, const void *Decoder) {
33336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return DecodeMem(Inst, insn, Address, Decoder, false,
33436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                   DecodeDFPRegsRegisterClass);
33536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
33636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
33736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeStoreQFP(MCInst &Inst, unsigned insn,
33836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                   uint64_t Address, const void *Decoder) {
33936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return DecodeMem(Inst, insn, Address, Decoder, false,
34036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                   DecodeQFPRegsRegisterClass);
34136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
34236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
34336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic bool tryAddingSymbolicOperand(int64_t Value,  bool isBranch,
34436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                     uint64_t Address, uint64_t Offset,
34536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                     uint64_t Width, MCInst &MI,
34636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                     const void *Decoder) {
34736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  const MCDisassembler *Dis = static_cast<const MCDisassembler*>(Decoder);
34836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return Dis->tryAddingSymbolicOperand(MI, Value, Address, isBranch,
34936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                       Offset, Width);
35036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
35136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
35236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeCall(MCInst &MI, unsigned insn,
35336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                               uint64_t Address, const void *Decoder) {
35436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned tgt = fieldFromInstruction(insn, 0, 30);
35536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  tgt <<= 2;
35636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (!tryAddingSymbolicOperand(tgt+Address, false, Address,
35736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                0, 30, MI, Decoder))
35836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MI.addOperand(MCOperand::CreateImm(tgt));
35936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
36036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
36136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
36236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeSIMM13(MCInst &MI, unsigned insn,
36336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                 uint64_t Address, const void *Decoder) {
36436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned tgt = SignExtend32<13>(fieldFromInstruction(insn, 0, 13));
36536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  MI.addOperand(MCOperand::CreateImm(tgt));
36636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
36736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
36836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
36936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeJMPL(MCInst &MI, unsigned insn, uint64_t Address,
37036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                               const void *Decoder) {
37136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
37236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned rd = fieldFromInstruction(insn, 25, 5);
37336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned rs1 = fieldFromInstruction(insn, 14, 5);
37436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned isImm = fieldFromInstruction(insn, 13, 1);
37536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned rs2 = 0;
37636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned simm13 = 0;
37736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (isImm)
37836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13));
37936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  else
38036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    rs2 = fieldFromInstruction(insn, 0, 5);
38136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
38236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Decode RD.
38336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  DecodeStatus status = DecodeIntRegsRegisterClass(MI, rd, Address, Decoder);
38436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (status != MCDisassembler::Success)
38536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return status;
38636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
38736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Decode RS1.
38836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
38936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (status != MCDisassembler::Success)
39036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return status;
39136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
39236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Decode RS1 | SIMM13.
39336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (isImm)
39436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MI.addOperand(MCOperand::CreateImm(simm13));
39536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  else {
39636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
39736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    if (status != MCDisassembler::Success)
39836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      return status;
39936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
40036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
40136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
40236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
40336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeReturn(MCInst &MI, unsigned insn, uint64_t Address,
40436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                                 const void *Decoder) {
40536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
40636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned rs1 = fieldFromInstruction(insn, 14, 5);
40736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned isImm = fieldFromInstruction(insn, 13, 1);
40836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned rs2 = 0;
40936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned simm13 = 0;
41036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (isImm)
41136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13));
41236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  else
41336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    rs2 = fieldFromInstruction(insn, 0, 5);
41436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
41536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Decode RS1.
41636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  DecodeStatus status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
41736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (status != MCDisassembler::Success)
41836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return status;
41936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
42036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Decode RS2 | SIMM13.
42136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (isImm)
42236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MI.addOperand(MCOperand::CreateImm(simm13));
42336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  else {
42436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
42536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    if (status != MCDisassembler::Success)
42636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      return status;
42736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
42836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
42936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
43036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
43136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hinesstatic DecodeStatus DecodeSWAP(MCInst &MI, unsigned insn, uint64_t Address,
43236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines                               const void *Decoder) {
43336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
43436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned rd = fieldFromInstruction(insn, 25, 5);
43536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned rs1 = fieldFromInstruction(insn, 14, 5);
43636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned isImm = fieldFromInstruction(insn, 13, 1);
43736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned rs2 = 0;
43836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  unsigned simm13 = 0;
43936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (isImm)
44036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    simm13 = SignExtend32<13>(fieldFromInstruction(insn, 0, 13));
44136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  else
44236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    rs2 = fieldFromInstruction(insn, 0, 5);
44336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
44436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Decode RD.
44536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  DecodeStatus status = DecodeIntRegsRegisterClass(MI, rd, Address, Decoder);
44636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (status != MCDisassembler::Success)
44736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return status;
44836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
44936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Decode RS1.
45036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);
45136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (status != MCDisassembler::Success)
45236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    return status;
45336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines
45436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  // Decode RS1 | SIMM13.
45536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  if (isImm)
45636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    MI.addOperand(MCOperand::CreateImm(simm13));
45736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  else {
45836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);
45936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines    if (status != MCDisassembler::Success)
46036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines      return status;
46136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  }
46236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines  return MCDisassembler::Success;
46336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines}
464