@@ -700,6 +700,26 @@ static DecodeStatus DecodeBlezGroupBranch(MCInst &MI, InsnType insn,
700
700
return MCDisassembler::Success;
701
701
}
702
702
703
+ // / Read two bytes from the ArrayRef and return 16 bit halfword sorted
704
+ // / according to the given endianess.
705
+ static DecodeStatus readInstruction16 (ArrayRef<uint8_t > Bytes, uint64_t Address,
706
+ uint64_t &Size , uint32_t &Insn,
707
+ bool IsBigEndian) {
708
+ // We want to read exactly 2 Bytes of data.
709
+ if (Bytes.size () < 2 ) {
710
+ Size = 0 ;
711
+ return MCDisassembler::Fail;
712
+ }
713
+
714
+ if (IsBigEndian) {
715
+ Insn = (Bytes[0 ] << 8 ) | Bytes[1 ];
716
+ } else {
717
+ Insn = (Bytes[1 ] << 8 ) | Bytes[0 ];
718
+ }
719
+
720
+ return MCDisassembler::Success;
721
+ }
722
+
703
723
// / Read four bytes from the ArrayRef and return 32 bit word sorted
704
724
// / according to the given endianess
705
725
static DecodeStatus readInstruction32 (ArrayRef<uint8_t > Bytes, uint64_t Address,
@@ -711,15 +731,19 @@ static DecodeStatus readInstruction32(ArrayRef<uint8_t> Bytes, uint64_t Address,
711
731
return MCDisassembler::Fail;
712
732
}
713
733
734
+ // High 16 bits of a 32-bit microMIPS instruction (where the opcode is)
735
+ // always precede the low 16 bits in the instruction stream (that is, they
736
+ // are placed at lower addresses in the instruction stream).
737
+ //
738
+ // microMIPS byte ordering:
739
+ // Big-endian: 0 | 1 | 2 | 3
740
+ // Little-endian: 1 | 0 | 3 | 2
741
+
714
742
if (IsBigEndian) {
715
743
// Encoded as a big-endian 32-bit word in the stream.
716
744
Insn =
717
745
(Bytes[3 ] << 0 ) | (Bytes[2 ] << 8 ) | (Bytes[1 ] << 16 ) | (Bytes[0 ] << 24 );
718
746
} else {
719
- // Encoded as a small-endian 32-bit word in the stream.
720
- // Little-endian byte ordering:
721
- // mips32r2: 4 | 3 | 2 | 1
722
- // microMIPS: 2 | 1 | 4 | 3
723
747
if (IsMicroMips) {
724
748
Insn = (Bytes[2 ] << 0 ) | (Bytes[3 ] << 8 ) | (Bytes[0 ] << 16 ) |
725
749
(Bytes[1 ] << 24 );
@@ -738,14 +762,25 @@ DecodeStatus MipsDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
738
762
raw_ostream &VStream,
739
763
raw_ostream &CStream) const {
740
764
uint32_t Insn;
741
-
742
- DecodeStatus Result =
743
- readInstruction32 (Bytes, Address, Size , Insn, IsBigEndian, IsMicroMips);
744
- if (Result == MCDisassembler::Fail)
745
- return MCDisassembler::Fail;
765
+ DecodeStatus Result;
746
766
747
767
if (IsMicroMips) {
748
- DEBUG (dbgs () << " Trying MicroMips32 table (32-bit opcodes):\n " );
768
+ Result = readInstruction16 (Bytes, Address, Size , Insn, IsBigEndian);
769
+
770
+ DEBUG (dbgs () << " Trying MicroMips16 table (16-bit instructions):\n " );
771
+ // Calling the auto-generated decoder function.
772
+ Result = decodeInstruction (DecoderTableMicroMips16, Instr, Insn, Address,
773
+ this , STI);
774
+ if (Result != MCDisassembler::Fail) {
775
+ Size = 2 ;
776
+ return Result;
777
+ }
778
+
779
+ Result = readInstruction32 (Bytes, Address, Size , Insn, IsBigEndian, true );
780
+ if (Result == MCDisassembler::Fail)
781
+ return MCDisassembler::Fail;
782
+
783
+ DEBUG (dbgs () << " Trying MicroMips32 table (32-bit instructions):\n " );
749
784
// Calling the auto-generated decoder function.
750
785
Result = decodeInstruction (DecoderTableMicroMips32, Instr, Insn, Address,
751
786
this , STI);
@@ -756,6 +791,10 @@ DecodeStatus MipsDisassembler::getInstruction(MCInst &Instr, uint64_t &Size,
756
791
return MCDisassembler::Fail;
757
792
}
758
793
794
+ Result = readInstruction32 (Bytes, Address, Size , Insn, IsBigEndian, false );
795
+ if (Result == MCDisassembler::Fail)
796
+ return MCDisassembler::Fail;
797
+
759
798
if (hasCOP3 ()) {
760
799
DEBUG (dbgs () << " Trying COP3_ table (32-bit opcodes):\n " );
761
800
Result =
@@ -854,7 +893,11 @@ static DecodeStatus DecodeGPRMM16RegisterClass(MCInst &Inst,
854
893
unsigned RegNo,
855
894
uint64_t Address,
856
895
const void *Decoder) {
857
- return MCDisassembler::Fail;
896
+ if (RegNo > 7 )
897
+ return MCDisassembler::Fail;
898
+ unsigned Reg = getReg (Decoder, Mips::GPRMM16RegClassID, RegNo);
899
+ Inst.addOperand (MCOperand::CreateReg (Reg));
900
+ return MCDisassembler::Success;
858
901
}
859
902
860
903
static DecodeStatus DecodeGPR32RegisterClass (MCInst &Inst,
0 commit comments