annotate agent/src/share/classes/sun/jvm/hotspot/asm/x86/InstructionDecoder.java @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 package sun.jvm.hotspot.asm.x86;
a61af66fc99e Initial load
duke
parents:
diff changeset
26
a61af66fc99e Initial load
duke
parents:
diff changeset
27 import sun.jvm.hotspot.asm.*;
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 // basic instruction decoder class
a61af66fc99e Initial load
duke
parents:
diff changeset
30 public class InstructionDecoder implements /* imports */ X86Opcodes , RTLDataTypes, RTLOperations {
a61af66fc99e Initial load
duke
parents:
diff changeset
31
a61af66fc99e Initial load
duke
parents:
diff changeset
32 protected String name;
a61af66fc99e Initial load
duke
parents:
diff changeset
33 protected int addrMode1;
a61af66fc99e Initial load
duke
parents:
diff changeset
34 protected int operandType1;
a61af66fc99e Initial load
duke
parents:
diff changeset
35 protected int addrMode2;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 protected int operandType2;
a61af66fc99e Initial load
duke
parents:
diff changeset
37 protected int addrMode3;
a61af66fc99e Initial load
duke
parents:
diff changeset
38 protected int operandType3;
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 private int mod;
a61af66fc99e Initial load
duke
parents:
diff changeset
41 private int regOrOpcode;
a61af66fc99e Initial load
duke
parents:
diff changeset
42 private int rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 protected int prefixes;
a61af66fc99e Initial load
duke
parents:
diff changeset
44
a61af66fc99e Initial load
duke
parents:
diff changeset
45 protected int byteIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
46 protected int instrStartIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
47
a61af66fc99e Initial load
duke
parents:
diff changeset
48 public InstructionDecoder(String name) {
a61af66fc99e Initial load
duke
parents:
diff changeset
49 this.name = name;
a61af66fc99e Initial load
duke
parents:
diff changeset
50 this.operandType1 = INVALID_OPERANDTYPE;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 this.operandType2 = INVALID_OPERANDTYPE;
a61af66fc99e Initial load
duke
parents:
diff changeset
52 this.operandType3 = INVALID_OPERANDTYPE;
a61af66fc99e Initial load
duke
parents:
diff changeset
53 this.addrMode1 = INVALID_ADDRMODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 this.addrMode2 = INVALID_ADDRMODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 this.addrMode3 = INVALID_ADDRMODE;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57 public InstructionDecoder(String name, int addrMode1, int operandType1) {
a61af66fc99e Initial load
duke
parents:
diff changeset
58 this(name);
a61af66fc99e Initial load
duke
parents:
diff changeset
59 this.addrMode1 = addrMode1;
a61af66fc99e Initial load
duke
parents:
diff changeset
60 this.operandType1 = operandType1;
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 public InstructionDecoder(String name, int addrMode1, int operandType1, int addrMode2, int operandType2) {
a61af66fc99e Initial load
duke
parents:
diff changeset
63 this(name, addrMode1, operandType1);
a61af66fc99e Initial load
duke
parents:
diff changeset
64 this.addrMode2 = addrMode2;
a61af66fc99e Initial load
duke
parents:
diff changeset
65 this.operandType2 = operandType2;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67 public InstructionDecoder(String name, int addrMode1, int operandType1, int addrMode2, int operandType2,
a61af66fc99e Initial load
duke
parents:
diff changeset
68 int addrMode3, int operandType3) {
a61af66fc99e Initial load
duke
parents:
diff changeset
69 this(name, addrMode1, operandType1, addrMode2, operandType2);
a61af66fc99e Initial load
duke
parents:
diff changeset
70 this.addrMode3 = addrMode3;
a61af66fc99e Initial load
duke
parents:
diff changeset
71 this.operandType3 = operandType3;
a61af66fc99e Initial load
duke
parents:
diff changeset
72 }
a61af66fc99e Initial load
duke
parents:
diff changeset
73 // "operand1"
a61af66fc99e Initial load
duke
parents:
diff changeset
74 protected Operand getOperand1(byte[] bytesArray, boolean operandSize, boolean addrSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 if( (addrMode1 != INVALID_ADDRMODE) && (operandType1 != INVALID_OPERANDTYPE) )
a61af66fc99e Initial load
duke
parents:
diff changeset
76 return getOperand(bytesArray, addrMode1, operandType1, operandSize, addrSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
77 else
a61af66fc99e Initial load
duke
parents:
diff changeset
78 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
79 }
a61af66fc99e Initial load
duke
parents:
diff changeset
80
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // "operand2"
a61af66fc99e Initial load
duke
parents:
diff changeset
82 protected Operand getOperand2(byte[] bytesArray, boolean operandSize, boolean addrSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
83 if( (addrMode2 != INVALID_ADDRMODE) && (operandType2 != INVALID_OPERANDTYPE) )
a61af66fc99e Initial load
duke
parents:
diff changeset
84 return getOperand(bytesArray, addrMode2, operandType2, operandSize, addrSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
85 else
a61af66fc99e Initial load
duke
parents:
diff changeset
86 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
87 }
a61af66fc99e Initial load
duke
parents:
diff changeset
88
a61af66fc99e Initial load
duke
parents:
diff changeset
89 // "operand3"
a61af66fc99e Initial load
duke
parents:
diff changeset
90 protected Operand getOperand3(byte[] bytesArray, boolean operandSize, boolean addrSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
91 if( (addrMode3 != INVALID_ADDRMODE) && (operandType3 != INVALID_OPERANDTYPE) )
a61af66fc99e Initial load
duke
parents:
diff changeset
92 return getOperand(bytesArray, addrMode3, operandType3, operandSize, addrSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
93 else
a61af66fc99e Initial load
duke
parents:
diff changeset
94 return null;
a61af66fc99e Initial load
duke
parents:
diff changeset
95 }
a61af66fc99e Initial load
duke
parents:
diff changeset
96
a61af66fc99e Initial load
duke
parents:
diff changeset
97 static int readInt32(byte[] bytesArray, int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
98 int ret = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
99 ret = readByte(bytesArray, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
100 ret |= readByte(bytesArray, index+1) << 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
101 ret |= readByte(bytesArray, index+2) << 16;
a61af66fc99e Initial load
duke
parents:
diff changeset
102 ret |= readByte(bytesArray, index+3) << 24;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 return ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
a61af66fc99e Initial load
duke
parents:
diff changeset
105 static int readInt16(byte[] bytesArray, int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
106 int ret = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
107 ret = readByte(bytesArray, index);
a61af66fc99e Initial load
duke
parents:
diff changeset
108 ret |= readByte(bytesArray, index+1) << 8;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 return ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
110 }
a61af66fc99e Initial load
duke
parents:
diff changeset
111 static int readByte(byte[] bytesArray, int index) {
a61af66fc99e Initial load
duke
parents:
diff changeset
112 int ret = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
113 if (index < bytesArray.length) {
a61af66fc99e Initial load
duke
parents:
diff changeset
114 ret = (int)bytesArray[index];
a61af66fc99e Initial load
duke
parents:
diff changeset
115 ret = ret & 0xff;
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 return ret;
a61af66fc99e Initial load
duke
parents:
diff changeset
118 }
a61af66fc99e Initial load
duke
parents:
diff changeset
119 private boolean isModRMPresent(int addrMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
120 if( (addrMode == ADDR_E) || (addrMode == ADDR_G) || (addrMode == ADDR_FPREG) || (addrMode == ADDR_Q) || (addrMode == ADDR_W) )
a61af66fc99e Initial load
duke
parents:
diff changeset
121 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
122 else
a61af66fc99e Initial load
duke
parents:
diff changeset
123 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
124 }
a61af66fc99e Initial load
duke
parents:
diff changeset
125 public int getCurrentIndex() {
a61af66fc99e Initial load
duke
parents:
diff changeset
126 return byteIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 }
a61af66fc99e Initial load
duke
parents:
diff changeset
128
a61af66fc99e Initial load
duke
parents:
diff changeset
129 public Instruction decode(byte[] bytesArray, int index, int instrStartIndex, int segmentOverride, int prefixes, X86InstructionFactory factory) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 this.byteIndex = index;
a61af66fc99e Initial load
duke
parents:
diff changeset
131 this.instrStartIndex = instrStartIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 this.prefixes = prefixes;
a61af66fc99e Initial load
duke
parents:
diff changeset
133 boolean operandSize; //operand-size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
134 boolean addrSize; //address-size prefix
a61af66fc99e Initial load
duke
parents:
diff changeset
135 if ( ( (prefixes & PREFIX_DATA) ^ segmentOverride ) == 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
136 operandSize = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
137 else
a61af66fc99e Initial load
duke
parents:
diff changeset
138 operandSize = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
139 if ( ((prefixes & PREFIX_ADR) ^ segmentOverride) == 1)
a61af66fc99e Initial load
duke
parents:
diff changeset
140 addrSize = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
141 else
a61af66fc99e Initial load
duke
parents:
diff changeset
142 addrSize = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
143 this.name = getCorrectOpcodeName(name, prefixes, operandSize, addrSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
144
a61af66fc99e Initial load
duke
parents:
diff changeset
145 //Fetch the mod/reg/rm byte only if it is present.
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if( isModRMPresent(addrMode1) || isModRMPresent(addrMode2) || isModRMPresent(addrMode3) ) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147
a61af66fc99e Initial load
duke
parents:
diff changeset
148 int ModRM = readByte(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
149 byteIndex++;
a61af66fc99e Initial load
duke
parents:
diff changeset
150 mod = (ModRM >> 6) & 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
151 regOrOpcode = (ModRM >> 3) & 7;
a61af66fc99e Initial load
duke
parents:
diff changeset
152 rm = ModRM & 7;
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 return decodeInstruction(bytesArray, operandSize, addrSize, factory);
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 protected Instruction decodeInstruction(byte[] bytesArray, boolean operandSize, boolean addrSize, X86InstructionFactory factory) {
a61af66fc99e Initial load
duke
parents:
diff changeset
158 Operand op1 = getOperand1(bytesArray, operandSize, addrSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
159 Operand op2 = getOperand2(bytesArray, operandSize, addrSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
160 Operand op3 = getOperand3(bytesArray, operandSize, addrSize);
a61af66fc99e Initial load
duke
parents:
diff changeset
161 int size = byteIndex - instrStartIndex;
a61af66fc99e Initial load
duke
parents:
diff changeset
162 return factory.newGeneralInstruction(name, op1, op2, op3, size, prefixes);
a61af66fc99e Initial load
duke
parents:
diff changeset
163 }
a61af66fc99e Initial load
duke
parents:
diff changeset
164
a61af66fc99e Initial load
duke
parents:
diff changeset
165 // capital letters in template are macros
a61af66fc99e Initial load
duke
parents:
diff changeset
166 private String getCorrectOpcodeName(String oldName, int prefixes, boolean operandSize, boolean addrSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 StringBuffer newName = new StringBuffer(oldName);
a61af66fc99e Initial load
duke
parents:
diff changeset
168 int index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
169 for(index=0; index<oldName.length(); index++) {
a61af66fc99e Initial load
duke
parents:
diff changeset
170 switch (oldName.charAt(index)) {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 case 'C': /* For jcxz/jecxz */
a61af66fc99e Initial load
duke
parents:
diff changeset
172 if (addrSize)
a61af66fc99e Initial load
duke
parents:
diff changeset
173 newName.setCharAt(index, 'e');
a61af66fc99e Initial load
duke
parents:
diff changeset
174 index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
175 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
176 case 'N':
a61af66fc99e Initial load
duke
parents:
diff changeset
177 if ((prefixes & PREFIX_FWAIT) == 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
178 newName.setCharAt(index, 'n');
a61af66fc99e Initial load
duke
parents:
diff changeset
179 index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
180 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
181 case 'S':
a61af66fc99e Initial load
duke
parents:
diff changeset
182 /* operand size flag */
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (operandSize == true)
a61af66fc99e Initial load
duke
parents:
diff changeset
184 newName.setCharAt(index, 'l');
a61af66fc99e Initial load
duke
parents:
diff changeset
185 else
a61af66fc99e Initial load
duke
parents:
diff changeset
186 newName.setCharAt(index, 'w');
a61af66fc99e Initial load
duke
parents:
diff changeset
187 index++;
a61af66fc99e Initial load
duke
parents:
diff changeset
188 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
190 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
191 }
a61af66fc99e Initial load
duke
parents:
diff changeset
192 }
a61af66fc99e Initial load
duke
parents:
diff changeset
193 return newName.toString();
a61af66fc99e Initial load
duke
parents:
diff changeset
194 }
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 //IA-32 Intel Architecture Software Developer's Manual Volume 2
a61af66fc99e Initial load
duke
parents:
diff changeset
197 //Refer to Chapter 2 - Instruction Format
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 //Get the Operand object from the address type and the operand type
a61af66fc99e Initial load
duke
parents:
diff changeset
200 private Operand getOperand(byte[] bytesArray, int addrMode, int operandType, boolean operandSize, boolean addrSize) {
a61af66fc99e Initial load
duke
parents:
diff changeset
201 Operand op = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
202 switch(addrMode) {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 case ADDR_E:
a61af66fc99e Initial load
duke
parents:
diff changeset
204 case ADDR_W: //SSE: ModR/M byte specifies either 128 bit XMM register or memory
a61af66fc99e Initial load
duke
parents:
diff changeset
205 case ADDR_Q: //SSE: ModR/M byte specifies either 128 bit MMX register or memory
a61af66fc99e Initial load
duke
parents:
diff changeset
206 X86SegmentRegister segReg = getSegmentRegisterFromPrefix(prefixes);
a61af66fc99e Initial load
duke
parents:
diff changeset
207
a61af66fc99e Initial load
duke
parents:
diff changeset
208 if (mod == 3) { //Register operand, no SIB follows
a61af66fc99e Initial load
duke
parents:
diff changeset
209 if (addrMode == ADDR_E) {
a61af66fc99e Initial load
duke
parents:
diff changeset
210 switch (operandType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
211 case b_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
212 op = X86Registers.getRegister8(rm);
a61af66fc99e Initial load
duke
parents:
diff changeset
213 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
214 case w_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
215 op = X86Registers.getRegister16(rm);
a61af66fc99e Initial load
duke
parents:
diff changeset
216 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
217 case v_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
218 if (operandSize == true) //Operand size prefix is present
a61af66fc99e Initial load
duke
parents:
diff changeset
219 op = X86Registers.getRegister32(rm);
a61af66fc99e Initial load
duke
parents:
diff changeset
220 else
a61af66fc99e Initial load
duke
parents:
diff changeset
221 op = X86Registers.getRegister16(rm);
a61af66fc99e Initial load
duke
parents:
diff changeset
222 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
223 case p_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
224 X86Register reg;
a61af66fc99e Initial load
duke
parents:
diff changeset
225 if (operandSize == true) //Operand size prefix is present
a61af66fc99e Initial load
duke
parents:
diff changeset
226 reg = X86Registers.getRegister32(rm);
a61af66fc99e Initial load
duke
parents:
diff changeset
227 else
a61af66fc99e Initial load
duke
parents:
diff changeset
228 reg = X86Registers.getRegister16(rm);
a61af66fc99e Initial load
duke
parents:
diff changeset
229
a61af66fc99e Initial load
duke
parents:
diff changeset
230 op = new X86RegisterIndirectAddress(segReg, reg, null, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
231 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
232 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
233 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
234 }
a61af66fc99e Initial load
duke
parents:
diff changeset
235 } else if (addrMode == ADDR_W) {
a61af66fc99e Initial load
duke
parents:
diff changeset
236 op = X86XMMRegisters.getRegister(rm);
a61af66fc99e Initial load
duke
parents:
diff changeset
237 } else if (addrMode == ADDR_Q) {
a61af66fc99e Initial load
duke
parents:
diff changeset
238 op = X86MMXRegisters.getRegister(rm);
a61af66fc99e Initial load
duke
parents:
diff changeset
239 }
a61af66fc99e Initial load
duke
parents:
diff changeset
240
a61af66fc99e Initial load
duke
parents:
diff changeset
241 } else { //mod != 3
a61af66fc99e Initial load
duke
parents:
diff changeset
242 //SIB follows for (rm==4), SIB gives scale, index and base in this case
a61af66fc99e Initial load
duke
parents:
diff changeset
243 //disp32 is present for (mod==0 && rm==5) || (mod==2)
a61af66fc99e Initial load
duke
parents:
diff changeset
244 //disp8 is present for (mod==1)
a61af66fc99e Initial load
duke
parents:
diff changeset
245 //for (rm!=4) base is register at rm.
a61af66fc99e Initial load
duke
parents:
diff changeset
246 int scale = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
247 int index = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
248 int base = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
249 long disp = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
250 if(rm == 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
251 int sib = readByte(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
252 byteIndex++;
a61af66fc99e Initial load
duke
parents:
diff changeset
253 scale = (sib >> 6) & 3;
a61af66fc99e Initial load
duke
parents:
diff changeset
254 index = (sib >> 3) & 7;
a61af66fc99e Initial load
duke
parents:
diff changeset
255 base = sib & 7;
a61af66fc99e Initial load
duke
parents:
diff changeset
256 }
a61af66fc99e Initial load
duke
parents:
diff changeset
257
a61af66fc99e Initial load
duke
parents:
diff changeset
258 switch (mod) {
a61af66fc99e Initial load
duke
parents:
diff changeset
259 case 0:
a61af66fc99e Initial load
duke
parents:
diff changeset
260 switch(rm) {
a61af66fc99e Initial load
duke
parents:
diff changeset
261 case 4:
a61af66fc99e Initial load
duke
parents:
diff changeset
262 if(base == 5) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 disp = readInt32(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
264 byteIndex += 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
265 if (index != 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
266 op = new X86RegisterIndirectAddress(segReg, null, X86Registers.getRegister32(index), disp, scale);
a61af66fc99e Initial load
duke
parents:
diff changeset
267 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 op = new X86RegisterIndirectAddress(segReg, null, null, disp, scale);
a61af66fc99e Initial load
duke
parents:
diff changeset
269 }
a61af66fc99e Initial load
duke
parents:
diff changeset
270 }
a61af66fc99e Initial load
duke
parents:
diff changeset
271 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
272 if (index != 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
273 op = new X86RegisterIndirectAddress(segReg, X86Registers.getRegister32(base), X86Registers.getRegister32(index), 0, scale);
a61af66fc99e Initial load
duke
parents:
diff changeset
274 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
275 op = new X86RegisterIndirectAddress(segReg, X86Registers.getRegister32(base), null, 0, scale);
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 }
a61af66fc99e Initial load
duke
parents:
diff changeset
278 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
279 case 5:
a61af66fc99e Initial load
duke
parents:
diff changeset
280 disp = readInt32(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
281 byteIndex += 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
282 //Create an Address object only with displacement
a61af66fc99e Initial load
duke
parents:
diff changeset
283 op = new X86RegisterIndirectAddress(segReg, null, null, disp);
a61af66fc99e Initial load
duke
parents:
diff changeset
284 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
285 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
286 base = rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
287 //Create an Address object only with base
a61af66fc99e Initial load
duke
parents:
diff changeset
288 op = new X86RegisterIndirectAddress(segReg, X86Registers.getRegister32(base), null, 0);
a61af66fc99e Initial load
duke
parents:
diff changeset
289 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
290 }
a61af66fc99e Initial load
duke
parents:
diff changeset
291 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
292 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
293 disp = (byte)readByte(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
294 byteIndex++;
a61af66fc99e Initial load
duke
parents:
diff changeset
295 if (rm !=4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
296 base = rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
297 //Address with base and disp only
a61af66fc99e Initial load
duke
parents:
diff changeset
298 op = new X86RegisterIndirectAddress(segReg, X86Registers.getRegister32(base), null, disp);
a61af66fc99e Initial load
duke
parents:
diff changeset
299 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
300 if (index != 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
301 op = new X86RegisterIndirectAddress(segReg, X86Registers.getRegister32(base), X86Registers.getRegister32(index), disp, scale);
a61af66fc99e Initial load
duke
parents:
diff changeset
302 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
303 op = new X86RegisterIndirectAddress(segReg, X86Registers.getRegister32(base), null, disp, scale);
a61af66fc99e Initial load
duke
parents:
diff changeset
304 }
a61af66fc99e Initial load
duke
parents:
diff changeset
305 }
a61af66fc99e Initial load
duke
parents:
diff changeset
306 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
307 case 2:
a61af66fc99e Initial load
duke
parents:
diff changeset
308 disp = readInt32(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
309 byteIndex += 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
310 if (rm !=4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
311 base = rm;
a61af66fc99e Initial load
duke
parents:
diff changeset
312 //Address with base and disp
a61af66fc99e Initial load
duke
parents:
diff changeset
313 op = new X86RegisterIndirectAddress(segReg, X86Registers.getRegister32(base), null, disp);
a61af66fc99e Initial load
duke
parents:
diff changeset
314 } else if (index != 4) {
a61af66fc99e Initial load
duke
parents:
diff changeset
315 op = new X86RegisterIndirectAddress(segReg, X86Registers.getRegister32(base), X86Registers.getRegister32(index), disp, scale);
a61af66fc99e Initial load
duke
parents:
diff changeset
316 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
317 op = new X86RegisterIndirectAddress(segReg, X86Registers.getRegister32(base), null, disp, scale);
a61af66fc99e Initial load
duke
parents:
diff changeset
318 }
a61af66fc99e Initial load
duke
parents:
diff changeset
319 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
320 }
a61af66fc99e Initial load
duke
parents:
diff changeset
321 }
a61af66fc99e Initial load
duke
parents:
diff changeset
322 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
323
a61af66fc99e Initial load
duke
parents:
diff changeset
324 case ADDR_I:
a61af66fc99e Initial load
duke
parents:
diff changeset
325 switch (operandType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
326 case b_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
327 op = new Immediate(new Integer(readByte(bytesArray, byteIndex)));
a61af66fc99e Initial load
duke
parents:
diff changeset
328 byteIndex++;
a61af66fc99e Initial load
duke
parents:
diff changeset
329 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
330 case w_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
331 op = new Immediate(new Integer(readInt16(bytesArray, byteIndex)));
a61af66fc99e Initial load
duke
parents:
diff changeset
332 byteIndex += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
333 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
334 case v_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
335 if (operandSize == true) { //Operand size prefix is present
a61af66fc99e Initial load
duke
parents:
diff changeset
336 op = new Immediate(new Integer(readInt32(bytesArray, byteIndex)));
a61af66fc99e Initial load
duke
parents:
diff changeset
337 byteIndex += 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
338 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
339 op = new Immediate(new Integer(readInt16(bytesArray, byteIndex)));
a61af66fc99e Initial load
duke
parents:
diff changeset
340 byteIndex += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
341 }
a61af66fc99e Initial load
duke
parents:
diff changeset
342 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
343 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
344 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
345 }
a61af66fc99e Initial load
duke
parents:
diff changeset
346 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
347 case ADDR_REG: //registers
a61af66fc99e Initial load
duke
parents:
diff changeset
348 switch(operandType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
349 case EAX:
a61af66fc99e Initial load
duke
parents:
diff changeset
350 case ECX:
a61af66fc99e Initial load
duke
parents:
diff changeset
351 case EDX:
a61af66fc99e Initial load
duke
parents:
diff changeset
352 case EBX:
a61af66fc99e Initial load
duke
parents:
diff changeset
353 case ESP:
a61af66fc99e Initial load
duke
parents:
diff changeset
354 case EBP:
a61af66fc99e Initial load
duke
parents:
diff changeset
355 case ESI:
a61af66fc99e Initial load
duke
parents:
diff changeset
356 case EDI:
a61af66fc99e Initial load
duke
parents:
diff changeset
357 if(operandSize == true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
358 op = X86Registers.getRegister32(operandType - EAX);
a61af66fc99e Initial load
duke
parents:
diff changeset
359 }
a61af66fc99e Initial load
duke
parents:
diff changeset
360 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
361 op = X86Registers.getRegister16(operandType - EAX);
a61af66fc99e Initial load
duke
parents:
diff changeset
362 }
a61af66fc99e Initial load
duke
parents:
diff changeset
363 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
364 case AX:
a61af66fc99e Initial load
duke
parents:
diff changeset
365 case CX:
a61af66fc99e Initial load
duke
parents:
diff changeset
366 case DX:
a61af66fc99e Initial load
duke
parents:
diff changeset
367 case BX:
a61af66fc99e Initial load
duke
parents:
diff changeset
368 case SP:
a61af66fc99e Initial load
duke
parents:
diff changeset
369 case BP:
a61af66fc99e Initial load
duke
parents:
diff changeset
370 case SI:
a61af66fc99e Initial load
duke
parents:
diff changeset
371 case DI:
a61af66fc99e Initial load
duke
parents:
diff changeset
372 op = X86Registers.getRegister16(operandType - AX);
a61af66fc99e Initial load
duke
parents:
diff changeset
373 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
374 case AL:
a61af66fc99e Initial load
duke
parents:
diff changeset
375 case CL:
a61af66fc99e Initial load
duke
parents:
diff changeset
376 case DL:
a61af66fc99e Initial load
duke
parents:
diff changeset
377 case BL:
a61af66fc99e Initial load
duke
parents:
diff changeset
378 case AH:
a61af66fc99e Initial load
duke
parents:
diff changeset
379 case CH:
a61af66fc99e Initial load
duke
parents:
diff changeset
380 case DH:
a61af66fc99e Initial load
duke
parents:
diff changeset
381 case BH:
a61af66fc99e Initial load
duke
parents:
diff changeset
382 op = X86Registers.getRegister8(operandType - AL);
a61af66fc99e Initial load
duke
parents:
diff changeset
383 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
384 case ES: //ES, CS, SS, DS, FS, GS
a61af66fc99e Initial load
duke
parents:
diff changeset
385 case CS:
a61af66fc99e Initial load
duke
parents:
diff changeset
386 case SS:
a61af66fc99e Initial load
duke
parents:
diff changeset
387 case DS:
a61af66fc99e Initial load
duke
parents:
diff changeset
388 case FS:
a61af66fc99e Initial load
duke
parents:
diff changeset
389 case GS:
a61af66fc99e Initial load
duke
parents:
diff changeset
390 op = X86SegmentRegisters.getSegmentRegister(operandType - ES);
a61af66fc99e Initial load
duke
parents:
diff changeset
391 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
392 }
a61af66fc99e Initial load
duke
parents:
diff changeset
393 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
394 case ADDR_DIR: //segment and offset
a61af66fc99e Initial load
duke
parents:
diff changeset
395 long segment = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
396 long offset = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
397 switch (operandType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
398 case p_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
399 if (addrSize == true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
400 offset = readInt32(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
401 byteIndex += 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
402 segment = readInt16(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
403 byteIndex += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
404 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
405 offset = readInt16(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
406 byteIndex += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
407 segment = readInt16(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
408 byteIndex += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
409 }
a61af66fc99e Initial load
duke
parents:
diff changeset
410 op = new X86DirectAddress(segment, offset); //with offset
a61af66fc99e Initial load
duke
parents:
diff changeset
411 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
412 case v_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
413 if (addrSize == true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
414 offset = readInt32(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
415 byteIndex += 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
416 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
417 offset = readInt16(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
418 byteIndex += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
419 }
a61af66fc99e Initial load
duke
parents:
diff changeset
420 op = new X86DirectAddress(offset); //with offset
a61af66fc99e Initial load
duke
parents:
diff changeset
421 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
422 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
423 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
424 }
a61af66fc99e Initial load
duke
parents:
diff changeset
425 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
426 case ADDR_G:
a61af66fc99e Initial load
duke
parents:
diff changeset
427 switch (operandType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
428 case b_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
429 op = X86Registers.getRegister8(regOrOpcode);
a61af66fc99e Initial load
duke
parents:
diff changeset
430 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
431 case w_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
432 op = X86Registers.getRegister16(regOrOpcode);
a61af66fc99e Initial load
duke
parents:
diff changeset
433 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
434 case d_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
435 op = X86Registers.getRegister32(regOrOpcode);
a61af66fc99e Initial load
duke
parents:
diff changeset
436 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
437 case v_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
438 if (operandSize == true)
a61af66fc99e Initial load
duke
parents:
diff changeset
439 op = X86Registers.getRegister32(regOrOpcode);
a61af66fc99e Initial load
duke
parents:
diff changeset
440 else
a61af66fc99e Initial load
duke
parents:
diff changeset
441 op = X86Registers.getRegister16(regOrOpcode);
a61af66fc99e Initial load
duke
parents:
diff changeset
442 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
443 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
444 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
445 }
a61af66fc99e Initial load
duke
parents:
diff changeset
446 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
447 case ADDR_SEG:
a61af66fc99e Initial load
duke
parents:
diff changeset
448 op = X86SegmentRegisters.getSegmentRegister(regOrOpcode);
a61af66fc99e Initial load
duke
parents:
diff changeset
449 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
450 case ADDR_OFF:
a61af66fc99e Initial load
duke
parents:
diff changeset
451 int off = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
452 if (addrSize == true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
453 off = readInt32(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
454 byteIndex += 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
455 }
a61af66fc99e Initial load
duke
parents:
diff changeset
456 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
457 off = readInt16(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
458 byteIndex += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
459 }
a61af66fc99e Initial load
duke
parents:
diff changeset
460 op = new X86DirectAddress((long)off);
a61af66fc99e Initial load
duke
parents:
diff changeset
461 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
462 case ADDR_J:
a61af66fc99e Initial load
duke
parents:
diff changeset
463 long disp = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
464 //The effective address is Instruction pointer + relative offset
a61af66fc99e Initial load
duke
parents:
diff changeset
465 switch(operandType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
466 case b_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
467 disp = (byte)readByte(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
468 byteIndex++;
a61af66fc99e Initial load
duke
parents:
diff changeset
469 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
470 case v_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
471 if (operandSize == true) {
a61af66fc99e Initial load
duke
parents:
diff changeset
472 disp = readInt32(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
473 byteIndex += 4;
a61af66fc99e Initial load
duke
parents:
diff changeset
474 }
a61af66fc99e Initial load
duke
parents:
diff changeset
475 else {
a61af66fc99e Initial load
duke
parents:
diff changeset
476 disp = readInt16(bytesArray, byteIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
477 byteIndex += 2;
a61af66fc99e Initial load
duke
parents:
diff changeset
478 }
a61af66fc99e Initial load
duke
parents:
diff changeset
479 //disp = disp + (byteIndex-instrStartIndex);
a61af66fc99e Initial load
duke
parents:
diff changeset
480 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
481 }
a61af66fc99e Initial load
duke
parents:
diff changeset
482 op = new X86PCRelativeAddress(disp);
a61af66fc99e Initial load
duke
parents:
diff changeset
483 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
484 case ADDR_ESDI:
a61af66fc99e Initial load
duke
parents:
diff changeset
485 op = new X86SegmentRegisterAddress(X86SegmentRegisters.ES, X86Registers.DI);
a61af66fc99e Initial load
duke
parents:
diff changeset
486 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
487 case ADDR_DSSI:
a61af66fc99e Initial load
duke
parents:
diff changeset
488 op = new X86SegmentRegisterAddress(X86SegmentRegisters.DS, X86Registers.SI);
a61af66fc99e Initial load
duke
parents:
diff changeset
489 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
490 case ADDR_R:
a61af66fc99e Initial load
duke
parents:
diff changeset
491 switch (operandType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
492 case b_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
493 op = X86Registers.getRegister8(mod);
a61af66fc99e Initial load
duke
parents:
diff changeset
494 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
495 case w_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
496 op = X86Registers.getRegister16(mod);
a61af66fc99e Initial load
duke
parents:
diff changeset
497 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
498 case d_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
499 op = X86Registers.getRegister32(mod);
a61af66fc99e Initial load
duke
parents:
diff changeset
500 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
501 case v_mode:
a61af66fc99e Initial load
duke
parents:
diff changeset
502 if (operandSize == true)
a61af66fc99e Initial load
duke
parents:
diff changeset
503 op = X86Registers.getRegister32(mod);
a61af66fc99e Initial load
duke
parents:
diff changeset
504 else
a61af66fc99e Initial load
duke
parents:
diff changeset
505 op = X86Registers.getRegister16(mod);
a61af66fc99e Initial load
duke
parents:
diff changeset
506 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
507 default:
a61af66fc99e Initial load
duke
parents:
diff changeset
508 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
509 }
a61af66fc99e Initial load
duke
parents:
diff changeset
510 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
511 case ADDR_FPREG:
a61af66fc99e Initial load
duke
parents:
diff changeset
512 switch (operandType) {
a61af66fc99e Initial load
duke
parents:
diff changeset
513 case 0:
a61af66fc99e Initial load
duke
parents:
diff changeset
514 op = X86FloatRegisters.getRegister(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
515 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
516 case 1:
a61af66fc99e Initial load
duke
parents:
diff changeset
517 op = X86FloatRegisters.getRegister(rm);
a61af66fc99e Initial load
duke
parents:
diff changeset
518 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
519 }
a61af66fc99e Initial load
duke
parents:
diff changeset
520 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
521
a61af66fc99e Initial load
duke
parents:
diff changeset
522 //SSE: reg field of ModR/M byte selects a 128-bit XMM register
a61af66fc99e Initial load
duke
parents:
diff changeset
523 case ADDR_V:
a61af66fc99e Initial load
duke
parents:
diff changeset
524 op = X86XMMRegisters.getRegister(regOrOpcode);
a61af66fc99e Initial load
duke
parents:
diff changeset
525 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
526
a61af66fc99e Initial load
duke
parents:
diff changeset
527 //SSE: reg field of ModR/M byte selects a 64-bit MMX register
a61af66fc99e Initial load
duke
parents:
diff changeset
528 case ADDR_P:
a61af66fc99e Initial load
duke
parents:
diff changeset
529 op = X86MMXRegisters.getRegister(regOrOpcode);
a61af66fc99e Initial load
duke
parents:
diff changeset
530 break;
a61af66fc99e Initial load
duke
parents:
diff changeset
531 }
a61af66fc99e Initial load
duke
parents:
diff changeset
532 return op;
a61af66fc99e Initial load
duke
parents:
diff changeset
533 }
a61af66fc99e Initial load
duke
parents:
diff changeset
534
a61af66fc99e Initial load
duke
parents:
diff changeset
535 private X86SegmentRegister getSegmentRegisterFromPrefix(int prefixes) {
a61af66fc99e Initial load
duke
parents:
diff changeset
536 X86SegmentRegister segRegister = null;
a61af66fc99e Initial load
duke
parents:
diff changeset
537
a61af66fc99e Initial load
duke
parents:
diff changeset
538 if ( (prefixes & PREFIX_CS) != 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
539 segRegister = X86SegmentRegisters.CS;
a61af66fc99e Initial load
duke
parents:
diff changeset
540 if ( (prefixes & PREFIX_DS) != 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
541 segRegister = X86SegmentRegisters.DS;
a61af66fc99e Initial load
duke
parents:
diff changeset
542 if ( (prefixes & PREFIX_ES) != 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
543 segRegister = X86SegmentRegisters.ES;
a61af66fc99e Initial load
duke
parents:
diff changeset
544 if ( (prefixes & PREFIX_FS) != 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
545 segRegister = X86SegmentRegisters.FS;
a61af66fc99e Initial load
duke
parents:
diff changeset
546 if ( (prefixes & PREFIX_SS) != 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
547 segRegister = X86SegmentRegisters.SS;
a61af66fc99e Initial load
duke
parents:
diff changeset
548 if ( (prefixes & PREFIX_GS) != 0)
a61af66fc99e Initial load
duke
parents:
diff changeset
549 segRegister = X86SegmentRegisters.GS;
a61af66fc99e Initial load
duke
parents:
diff changeset
550
a61af66fc99e Initial load
duke
parents:
diff changeset
551 return segRegister;
a61af66fc99e Initial load
duke
parents:
diff changeset
552 }
a61af66fc99e Initial load
duke
parents:
diff changeset
553
a61af66fc99e Initial load
duke
parents:
diff changeset
554 }