/src/capstonev5/arch/Sparc/SparcDisassembler.c
Line  | Count  | Source  | 
1  |  | //===------ SparcDisassembler.cpp - Disassembler for PowerPC ------*- 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  |  | /* Capstone Disassembly Engine */  | 
11  |  | /* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2015 */  | 
12  |  |  | 
13  |  | #ifdef CAPSTONE_HAS_SPARC  | 
14  |  |  | 
15  |  | #include <stdio.h>  // DEBUG  | 
16  |  | #include <stdlib.h>  | 
17  |  | #include <string.h>  | 
18  |  |  | 
19  |  | #include "../../cs_priv.h"  | 
20  |  | #include "../../utils.h"  | 
21  |  |  | 
22  |  | #include "SparcDisassembler.h"  | 
23  |  |  | 
24  |  | #include "../../MCInst.h"  | 
25  |  | #include "../../MCInstrDesc.h"  | 
26  |  | #include "../../MCFixedLenDisassembler.h"  | 
27  |  | #include "../../MCRegisterInfo.h"  | 
28  |  | #include "../../MCDisassembler.h"  | 
29  |  | #include "../../MathExtras.h"  | 
30  |  |  | 
31  |  |  | 
32  |  | #define GET_REGINFO_MC_DESC  | 
33  |  | #define GET_REGINFO_ENUM  | 
34  |  | #include "SparcGenRegisterInfo.inc"  | 
35  |  | static const unsigned IntRegDecoderTable[] = { | 
36  |  |   SP_G0,  SP_G1,  SP_G2,  SP_G3,  | 
37  |  |   SP_G4,  SP_G5,  SP_G6,  SP_G7,  | 
38  |  |   SP_O0,  SP_O1,  SP_O2,  SP_O3,  | 
39  |  |   SP_O4,  SP_O5,  SP_O6,  SP_O7,  | 
40  |  |   SP_L0,  SP_L1,  SP_L2,  SP_L3,  | 
41  |  |   SP_L4,  SP_L5,  SP_L6,  SP_L7,  | 
42  |  |   SP_I0,  SP_I1,  SP_I2,  SP_I3,  | 
43  |  |   SP_I4,  SP_I5,  SP_I6,  SP_I7  | 
44  |  | };  | 
45  |  |  | 
46  |  | static const unsigned FPRegDecoderTable[] = { | 
47  |  |   SP_F0,   SP_F1,   SP_F2,   SP_F3,  | 
48  |  |   SP_F4,   SP_F5,   SP_F6,   SP_F7,  | 
49  |  |   SP_F8,   SP_F9,   SP_F10,  SP_F11,  | 
50  |  |   SP_F12,  SP_F13,  SP_F14,  SP_F15,  | 
51  |  |   SP_F16,  SP_F17,  SP_F18,  SP_F19,  | 
52  |  |   SP_F20,  SP_F21,  SP_F22,  SP_F23,  | 
53  |  |   SP_F24,  SP_F25,  SP_F26,  SP_F27,  | 
54  |  |   SP_F28,  SP_F29,  SP_F30,  SP_F31  | 
55  |  | };  | 
56  |  |  | 
57  |  | static const unsigned DFPRegDecoderTable[] = { | 
58  |  |   SP_D0,   SP_D16,  SP_D1,   SP_D17,  | 
59  |  |   SP_D2,   SP_D18,  SP_D3,   SP_D19,  | 
60  |  |   SP_D4,   SP_D20,  SP_D5,   SP_D21,  | 
61  |  |   SP_D6,   SP_D22,  SP_D7,   SP_D23,  | 
62  |  |   SP_D8,   SP_D24,  SP_D9,   SP_D25,  | 
63  |  |   SP_D10,  SP_D26,  SP_D11,  SP_D27,  | 
64  |  |   SP_D12,  SP_D28,  SP_D13,  SP_D29,  | 
65  |  |   SP_D14,  SP_D30,  SP_D15,  SP_D31  | 
66  |  | };  | 
67  |  |  | 
68  |  | static const unsigned QFPRegDecoderTable[] = { | 
69  |  |   SP_Q0,  SP_Q8,   ~0U,  ~0U,  | 
70  |  |   SP_Q1,  SP_Q9,   ~0U,  ~0U,  | 
71  |  |   SP_Q2,  SP_Q10,  ~0U,  ~0U,  | 
72  |  |   SP_Q3,  SP_Q11,  ~0U,  ~0U,  | 
73  |  |   SP_Q4,  SP_Q12,  ~0U,  ~0U,  | 
74  |  |   SP_Q5,  SP_Q13,  ~0U,  ~0U,  | 
75  |  |   SP_Q6,  SP_Q14,  ~0U,  ~0U,  | 
76  |  |   SP_Q7,  SP_Q15,  ~0U,  ~0U  | 
77  |  | };  | 
78  |  |  | 
79  |  | static const unsigned FCCRegDecoderTable[] = { | 
80  |  |   SP_FCC0, SP_FCC1, SP_FCC2, SP_FCC3  | 
81  |  | };  | 
82  |  |  | 
83  |  | static uint64_t getFeatureBits(int mode)  | 
84  | 83.2k  | { | 
85  |  |   // support everything  | 
86  | 83.2k  |   return (uint64_t)-1;  | 
87  | 83.2k  | }  | 
88  |  |  | 
89  |  | static DecodeStatus DecodeIntRegsRegisterClass(MCInst *Inst, unsigned RegNo,  | 
90  |  |     uint64_t Address, const void *Decoder)  | 
91  | 42.2k  | { | 
92  | 42.2k  |   unsigned Reg;  | 
93  |  |  | 
94  | 42.2k  |   if (RegNo > 31)  | 
95  | 0  |     return MCDisassembler_Fail;  | 
96  |  |  | 
97  | 42.2k  |   Reg = IntRegDecoderTable[RegNo];  | 
98  | 42.2k  |   MCOperand_CreateReg0(Inst, Reg);  | 
99  |  |  | 
100  | 42.2k  |   return MCDisassembler_Success;  | 
101  | 42.2k  | }  | 
102  |  |  | 
103  |  | static DecodeStatus DecodeI64RegsRegisterClass(MCInst *Inst, unsigned RegNo,  | 
104  |  |     uint64_t Address, const void *Decoder)  | 
105  | 6.10k  | { | 
106  | 6.10k  |   unsigned Reg;  | 
107  |  |  | 
108  | 6.10k  |   if (RegNo > 31)  | 
109  | 0  |     return MCDisassembler_Fail;  | 
110  |  |  | 
111  | 6.10k  |   Reg = IntRegDecoderTable[RegNo];  | 
112  | 6.10k  |   MCOperand_CreateReg0(Inst, Reg);  | 
113  |  |  | 
114  | 6.10k  |   return MCDisassembler_Success;  | 
115  | 6.10k  | }  | 
116  |  |  | 
117  |  | static DecodeStatus DecodeFPRegsRegisterClass(MCInst *Inst, unsigned RegNo,  | 
118  |  |     uint64_t Address, const void *Decoder)  | 
119  | 6.85k  | { | 
120  | 6.85k  |   unsigned Reg;  | 
121  |  |  | 
122  | 6.85k  |   if (RegNo > 31)  | 
123  | 0  |     return MCDisassembler_Fail;  | 
124  |  |  | 
125  | 6.85k  |   Reg = FPRegDecoderTable[RegNo];  | 
126  | 6.85k  |   MCOperand_CreateReg0(Inst, Reg);  | 
127  |  |  | 
128  | 6.85k  |   return MCDisassembler_Success;  | 
129  | 6.85k  | }  | 
130  |  |  | 
131  |  | static DecodeStatus DecodeDFPRegsRegisterClass(MCInst *Inst, unsigned RegNo,  | 
132  |  |     uint64_t Address, const void *Decoder)  | 
133  | 5.21k  | { | 
134  | 5.21k  |   unsigned Reg;  | 
135  |  |  | 
136  | 5.21k  |   if (RegNo > 31)  | 
137  | 0  |     return MCDisassembler_Fail;  | 
138  |  |  | 
139  | 5.21k  |   Reg = DFPRegDecoderTable[RegNo];  | 
140  | 5.21k  |   MCOperand_CreateReg0(Inst, Reg);  | 
141  |  |  | 
142  | 5.21k  |   return MCDisassembler_Success;  | 
143  | 5.21k  | }  | 
144  |  |  | 
145  |  | static DecodeStatus DecodeQFPRegsRegisterClass(MCInst *Inst, unsigned RegNo,  | 
146  |  |     uint64_t Address, const void *Decoder)  | 
147  | 6.76k  | { | 
148  | 6.76k  |   unsigned Reg;  | 
149  |  |  | 
150  | 6.76k  |   if (RegNo > 31)  | 
151  | 0  |     return MCDisassembler_Fail;  | 
152  |  |  | 
153  | 6.76k  |   Reg = QFPRegDecoderTable[RegNo];  | 
154  | 6.76k  |   if (Reg == ~0U)  | 
155  | 20  |     return MCDisassembler_Fail;  | 
156  |  |  | 
157  | 6.74k  |   MCOperand_CreateReg0(Inst, Reg);  | 
158  |  |  | 
159  | 6.74k  |   return MCDisassembler_Success;  | 
160  | 6.76k  | }  | 
161  |  |  | 
162  |  | static DecodeStatus DecodeFCCRegsRegisterClass(MCInst *Inst, unsigned RegNo,  | 
163  |  |     uint64_t Address, const void *Decoder)  | 
164  | 13.3k  | { | 
165  | 13.3k  |   if (RegNo > 3)  | 
166  | 3  |     return MCDisassembler_Fail;  | 
167  |  |  | 
168  | 13.3k  |   MCOperand_CreateReg0(Inst, FCCRegDecoderTable[RegNo]);  | 
169  |  |  | 
170  | 13.3k  |   return MCDisassembler_Success;  | 
171  | 13.3k  | }  | 
172  |  |  | 
173  |  |  | 
174  |  | static DecodeStatus DecodeLoadInt(MCInst *Inst, unsigned insn, uint64_t Address,  | 
175  |  |     const void *Decoder);  | 
176  |  | static DecodeStatus DecodeLoadFP(MCInst *Inst, unsigned insn, uint64_t Address,  | 
177  |  |     const void *Decoder);  | 
178  |  | static DecodeStatus DecodeLoadDFP(MCInst *Inst, unsigned insn, uint64_t Address,  | 
179  |  |     const void *Decoder);  | 
180  |  | static DecodeStatus DecodeLoadQFP(MCInst *Inst, unsigned insn, uint64_t Address,  | 
181  |  |     const void *Decoder);  | 
182  |  | static DecodeStatus DecodeStoreInt(MCInst *Inst, unsigned insn,  | 
183  |  |     uint64_t Address, const void *Decoder);  | 
184  |  | static DecodeStatus DecodeStoreFP(MCInst *Inst, unsigned insn,  | 
185  |  |     uint64_t Address, const void *Decoder);  | 
186  |  | static DecodeStatus DecodeStoreDFP(MCInst *Inst, unsigned insn,  | 
187  |  |     uint64_t Address, const void *Decoder);  | 
188  |  | static DecodeStatus DecodeStoreQFP(MCInst *Inst, unsigned insn,  | 
189  |  |     uint64_t Address, const void *Decoder);  | 
190  |  | static DecodeStatus DecodeCall(MCInst *Inst, unsigned insn,  | 
191  |  |     uint64_t Address, const void *Decoder);  | 
192  |  | static DecodeStatus DecodeSIMM13(MCInst *Inst, unsigned insn,  | 
193  |  |     uint64_t Address, const void *Decoder);  | 
194  |  | static DecodeStatus DecodeJMPL(MCInst *Inst, unsigned insn, uint64_t Address,  | 
195  |  |     const void *Decoder);  | 
196  |  | static DecodeStatus DecodeReturn(MCInst *MI, unsigned insn, uint64_t Address,  | 
197  |  |     const void *Decoder);  | 
198  |  | static DecodeStatus DecodeSWAP(MCInst *Inst, unsigned insn, uint64_t Address,  | 
199  |  |     const void *Decoder);  | 
200  |  |  | 
201  |  |  | 
202  |  | #define GET_SUBTARGETINFO_ENUM  | 
203  |  | #include "SparcGenSubtargetInfo.inc"  | 
204  |  | #include "SparcGenDisassemblerTables.inc"  | 
205  |  |  | 
206  |  | /// readInstruction - read four bytes and return 32 bit word.  | 
207  |  | static DecodeStatus readInstruction32(const uint8_t *code, size_t len, uint32_t *Insn)  | 
208  | 83.9k  | { | 
209  | 83.9k  |   if (len < 4)  | 
210  |  |     // not enough data  | 
211  | 629  |     return MCDisassembler_Fail;  | 
212  |  |  | 
213  |  |   // Encoded as a big-endian 32-bit word in the stream.  | 
214  | 83.2k  |   *Insn = (code[3] <<  0) |  | 
215  | 83.2k  |     (code[2] <<  8) |  | 
216  | 83.2k  |     (code[1] << 16) |  | 
217  | 83.2k  |     ((uint32_t) code[0] << 24);  | 
218  |  |  | 
219  | 83.2k  |   return MCDisassembler_Success;  | 
220  | 83.9k  | }  | 
221  |  |  | 
222  |  | bool Sparc_getInstruction(csh ud, const uint8_t *code, size_t code_len, MCInst *MI,  | 
223  |  |     uint16_t *size, uint64_t address, void *info)  | 
224  | 83.9k  | { | 
225  | 83.9k  |   uint32_t Insn;  | 
226  | 83.9k  |   DecodeStatus Result;  | 
227  |  |     | 
228  | 83.9k  |   Result = readInstruction32(code, code_len, &Insn);  | 
229  | 83.9k  |   if (Result == MCDisassembler_Fail)  | 
230  | 629  |     return false;  | 
231  |  |  | 
232  | 83.2k  |   if (MI->flat_insn->detail) { | 
233  | 83.2k  |     memset(MI->flat_insn->detail, 0, offsetof(cs_detail, sparc)+sizeof(cs_sparc));  | 
234  | 83.2k  |   }  | 
235  |  |  | 
236  | 83.2k  |   Result = decodeInstruction_4(DecoderTableSparc32, MI, Insn, address,  | 
237  | 83.2k  |       (MCRegisterInfo *)info, 0);  | 
238  | 83.2k  |   if (Result != MCDisassembler_Fail) { | 
239  | 83.0k  |     *size = 4;  | 
240  | 83.0k  |     return true;  | 
241  | 83.0k  |   }  | 
242  |  |  | 
243  | 265  |   return false;  | 
244  | 83.2k  | }  | 
245  |  |  | 
246  |  | typedef DecodeStatus (*DecodeFunc)(MCInst *MI, unsigned insn, uint64_t Address,  | 
247  |  |     const void *Decoder);  | 
248  |  |  | 
249  |  | static DecodeStatus DecodeMem(MCInst *MI, unsigned insn, uint64_t Address,  | 
250  |  |     const void *Decoder,  | 
251  |  |     bool isLoad, DecodeFunc DecodeRD)  | 
252  | 3.56k  | { | 
253  | 3.56k  |   DecodeStatus status;  | 
254  | 3.56k  |   unsigned rd = fieldFromInstruction_4(insn, 25, 5);  | 
255  | 3.56k  |   unsigned rs1 = fieldFromInstruction_4(insn, 14, 5);  | 
256  | 3.56k  |   bool isImm = fieldFromInstruction_4(insn, 13, 1) != 0;  | 
257  | 3.56k  |   unsigned rs2 = 0;  | 
258  | 3.56k  |   unsigned simm13 = 0;  | 
259  |  |  | 
260  | 3.56k  |   if (isImm)  | 
261  | 2.24k  |     simm13 = SignExtend32(fieldFromInstruction_4(insn, 0, 13), 13);  | 
262  | 1.31k  |   else  | 
263  | 1.31k  |     rs2 = fieldFromInstruction_4(insn, 0, 5);  | 
264  |  |  | 
265  | 3.56k  |   if (isLoad) { | 
266  | 2.05k  |     status = DecodeRD(MI, rd, Address, Decoder);  | 
267  | 2.05k  |     if (status != MCDisassembler_Success)  | 
268  | 3  |       return status;  | 
269  | 2.05k  |   }  | 
270  |  |  | 
271  |  |   // Decode rs1.  | 
272  | 3.55k  |   status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);  | 
273  | 3.55k  |   if (status != MCDisassembler_Success)  | 
274  | 0  |     return status;  | 
275  |  |  | 
276  |  |   // Decode imm|rs2.  | 
277  | 3.55k  |   if (isImm)  | 
278  | 2.24k  |     MCOperand_CreateImm0(MI, simm13);  | 
279  | 1.31k  |   else { | 
280  | 1.31k  |     status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);  | 
281  | 1.31k  |     if (status != MCDisassembler_Success)  | 
282  | 0  |       return status;  | 
283  | 1.31k  |   }  | 
284  |  |  | 
285  | 3.55k  |   if (!isLoad) { | 
286  | 1.51k  |     status = DecodeRD(MI, rd, Address, Decoder);  | 
287  | 1.51k  |     if (status != MCDisassembler_Success)  | 
288  | 1  |       return status;  | 
289  | 1.51k  |   }  | 
290  |  |  | 
291  | 3.55k  |   return MCDisassembler_Success;  | 
292  | 3.55k  | }  | 
293  |  |  | 
294  |  | static DecodeStatus DecodeLoadInt(MCInst *Inst, unsigned insn, uint64_t Address,  | 
295  |  |     const void *Decoder)  | 
296  | 710  | { | 
297  | 710  |   return DecodeMem(Inst, insn, Address, Decoder, true,  | 
298  | 710  |       DecodeIntRegsRegisterClass);  | 
299  | 710  | }  | 
300  |  |  | 
301  |  | static DecodeStatus DecodeLoadFP(MCInst *Inst, unsigned insn, uint64_t Address,  | 
302  |  |     const void *Decoder)  | 
303  | 834  | { | 
304  | 834  |   return DecodeMem(Inst, insn, Address, Decoder, true,  | 
305  | 834  |       DecodeFPRegsRegisterClass);  | 
306  | 834  | }  | 
307  |  |  | 
308  |  | static DecodeStatus DecodeLoadDFP(MCInst *Inst, unsigned insn, uint64_t Address,  | 
309  |  |     const void *Decoder)  | 
310  | 367  | { | 
311  | 367  |   return DecodeMem(Inst, insn, Address, Decoder, true,  | 
312  | 367  |       DecodeDFPRegsRegisterClass);  | 
313  | 367  | }  | 
314  |  |  | 
315  |  | static DecodeStatus DecodeLoadQFP(MCInst *Inst, unsigned insn, uint64_t Address,  | 
316  |  |     const void *Decoder)  | 
317  | 139  | { | 
318  | 139  |   return DecodeMem(Inst, insn, Address, Decoder, true,  | 
319  | 139  |       DecodeQFPRegsRegisterClass);  | 
320  | 139  | }  | 
321  |  |  | 
322  |  | static DecodeStatus DecodeStoreInt(MCInst *Inst, unsigned insn,  | 
323  |  |     uint64_t Address, const void *Decoder)  | 
324  | 659  | { | 
325  | 659  |   return DecodeMem(Inst, insn, Address, Decoder, false,  | 
326  | 659  |       DecodeIntRegsRegisterClass);  | 
327  | 659  | }  | 
328  |  |  | 
329  |  | static DecodeStatus DecodeStoreFP(MCInst *Inst, unsigned insn, uint64_t Address,  | 
330  |  |     const void *Decoder)  | 
331  | 317  | { | 
332  | 317  |   return DecodeMem(Inst, insn, Address, Decoder, false,  | 
333  | 317  |       DecodeFPRegsRegisterClass);  | 
334  | 317  | }  | 
335  |  |  | 
336  |  | static DecodeStatus DecodeStoreDFP(MCInst *Inst, unsigned insn,  | 
337  |  |     uint64_t Address, const void *Decoder)  | 
338  | 403  | { | 
339  | 403  |   return DecodeMem(Inst, insn, Address, Decoder, false,  | 
340  | 403  |       DecodeDFPRegsRegisterClass);  | 
341  | 403  | }  | 
342  |  |  | 
343  |  | static DecodeStatus DecodeStoreQFP(MCInst *Inst, unsigned insn,  | 
344  |  |     uint64_t Address, const void *Decoder)  | 
345  | 133  | { | 
346  | 133  |   return DecodeMem(Inst, insn, Address, Decoder, false,  | 
347  | 133  |       DecodeQFPRegsRegisterClass);  | 
348  | 133  | }  | 
349  |  |  | 
350  |  | static DecodeStatus DecodeCall(MCInst *MI, unsigned insn,  | 
351  |  |     uint64_t Address, const void *Decoder)  | 
352  | 12.2k  | { | 
353  | 12.2k  |   unsigned tgt = fieldFromInstruction_4(insn, 0, 30);  | 
354  | 12.2k  |   tgt <<= 2;  | 
355  |  |  | 
356  | 12.2k  |   MCOperand_CreateImm0(MI, tgt);  | 
357  |  |  | 
358  | 12.2k  |   return MCDisassembler_Success;  | 
359  | 12.2k  | }  | 
360  |  |  | 
361  |  | static DecodeStatus DecodeSIMM13(MCInst *MI, unsigned insn,  | 
362  |  |     uint64_t Address, const void *Decoder)  | 
363  | 2.16k  | { | 
364  | 2.16k  |   unsigned tgt = SignExtend32(fieldFromInstruction_4(insn, 0, 13), 13);  | 
365  |  |  | 
366  | 2.16k  |   MCOperand_CreateImm0(MI, tgt);  | 
367  |  |  | 
368  | 2.16k  |   return MCDisassembler_Success;  | 
369  | 2.16k  | }  | 
370  |  |  | 
371  |  | static DecodeStatus DecodeJMPL(MCInst *MI, unsigned insn, uint64_t Address,  | 
372  |  |     const void *Decoder)  | 
373  | 1.57k  | { | 
374  | 1.57k  |   DecodeStatus status;  | 
375  | 1.57k  |   unsigned rd = fieldFromInstruction_4(insn, 25, 5);  | 
376  | 1.57k  |   unsigned rs1 = fieldFromInstruction_4(insn, 14, 5);  | 
377  | 1.57k  |   unsigned isImm = fieldFromInstruction_4(insn, 13, 1);  | 
378  | 1.57k  |   unsigned rs2 = 0;  | 
379  | 1.57k  |   unsigned simm13 = 0;  | 
380  |  |  | 
381  | 1.57k  |   if (isImm)  | 
382  | 1.50k  |     simm13 = SignExtend32(fieldFromInstruction_4(insn, 0, 13), 13);  | 
383  | 69  |   else  | 
384  | 69  |     rs2 = fieldFromInstruction_4(insn, 0, 5);  | 
385  |  |  | 
386  |  |   // Decode RD.  | 
387  | 1.57k  |   status = DecodeIntRegsRegisterClass(MI, rd, Address, Decoder);  | 
388  | 1.57k  |   if (status != MCDisassembler_Success)  | 
389  | 0  |     return status;  | 
390  |  |  | 
391  |  |   // Decode RS1.  | 
392  | 1.57k  |   status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);  | 
393  | 1.57k  |   if (status != MCDisassembler_Success)  | 
394  | 0  |     return status;  | 
395  |  |  | 
396  |  |   // Decode RS1 | SIMM13.  | 
397  | 1.57k  |   if (isImm)  | 
398  | 1.50k  |     MCOperand_CreateImm0(MI, simm13);  | 
399  | 69  |   else { | 
400  | 69  |     status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);  | 
401  | 69  |     if (status != MCDisassembler_Success)  | 
402  | 0  |       return status;  | 
403  | 69  |   }  | 
404  |  |  | 
405  | 1.57k  |   return MCDisassembler_Success;  | 
406  | 1.57k  | }  | 
407  |  |  | 
408  |  | static DecodeStatus DecodeReturn(MCInst *MI, unsigned insn, uint64_t Address,  | 
409  |  |     const void *Decoder)  | 
410  | 165  | { | 
411  | 165  |   DecodeStatus status;  | 
412  | 165  |   unsigned rs1 = fieldFromInstruction_4(insn, 14, 5);  | 
413  | 165  |   unsigned isImm = fieldFromInstruction_4(insn, 13, 1);  | 
414  | 165  |   unsigned rs2 = 0;  | 
415  | 165  |   unsigned simm13 = 0;  | 
416  | 165  |   if (isImm)  | 
417  | 73  |     simm13 = SignExtend32(fieldFromInstruction_4(insn, 0, 13), 13);  | 
418  | 92  |   else  | 
419  | 92  |     rs2 = fieldFromInstruction_4(insn, 0, 5);  | 
420  |  |  | 
421  |  |   // Decode RS1.  | 
422  | 165  |   status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);  | 
423  | 165  |   if (status != MCDisassembler_Success)  | 
424  | 0  |     return status;  | 
425  |  |  | 
426  |  |   // Decode RS2 | SIMM13.  | 
427  | 165  |   if (isImm)  | 
428  | 73  |     MCOperand_CreateImm0(MI, simm13);  | 
429  | 92  |   else { | 
430  | 92  |     status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);  | 
431  | 92  |     if (status != MCDisassembler_Success)  | 
432  | 0  |       return status;  | 
433  | 92  |   }  | 
434  |  |  | 
435  | 165  |   return MCDisassembler_Success;  | 
436  | 165  | }  | 
437  |  |  | 
438  |  | static DecodeStatus DecodeSWAP(MCInst *MI, unsigned insn, uint64_t Address,  | 
439  |  |     const void *Decoder)  | 
440  | 312  | { | 
441  | 312  |   DecodeStatus status;  | 
442  | 312  |   unsigned rd = fieldFromInstruction_4(insn, 25, 5);  | 
443  | 312  |   unsigned rs1 = fieldFromInstruction_4(insn, 14, 5);  | 
444  | 312  |   unsigned isImm = fieldFromInstruction_4(insn, 13, 1);  | 
445  | 312  |   unsigned rs2 = 0;  | 
446  | 312  |   unsigned simm13 = 0;  | 
447  |  |  | 
448  | 312  |   if (isImm)  | 
449  | 244  |     simm13 = SignExtend32(fieldFromInstruction_4(insn, 0, 13), 13);  | 
450  | 68  |   else  | 
451  | 68  |     rs2 = fieldFromInstruction_4(insn, 0, 5);  | 
452  |  |  | 
453  |  |   // Decode RD.  | 
454  | 312  |   status = DecodeIntRegsRegisterClass(MI, rd, Address, Decoder);  | 
455  | 312  |   if (status != MCDisassembler_Success)  | 
456  | 0  |     return status;  | 
457  |  |  | 
458  |  |   // Decode RS1.  | 
459  | 312  |   status = DecodeIntRegsRegisterClass(MI, rs1, Address, Decoder);  | 
460  | 312  |   if (status != MCDisassembler_Success)  | 
461  | 0  |     return status;  | 
462  |  |  | 
463  |  |   // Decode RS1 | SIMM13.  | 
464  | 312  |   if (isImm)  | 
465  | 244  |     MCOperand_CreateImm0(MI, simm13);  | 
466  | 68  |   else { | 
467  | 68  |     status = DecodeIntRegsRegisterClass(MI, rs2, Address, Decoder);  | 
468  | 68  |     if (status != MCDisassembler_Success)  | 
469  | 0  |       return status;  | 
470  | 68  |   }  | 
471  |  |  | 
472  | 312  |   return MCDisassembler_Success;  | 
473  | 312  | }  | 
474  |  |  | 
475  |  | void Sparc_init(MCRegisterInfo *MRI)  | 
476  | 2.45k  | { | 
477  |  |   /*  | 
478  |  |   InitMCRegisterInfo(SparcRegDesc, 119, RA, PC,  | 
479  |  |       SparcMCRegisterClasses, 8,  | 
480  |  |       SparcRegUnitRoots,  | 
481  |  |       86,  | 
482  |  |       SparcRegDiffLists,  | 
483  |  |       SparcRegStrings,  | 
484  |  |       SparcSubRegIdxLists,  | 
485  |  |       7,  | 
486  |  |       SparcSubRegIdxRanges,  | 
487  |  |       SparcRegEncodingTable);  | 
488  |  |   */  | 
489  |  |  | 
490  | 2.45k  |   MCRegisterInfo_InitMCRegisterInfo(MRI, SparcRegDesc, 119,  | 
491  | 2.45k  |       0, 0,  | 
492  | 2.45k  |       SparcMCRegisterClasses, 8,  | 
493  | 2.45k  |       0, 0,  | 
494  | 2.45k  |       SparcRegDiffLists,  | 
495  | 2.45k  |       0,  | 
496  | 2.45k  |       SparcSubRegIdxLists, 7,  | 
497  | 2.45k  |       0);  | 
498  | 2.45k  | }  | 
499  |  |  | 
500  |  | #endif  |