]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.cpp
Upgrade our copy of llvm/clang to r130700, from upstream's trunk.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / MBlaze / Disassembler / MBlazeDisassembler.cpp
1 //===- MBlazeDisassembler.cpp - Disassembler for MicroBlaze  ----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file is part of the MBlaze Disassembler. It contains code to translate
11 // the data produced by the decoder into MCInsts.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "MBlaze.h"
16 #include "MBlazeInstrInfo.h"
17 #include "MBlazeDisassembler.h"
18
19 #include "llvm/MC/EDInstInfo.h"
20 #include "llvm/MC/MCDisassembler.h"
21 #include "llvm/MC/MCDisassembler.h"
22 #include "llvm/MC/MCInst.h"
23 #include "llvm/Target/TargetRegistry.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/MemoryObject.h"
26 #include "llvm/Support/raw_ostream.h"
27
28 // #include "MBlazeGenDecoderTables.inc"
29 // #include "MBlazeGenRegisterNames.inc"
30 #include "MBlazeGenInstrInfo.inc"
31 #include "MBlazeGenEDInfo.inc"
32
33 using namespace llvm;
34
35 const unsigned UNSUPPORTED = -1;
36
37 static unsigned mblazeBinary2Opcode[] = {
38   MBlaze::ADD,   MBlaze::RSUB,   MBlaze::ADDC,   MBlaze::RSUBC,   //00,01,02,03
39   MBlaze::ADDK,  MBlaze::RSUBK,  MBlaze::ADDKC,  MBlaze::RSUBKC,  //04,05,06,07
40   MBlaze::ADDI,  MBlaze::RSUBI,  MBlaze::ADDIC,  MBlaze::RSUBIC,  //08,09,0A,0B
41   MBlaze::ADDIK, MBlaze::RSUBIK, MBlaze::ADDIKC, MBlaze::RSUBIKC, //0C,0D,0E,0F
42
43   MBlaze::MUL,   MBlaze::BSRL,   MBlaze::IDIV,   MBlaze::GETD,    //10,11,12,13
44   UNSUPPORTED,   UNSUPPORTED,    MBlaze::FADD,   UNSUPPORTED,     //14,15,16,17
45   MBlaze::MULI,  MBlaze::BSRLI,  UNSUPPORTED,    MBlaze::GET,     //18,19,1A,1B
46   UNSUPPORTED,   UNSUPPORTED,    UNSUPPORTED,    UNSUPPORTED,     //1C,1D,1E,1F
47
48   MBlaze::OR,    MBlaze::AND,    MBlaze::XOR,    MBlaze::ANDN,    //20,21,22,23
49   MBlaze::SEXT8, MBlaze::MFS,    MBlaze::BR,     MBlaze::BEQ,     //24,25,26,27
50   MBlaze::ORI,   MBlaze::ANDI,   MBlaze::XORI,   MBlaze::ANDNI,   //28,29,2A,2B
51   MBlaze::IMM,   MBlaze::RTSD,   MBlaze::BRI,    MBlaze::BEQI,    //2C,2D,2E,2F
52
53   MBlaze::LBU,   MBlaze::LHU,    MBlaze::LW,     UNSUPPORTED,     //30,31,32,33
54   MBlaze::SB,    MBlaze::SH,     MBlaze::SW,     UNSUPPORTED,     //34,35,36,37
55   MBlaze::LBUI,  MBlaze::LHUI,   MBlaze::LWI,    UNSUPPORTED,     //38,39,3A,3B
56   MBlaze::SBI,   MBlaze::SHI,    MBlaze::SWI,    UNSUPPORTED,     //3C,3D,3E,3F
57 };
58
59 static unsigned getRD(uint32_t insn) {
60   if (!MBlazeRegisterInfo::isRegister((insn>>21)&0x1F))
61     return UNSUPPORTED;
62   return MBlazeRegisterInfo::getRegisterFromNumbering((insn>>21)&0x1F);
63 }
64
65 static unsigned getRA(uint32_t insn) {
66   if (!MBlazeRegisterInfo::getRegisterFromNumbering((insn>>16)&0x1F))
67     return UNSUPPORTED;
68   return MBlazeRegisterInfo::getRegisterFromNumbering((insn>>16)&0x1F);
69 }
70
71 static unsigned getRB(uint32_t insn) {
72   if (!MBlazeRegisterInfo::getRegisterFromNumbering((insn>>11)&0x1F))
73     return UNSUPPORTED;
74   return MBlazeRegisterInfo::getRegisterFromNumbering((insn>>11)&0x1F);
75 }
76
77 static int64_t getRS(uint32_t insn) {
78   if (!MBlazeRegisterInfo::isSpecialRegister(insn&0x3FFF))
79     return UNSUPPORTED;
80   return MBlazeRegisterInfo::getSpecialRegisterFromNumbering(insn&0x3FFF);
81 }
82
83 static int64_t getIMM(uint32_t insn) {
84     int16_t val = (insn & 0xFFFF);
85     return val;
86 }
87
88 static int64_t getSHT(uint32_t insn) {
89     int16_t val = (insn & 0x1F);
90     return val;
91 }
92
93 static unsigned getFLAGS(int32_t insn) {
94     return (insn & 0x7FF);
95 }
96
97 static int64_t getFSL(uint32_t insn) {
98     int16_t val = (insn & 0xF);
99     return val;
100 }
101
102 static unsigned decodeMUL(uint32_t insn) {
103     switch (getFLAGS(insn)) {
104     default: return UNSUPPORTED;
105     case 0:  return MBlaze::MUL;
106     case 1:  return MBlaze::MULH;
107     case 2:  return MBlaze::MULHSU;
108     case 3:  return MBlaze::MULHU;
109     }
110 }
111
112 static unsigned decodeSEXT(uint32_t insn) {
113     switch (insn&0x7FF) {
114     default:   return UNSUPPORTED;
115     case 0x60: return MBlaze::SEXT8;
116     case 0x68: return MBlaze::WIC;
117     case 0x64: return MBlaze::WDC;
118     case 0x66: return MBlaze::WDCC;
119     case 0x74: return MBlaze::WDCF;
120     case 0x61: return MBlaze::SEXT16;
121     case 0x41: return MBlaze::SRL;
122     case 0x21: return MBlaze::SRC;
123     case 0x01: return MBlaze::SRA;
124     }
125 }
126
127 static unsigned decodeBEQ(uint32_t insn) {
128     switch ((insn>>21)&0x1F) {
129     default:    return UNSUPPORTED;
130     case 0x00:  return MBlaze::BEQ;
131     case 0x10:  return MBlaze::BEQD;
132     case 0x05:  return MBlaze::BGE;
133     case 0x15:  return MBlaze::BGED;
134     case 0x04:  return MBlaze::BGT;
135     case 0x14:  return MBlaze::BGTD;
136     case 0x03:  return MBlaze::BLE;
137     case 0x13:  return MBlaze::BLED;
138     case 0x02:  return MBlaze::BLT;
139     case 0x12:  return MBlaze::BLTD;
140     case 0x01:  return MBlaze::BNE;
141     case 0x11:  return MBlaze::BNED;
142     }
143 }
144
145 static unsigned decodeBEQI(uint32_t insn) {
146     switch ((insn>>21)&0x1F) {
147     default:    return UNSUPPORTED;
148     case 0x00:  return MBlaze::BEQI;
149     case 0x10:  return MBlaze::BEQID;
150     case 0x05:  return MBlaze::BGEI;
151     case 0x15:  return MBlaze::BGEID;
152     case 0x04:  return MBlaze::BGTI;
153     case 0x14:  return MBlaze::BGTID;
154     case 0x03:  return MBlaze::BLEI;
155     case 0x13:  return MBlaze::BLEID;
156     case 0x02:  return MBlaze::BLTI;
157     case 0x12:  return MBlaze::BLTID;
158     case 0x01:  return MBlaze::BNEI;
159     case 0x11:  return MBlaze::BNEID;
160     }
161 }
162
163 static unsigned decodeBR(uint32_t insn) {
164     switch ((insn>>16)&0x1F) {
165     default:   return UNSUPPORTED;
166     case 0x00: return MBlaze::BR;
167     case 0x08: return MBlaze::BRA;
168     case 0x0C: return MBlaze::BRK;
169     case 0x10: return MBlaze::BRD;
170     case 0x14: return MBlaze::BRLD;
171     case 0x18: return MBlaze::BRAD;
172     case 0x1C: return MBlaze::BRALD;
173     }
174 }
175
176 static unsigned decodeBRI(uint32_t insn) {
177     switch ((insn>>16)&0x1F) {
178     default:   return UNSUPPORTED;
179     case 0x00: return MBlaze::BRI;
180     case 0x08: return MBlaze::BRAI;
181     case 0x0C: return MBlaze::BRKI;
182     case 0x10: return MBlaze::BRID;
183     case 0x14: return MBlaze::BRLID;
184     case 0x18: return MBlaze::BRAID;
185     case 0x1C: return MBlaze::BRALID;
186     }
187 }
188
189 static unsigned decodeBSRL(uint32_t insn) {
190     switch ((insn>>9)&0x3) {
191     default:  return UNSUPPORTED;
192     case 0x2: return MBlaze::BSLL;
193     case 0x1: return MBlaze::BSRA;
194     case 0x0: return MBlaze::BSRL;
195     }
196 }
197
198 static unsigned decodeBSRLI(uint32_t insn) {
199     switch ((insn>>9)&0x3) {
200     default:  return UNSUPPORTED;
201     case 0x2: return MBlaze::BSLLI;
202     case 0x1: return MBlaze::BSRAI;
203     case 0x0: return MBlaze::BSRLI;
204     }
205 }
206
207 static unsigned decodeRSUBK(uint32_t insn) {
208     switch (getFLAGS(insn)) {
209     default:  return UNSUPPORTED;
210     case 0x0: return MBlaze::RSUBK;
211     case 0x1: return MBlaze::CMP;
212     case 0x3: return MBlaze::CMPU;
213     }
214 }
215
216 static unsigned decodeFADD(uint32_t insn) {
217     switch (getFLAGS(insn)) {
218     default:    return UNSUPPORTED;
219     case 0x000: return MBlaze::FADD;
220     case 0x080: return MBlaze::FRSUB;
221     case 0x100: return MBlaze::FMUL;
222     case 0x180: return MBlaze::FDIV;
223     case 0x200: return MBlaze::FCMP_UN;
224     case 0x210: return MBlaze::FCMP_LT;
225     case 0x220: return MBlaze::FCMP_EQ;
226     case 0x230: return MBlaze::FCMP_LE;
227     case 0x240: return MBlaze::FCMP_GT;
228     case 0x250: return MBlaze::FCMP_NE;
229     case 0x260: return MBlaze::FCMP_GE;
230     case 0x280: return MBlaze::FLT;
231     case 0x300: return MBlaze::FINT;
232     case 0x380: return MBlaze::FSQRT;
233     }
234 }
235
236 static unsigned decodeGET(uint32_t insn) {
237     switch ((insn>>10)&0x3F) {
238     default:   return UNSUPPORTED;
239     case 0x00: return MBlaze::GET;
240     case 0x01: return MBlaze::EGET;
241     case 0x02: return MBlaze::AGET;
242     case 0x03: return MBlaze::EAGET;
243     case 0x04: return MBlaze::TGET;
244     case 0x05: return MBlaze::TEGET;
245     case 0x06: return MBlaze::TAGET;
246     case 0x07: return MBlaze::TEAGET;
247     case 0x08: return MBlaze::CGET;
248     case 0x09: return MBlaze::ECGET;
249     case 0x0A: return MBlaze::CAGET;
250     case 0x0B: return MBlaze::ECAGET;
251     case 0x0C: return MBlaze::TCGET;
252     case 0x0D: return MBlaze::TECGET;
253     case 0x0E: return MBlaze::TCAGET;
254     case 0x0F: return MBlaze::TECAGET;
255     case 0x10: return MBlaze::NGET;
256     case 0x11: return MBlaze::NEGET;
257     case 0x12: return MBlaze::NAGET;
258     case 0x13: return MBlaze::NEAGET;
259     case 0x14: return MBlaze::TNGET;
260     case 0x15: return MBlaze::TNEGET;
261     case 0x16: return MBlaze::TNAGET;
262     case 0x17: return MBlaze::TNEAGET;
263     case 0x18: return MBlaze::NCGET;
264     case 0x19: return MBlaze::NECGET;
265     case 0x1A: return MBlaze::NCAGET;
266     case 0x1B: return MBlaze::NECAGET;
267     case 0x1C: return MBlaze::TNCGET;
268     case 0x1D: return MBlaze::TNECGET;
269     case 0x1E: return MBlaze::TNCAGET;
270     case 0x1F: return MBlaze::TNECAGET;
271     case 0x20: return MBlaze::PUT;
272     case 0x22: return MBlaze::APUT;
273     case 0x24: return MBlaze::TPUT;
274     case 0x26: return MBlaze::TAPUT;
275     case 0x28: return MBlaze::CPUT;
276     case 0x2A: return MBlaze::CAPUT;
277     case 0x2C: return MBlaze::TCPUT;
278     case 0x2E: return MBlaze::TCAPUT;
279     case 0x30: return MBlaze::NPUT;
280     case 0x32: return MBlaze::NAPUT;
281     case 0x34: return MBlaze::TNPUT;
282     case 0x36: return MBlaze::TNAPUT;
283     case 0x38: return MBlaze::NCPUT;
284     case 0x3A: return MBlaze::NCAPUT;
285     case 0x3C: return MBlaze::TNCPUT;
286     case 0x3E: return MBlaze::TNCAPUT;
287     }
288 }
289
290 static unsigned decodeGETD(uint32_t insn) {
291     switch ((insn>>5)&0x3F) {
292     default:   return UNSUPPORTED;
293     case 0x00: return MBlaze::GETD;
294     case 0x01: return MBlaze::EGETD;
295     case 0x02: return MBlaze::AGETD;
296     case 0x03: return MBlaze::EAGETD;
297     case 0x04: return MBlaze::TGETD;
298     case 0x05: return MBlaze::TEGETD;
299     case 0x06: return MBlaze::TAGETD;
300     case 0x07: return MBlaze::TEAGETD;
301     case 0x08: return MBlaze::CGETD;
302     case 0x09: return MBlaze::ECGETD;
303     case 0x0A: return MBlaze::CAGETD;
304     case 0x0B: return MBlaze::ECAGETD;
305     case 0x0C: return MBlaze::TCGETD;
306     case 0x0D: return MBlaze::TECGETD;
307     case 0x0E: return MBlaze::TCAGETD;
308     case 0x0F: return MBlaze::TECAGETD;
309     case 0x10: return MBlaze::NGETD;
310     case 0x11: return MBlaze::NEGETD;
311     case 0x12: return MBlaze::NAGETD;
312     case 0x13: return MBlaze::NEAGETD;
313     case 0x14: return MBlaze::TNGETD;
314     case 0x15: return MBlaze::TNEGETD;
315     case 0x16: return MBlaze::TNAGETD;
316     case 0x17: return MBlaze::TNEAGETD;
317     case 0x18: return MBlaze::NCGETD;
318     case 0x19: return MBlaze::NECGETD;
319     case 0x1A: return MBlaze::NCAGETD;
320     case 0x1B: return MBlaze::NECAGETD;
321     case 0x1C: return MBlaze::TNCGETD;
322     case 0x1D: return MBlaze::TNECGETD;
323     case 0x1E: return MBlaze::TNCAGETD;
324     case 0x1F: return MBlaze::TNECAGETD;
325     case 0x20: return MBlaze::PUTD;
326     case 0x22: return MBlaze::APUTD;
327     case 0x24: return MBlaze::TPUTD;
328     case 0x26: return MBlaze::TAPUTD;
329     case 0x28: return MBlaze::CPUTD;
330     case 0x2A: return MBlaze::CAPUTD;
331     case 0x2C: return MBlaze::TCPUTD;
332     case 0x2E: return MBlaze::TCAPUTD;
333     case 0x30: return MBlaze::NPUTD;
334     case 0x32: return MBlaze::NAPUTD;
335     case 0x34: return MBlaze::TNPUTD;
336     case 0x36: return MBlaze::TNAPUTD;
337     case 0x38: return MBlaze::NCPUTD;
338     case 0x3A: return MBlaze::NCAPUTD;
339     case 0x3C: return MBlaze::TNCPUTD;
340     case 0x3E: return MBlaze::TNCAPUTD;
341     }
342 }
343
344 static unsigned decodeIDIV(uint32_t insn) {
345     switch (insn&0x3) {
346     default:  return UNSUPPORTED;
347     case 0x0: return MBlaze::IDIV;
348     case 0x2: return MBlaze::IDIVU;
349     }
350 }
351
352 static unsigned decodeLBU(uint32_t insn) {
353     switch ((insn>>9)&0x1) {
354     default:  return UNSUPPORTED;
355     case 0x0: return MBlaze::LBU;
356     case 0x1: return MBlaze::LBUR;
357     }
358 }
359
360 static unsigned decodeLHU(uint32_t insn) {
361     switch ((insn>>9)&0x1) {
362     default:  return UNSUPPORTED;
363     case 0x0: return MBlaze::LHU;
364     case 0x1: return MBlaze::LHUR;
365     }
366 }
367
368 static unsigned decodeLW(uint32_t insn) {
369     switch ((insn>>9)&0x3) {
370     default:  return UNSUPPORTED;
371     case 0x0: return MBlaze::LW;
372     case 0x1: return MBlaze::LWR;
373     case 0x2: return MBlaze::LWX;
374     }
375 }
376
377 static unsigned decodeSB(uint32_t insn) {
378     switch ((insn>>9)&0x1) {
379     default:  return UNSUPPORTED;
380     case 0x0: return MBlaze::SB;
381     case 0x1: return MBlaze::SBR;
382     }
383 }
384
385 static unsigned decodeSH(uint32_t insn) {
386     switch ((insn>>9)&0x1) {
387     default:  return UNSUPPORTED;
388     case 0x0: return MBlaze::SH;
389     case 0x1: return MBlaze::SHR;
390     }
391 }
392
393 static unsigned decodeSW(uint32_t insn) {
394     switch ((insn>>9)&0x3) {
395     default:  return UNSUPPORTED;
396     case 0x0: return MBlaze::SW;
397     case 0x1: return MBlaze::SWR;
398     case 0x2: return MBlaze::SWX;
399     }
400 }
401
402 static unsigned decodeMFS(uint32_t insn) {
403     switch ((insn>>15)&0x1) {
404     default:   return UNSUPPORTED;
405     case 0x0:
406       switch ((insn>>16)&0x1) {
407       default:   return UNSUPPORTED;
408       case 0x0: return MBlaze::MSRSET;
409       case 0x1: return MBlaze::MSRCLR;
410       }
411     case 0x1:
412       switch ((insn>>14)&0x1) {
413       default:   return UNSUPPORTED;
414       case 0x0: return MBlaze::MFS;
415       case 0x1: return MBlaze::MTS;
416       }
417     }
418 }
419
420 static unsigned decodeOR(uint32_t insn) {
421     switch (getFLAGS(insn)) {
422     default:    return UNSUPPORTED;
423     case 0x000: return MBlaze::OR;
424     case 0x400: return MBlaze::PCMPBF;
425     }
426 }
427
428 static unsigned decodeXOR(uint32_t insn) {
429     switch (getFLAGS(insn)) {
430     default:    return UNSUPPORTED;
431     case 0x000: return MBlaze::XOR;
432     case 0x400: return MBlaze::PCMPEQ;
433     }
434 }
435
436 static unsigned decodeANDN(uint32_t insn) {
437     switch (getFLAGS(insn)) {
438     default:    return UNSUPPORTED;
439     case 0x000: return MBlaze::ANDN;
440     case 0x400: return MBlaze::PCMPNE;
441     }
442 }
443
444 static unsigned decodeRTSD(uint32_t insn) {
445     switch ((insn>>21)&0x1F) {
446     default:   return UNSUPPORTED;
447     case 0x10: return MBlaze::RTSD;
448     case 0x11: return MBlaze::RTID;
449     case 0x12: return MBlaze::RTBD;
450     case 0x14: return MBlaze::RTED;
451     }
452 }
453
454 static unsigned getOPCODE(uint32_t insn) {
455   unsigned opcode = mblazeBinary2Opcode[ (insn>>26)&0x3F ];
456   switch (opcode) {
457   case MBlaze::MUL:     return decodeMUL(insn);
458   case MBlaze::SEXT8:   return decodeSEXT(insn);
459   case MBlaze::BEQ:     return decodeBEQ(insn);
460   case MBlaze::BEQI:    return decodeBEQI(insn);
461   case MBlaze::BR:      return decodeBR(insn);
462   case MBlaze::BRI:     return decodeBRI(insn);
463   case MBlaze::BSRL:    return decodeBSRL(insn);
464   case MBlaze::BSRLI:   return decodeBSRLI(insn);
465   case MBlaze::RSUBK:   return decodeRSUBK(insn);
466   case MBlaze::FADD:    return decodeFADD(insn);
467   case MBlaze::GET:     return decodeGET(insn);
468   case MBlaze::GETD:    return decodeGETD(insn);
469   case MBlaze::IDIV:    return decodeIDIV(insn);
470   case MBlaze::LBU:     return decodeLBU(insn);
471   case MBlaze::LHU:     return decodeLHU(insn);
472   case MBlaze::LW:      return decodeLW(insn);
473   case MBlaze::SB:      return decodeSB(insn);
474   case MBlaze::SH:      return decodeSH(insn);
475   case MBlaze::SW:      return decodeSW(insn);
476   case MBlaze::MFS:     return decodeMFS(insn);
477   case MBlaze::OR:      return decodeOR(insn);
478   case MBlaze::XOR:     return decodeXOR(insn);
479   case MBlaze::ANDN:    return decodeANDN(insn);
480   case MBlaze::RTSD:    return decodeRTSD(insn);
481   default:              return opcode;
482   }
483 }
484
485 EDInstInfo *MBlazeDisassembler::getEDInfo() const {
486   return instInfoMBlaze;
487 }
488
489 //
490 // Public interface for the disassembler
491 //
492
493 bool MBlazeDisassembler::getInstruction(MCInst &instr,
494                                         uint64_t &size,
495                                         const MemoryObject &region,
496                                         uint64_t address,
497                                         raw_ostream &vStream) const {
498   // The machine instruction.
499   uint32_t insn;
500   uint64_t read;
501   uint8_t bytes[4];
502
503   // By default we consume 1 byte on failure
504   size = 1;
505
506   // We want to read exactly 4 bytes of data.
507   if (region.readBytes(address, 4, (uint8_t*)bytes, &read) == -1 || read < 4)
508     return false;
509
510   // Encoded as a big-endian 32-bit word in the stream.
511   insn = (bytes[0]<<24) | (bytes[1]<<16) | (bytes[2]<< 8) | (bytes[3]<<0);
512
513   // Get the MCInst opcode from the binary instruction and make sure
514   // that it is a valid instruction.
515   unsigned opcode = getOPCODE(insn);
516   if (opcode == UNSUPPORTED)
517     return false;
518
519   instr.setOpcode(opcode);
520
521   unsigned RD = getRD(insn);
522   unsigned RA = getRA(insn);
523   unsigned RB = getRB(insn);
524   unsigned RS = getRS(insn);
525
526   uint64_t tsFlags = MBlazeInsts[opcode].TSFlags;
527   switch ((tsFlags & MBlazeII::FormMask)) {
528   default: 
529     return false;
530
531   case MBlazeII::FRRRR:
532     if (RD == UNSUPPORTED || RA == UNSUPPORTED || RB == UNSUPPORTED)
533       return false;
534     instr.addOperand(MCOperand::CreateReg(RD));
535     instr.addOperand(MCOperand::CreateReg(RB));
536     instr.addOperand(MCOperand::CreateReg(RA));
537     break;
538
539   case MBlazeII::FRRR:
540     if (RD == UNSUPPORTED || RA == UNSUPPORTED || RB == UNSUPPORTED)
541       return false;
542     instr.addOperand(MCOperand::CreateReg(RD));
543     instr.addOperand(MCOperand::CreateReg(RA));
544     instr.addOperand(MCOperand::CreateReg(RB));
545     break;
546
547   case MBlazeII::FRI:
548     switch (opcode) {
549     default: 
550       return false;
551     case MBlaze::MFS:
552       if (RD == UNSUPPORTED)
553         return false;
554       instr.addOperand(MCOperand::CreateReg(RD));
555       instr.addOperand(MCOperand::CreateImm(insn&0x3FFF));
556       break;
557     case MBlaze::MTS:
558       if (RA == UNSUPPORTED)
559         return false;
560       instr.addOperand(MCOperand::CreateImm(insn&0x3FFF));
561       instr.addOperand(MCOperand::CreateReg(RA));
562       break;
563     case MBlaze::MSRSET:
564     case MBlaze::MSRCLR:
565       if (RD == UNSUPPORTED)
566         return false;
567       instr.addOperand(MCOperand::CreateReg(RD));
568       instr.addOperand(MCOperand::CreateImm(insn&0x7FFF));
569       break;
570     }
571     break;
572
573   case MBlazeII::FRRI:
574     if (RD == UNSUPPORTED || RA == UNSUPPORTED)
575       return false;
576     instr.addOperand(MCOperand::CreateReg(RD));
577     instr.addOperand(MCOperand::CreateReg(RA));
578     switch (opcode) {
579     default:
580       instr.addOperand(MCOperand::CreateImm(getIMM(insn)));
581       break;
582     case MBlaze::BSRLI:
583     case MBlaze::BSRAI:
584     case MBlaze::BSLLI:
585       instr.addOperand(MCOperand::CreateImm(insn&0x1F));
586       break;
587     }
588     break;
589
590   case MBlazeII::FCRR:
591     if (RA == UNSUPPORTED || RB == UNSUPPORTED)
592       return false;
593     instr.addOperand(MCOperand::CreateReg(RA));
594     instr.addOperand(MCOperand::CreateReg(RB));
595     break;
596
597   case MBlazeII::FCRI:
598     if (RA == UNSUPPORTED)
599       return false;
600     instr.addOperand(MCOperand::CreateReg(RA));
601     instr.addOperand(MCOperand::CreateImm(getIMM(insn)));
602     break;
603
604   case MBlazeII::FRCR:
605     if (RD == UNSUPPORTED || RB == UNSUPPORTED)
606       return false;
607     instr.addOperand(MCOperand::CreateReg(RD));
608     instr.addOperand(MCOperand::CreateReg(RB));
609     break;
610
611   case MBlazeII::FRCI:
612     if (RD == UNSUPPORTED)
613       return false;
614     instr.addOperand(MCOperand::CreateReg(RD));
615     instr.addOperand(MCOperand::CreateImm(getIMM(insn)));
616     break;
617
618   case MBlazeII::FCCR:
619     if (RB == UNSUPPORTED)
620       return false;
621     instr.addOperand(MCOperand::CreateReg(RB));
622     break;
623
624   case MBlazeII::FCCI:
625     instr.addOperand(MCOperand::CreateImm(getIMM(insn)));
626     break;
627
628   case MBlazeII::FRRCI:
629     if (RD == UNSUPPORTED || RA == UNSUPPORTED)
630       return false;
631     instr.addOperand(MCOperand::CreateReg(RD));
632     instr.addOperand(MCOperand::CreateReg(RA));
633     instr.addOperand(MCOperand::CreateImm(getSHT(insn)));
634     break;
635
636   case MBlazeII::FRRC:
637     if (RD == UNSUPPORTED || RA == UNSUPPORTED)
638       return false;
639     instr.addOperand(MCOperand::CreateReg(RD));
640     instr.addOperand(MCOperand::CreateReg(RA));
641     break;
642
643   case MBlazeII::FRCX:
644     if (RD == UNSUPPORTED)
645       return false;
646     instr.addOperand(MCOperand::CreateReg(RD));
647     instr.addOperand(MCOperand::CreateImm(getFSL(insn)));
648     break;
649
650   case MBlazeII::FRCS:
651     if (RD == UNSUPPORTED || RS == UNSUPPORTED)
652       return false;
653     instr.addOperand(MCOperand::CreateReg(RD));
654     instr.addOperand(MCOperand::CreateReg(RS));
655     break;
656
657   case MBlazeII::FCRCS:
658     if (RS == UNSUPPORTED || RA == UNSUPPORTED)
659       return false;
660     instr.addOperand(MCOperand::CreateReg(RS));
661     instr.addOperand(MCOperand::CreateReg(RA));
662     break;
663
664   case MBlazeII::FCRCX:
665     if (RA == UNSUPPORTED)
666       return false;
667     instr.addOperand(MCOperand::CreateReg(RA));
668     instr.addOperand(MCOperand::CreateImm(getFSL(insn)));
669     break;
670
671   case MBlazeII::FCX:
672     instr.addOperand(MCOperand::CreateImm(getFSL(insn)));
673     break;
674
675   case MBlazeII::FCR:
676     if (RB == UNSUPPORTED)
677       return false;
678     instr.addOperand(MCOperand::CreateReg(RB));
679     break;
680
681   case MBlazeII::FRIR:
682     if (RD == UNSUPPORTED || RA == UNSUPPORTED)
683       return false;
684     instr.addOperand(MCOperand::CreateReg(RD));
685     instr.addOperand(MCOperand::CreateImm(getIMM(insn)));
686     instr.addOperand(MCOperand::CreateReg(RA));
687     break;
688   }
689
690   // We always consume 4 bytes of data on success
691   size = 4;
692
693   return true;
694 }
695
696 static MCDisassembler *createMBlazeDisassembler(const Target &T) {
697   return new MBlazeDisassembler;
698 }
699
700 extern "C" void LLVMInitializeMBlazeDisassembler() {
701   // Register the disassembler.
702   TargetRegistry::RegisterMCDisassembler(TheMBlazeTarget,
703                                          createMBlazeDisassembler);
704 }