OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_CONSTANTS_MIPS_H_ | 5 #ifndef VM_CONSTANTS_MIPS_H_ |
6 #define VM_CONSTANTS_MIPS_H_ | 6 #define VM_CONSTANTS_MIPS_H_ |
7 | 7 |
8 namespace dart { | 8 namespace dart { |
9 | 9 |
10 enum Register { | 10 enum Register { |
11 ZR = 0, | 11 R0 = 0, |
12 AT = 1, | 12 R1 = 1, |
13 kFirstFreeCpuRegister = 2, | 13 kFirstFreeCpuRegister = 2, |
14 V0 = 2, | 14 R2 = 2, |
15 V1 = 3, | 15 R3 = 3, |
16 A0 = 4, | 16 R4 = 4, |
17 A1 = 5, | 17 R5 = 5, |
18 A2 = 6, | 18 R6 = 6, |
19 A3 = 7, | 19 R7 = 7, |
20 T0 = 8, | 20 R8 = 8, |
21 T1 = 9, | 21 R9 = 9, |
22 T2 = 10, | 22 R10 = 10, |
23 T3 = 11, | 23 R11 = 11, |
24 T4 = 12, | 24 R12 = 12, |
25 T5 = 13, | 25 R13 = 13, |
26 T6 = 14, | 26 R14 = 14, |
27 T7 = 15, | 27 R15 = 15, |
28 S0 = 16, | 28 R16 = 16, |
29 S1 = 17, | 29 R17 = 17, |
30 S2 = 18, | 30 R18 = 18, |
31 S3 = 19, | 31 R19 = 19, |
32 S4 = 20, | 32 R20 = 20, |
33 S5 = 21, | 33 R21 = 21, |
34 S6 = 22, | 34 R22 = 22, |
35 S7 = 23, | 35 R23 = 23, |
36 T8 = 24, | 36 R24 = 24, |
37 T9 = 25, | 37 R25 = 25, |
38 kLastFreeCpuRegister = 25, | 38 kLastFreeCpuRegister = 25, |
39 K0 = 26, | 39 R26 = 26, |
40 K1 = 27, | 40 R27 = 27, |
41 GP = 28, | 41 R28 = 28, |
42 SP = 29, | 42 R29 = 29, |
43 FP = 30, | 43 R30 = 30, |
44 RA = 31, | 44 R31 = 31, |
45 kNumberOfCpuRegisters = 32, | 45 kNumberOfCpuRegisters = 32, |
46 kNoRegister = -1, | 46 kNoRegister = -1, |
47 | |
48 // Register aliases. | |
49 ZR = R0, | |
50 AT = R1, | |
51 V0 = R2, | |
52 V1 = R3, | |
53 A0 = R4, | |
54 A1 = R5, | |
55 A2 = R6, | |
56 A3 = R7, | |
57 T0 = R8, | |
58 T1 = R9, | |
59 T2 = R10, | |
60 T3 = R11, | |
61 T4 = R12, | |
62 T5 = R13, | |
63 T6 = R14, | |
64 T7 = R15, | |
65 S0 = R16, | |
66 S1 = R17, | |
67 S3 = R18, | |
68 S4 = R19, | |
69 S5 = R20, | |
70 S6 = R21, | |
71 S7 = R22, | |
72 T8 = R24, | |
73 T9 = R25, | |
74 K0 = R26, | |
75 K1 = R27, | |
76 GP = R28, | |
77 SP = R29, | |
78 FP = R30, | |
79 RA = R31, | |
47 }; | 80 }; |
48 | 81 |
49 | 82 |
50 // Values for double-precision floating point registers. | 83 // Values for double-precision floating point registers. |
51 enum FRegister { | 84 enum FRegister { |
52 F0 = 0, | 85 F0 = 0, |
53 F1 = 1, | 86 F1 = 1, |
54 F2 = 2, | 87 F2 = 2, |
55 F3 = 3, | 88 F3 = 3, |
56 F4 = 4, | 89 F4 = 4, |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 const Register SPREG = SP; // Stack pointer register. | 132 const Register SPREG = SP; // Stack pointer register. |
100 const Register FPREG = FP; // Frame pointer register. | 133 const Register FPREG = FP; // Frame pointer register. |
101 | 134 |
102 | 135 |
103 // Values for the condition field. // UNIMPLEMENTED. | 136 // Values for the condition field. // UNIMPLEMENTED. |
104 enum Condition { | 137 enum Condition { |
105 kNoCondition = -1, | 138 kNoCondition = -1, |
106 kMaxCondition = 16, | 139 kMaxCondition = 16, |
107 }; | 140 }; |
108 | 141 |
142 | |
143 // Constants used for the decoding or encoding of the individual fields of | |
144 // instructions. Based on the "Table 4.25 CPU Instruction Format Fields". | |
145 enum InstructionFields { | |
146 kOpcodeShift = 26, | |
147 kOpcodeBits = 6, | |
148 kRsShift = 21, | |
149 kRsBits = 5, | |
150 kRtShift = 16, | |
151 kRtBits = 5, | |
152 kRdShift = 11, | |
153 kRdBits = 5, | |
154 kSaShift = 6, | |
155 kSaBits = 5, | |
156 kFunctionShift = 0, | |
157 kFunctionBits = 6, | |
158 kImmShift = 0, | |
159 kImmBits = 16, | |
160 kInstrShift = 0, | |
161 kInstrBits = 26, | |
162 }; | |
163 | |
164 | |
165 enum Opcode { | |
166 SPECIAL = 0, | |
167 REGIMM = 1, | |
168 J = 2, | |
169 JAL = 3, | |
170 BEQ = 4, | |
171 BNE = 5, | |
172 BLEZ = 6, | |
173 BGTZ = 7, | |
174 ADDI = 8, | |
175 ADDIU = 9, | |
176 SLTI = 10, | |
177 SLTIU = 11, | |
178 ANDI = 12, | |
179 ORI = 13, | |
180 XORI = 14, | |
181 LUI = 15, | |
182 CPO0 = 16, | |
183 COP1 = 17, | |
184 COP2 = 18, | |
185 COP1X = 19, | |
186 BEQL = 20, | |
187 BNEL = 21, | |
188 BLEZL = 22, | |
189 BGTZL = 23, | |
190 SPECIAL2 = 28, | |
191 JALX = 29, | |
192 SPECIAL3 = 31, | |
193 LB = 32, | |
194 LH = 33, | |
195 LWL = 34, | |
196 LW = 35, | |
197 LBU = 36, | |
198 LHU = 37, | |
199 LWR = 38, | |
200 SB = 40, | |
201 SH = 41, | |
202 SWL = 42, | |
203 SW = 43, | |
204 SWR = 46, | |
205 CACHE = 47, | |
206 LL = 48, | |
207 LWC1 = 49, | |
208 LWC2 = 50, | |
209 PREF = 51, | |
210 LDC1 = 53, | |
211 LDC2 = 54, | |
212 SC = 56, | |
213 SWC1 = 57, | |
214 SWC2 = 58, | |
215 SDC1 = 61, | |
216 SDC2 = 62, | |
217 }; | |
218 | |
219 | |
220 enum SpecialFunction { | |
221 SLL = 0, | |
222 MOVCI = 1, | |
223 SRL = 2, | |
224 SRA = 3, | |
225 SLLV = 4, | |
226 SRLV = 6, | |
227 SRAV = 7, | |
228 JR = 8, | |
229 JALR = 9, | |
230 MOVZ = 10, | |
231 MOVN = 11, | |
232 SYSCALL = 12, | |
233 BREAK = 13, | |
234 SYNC = 15, | |
235 MFHI, | |
regis
2013/03/06 21:18:42
= 16
etc...
Ivan Posva
2013/03/07 11:03:22
Done. I wasn't sure which one is more readable. I
regis
2013/03/07 17:56:57
It looks like you forgot to upload before committi
| |
236 MTHI, | |
237 MFLO, | |
238 MTLO, | |
239 MULT = 24, | |
240 MUTLU, | |
241 DIV, | |
242 DIVU, | |
243 ADD = 32, | |
244 ADDU, | |
245 SUB, | |
246 SUBU, | |
247 AND, | |
248 OR, | |
249 XOR, | |
250 NOR, | |
251 SLT = 42, | |
252 SLTU, | |
253 TGE = 48, | |
254 TGEU, | |
255 TLT, | |
256 TLTU, | |
257 TEQ, | |
258 TNE = 54, | |
259 }; | |
260 | |
261 | |
262 enum RtRegImm { | |
263 BLTZ = 0, | |
264 BGEZ, | |
regis
2013/03/06 21:18:42
fill in enum values
Ivan Posva
2013/03/07 11:03:22
Done.
| |
265 BLTZL, | |
266 BGEZL, | |
267 TGEI = 8, | |
268 TGEIU, | |
269 TLTI, | |
270 TLTIU, | |
271 TEQI, | |
272 TNEI = 14, | |
273 BLTZAL = 16, | |
274 BGEZAL, | |
275 BLTZALL, | |
276 BGEZALL, | |
277 SYNCI = 31, | |
278 }; | |
279 | |
280 | |
281 class Instr { | |
282 public: | |
283 enum { | |
284 kInstrSize = 4, | |
285 }; | |
286 | |
287 static const int32_t kBreakPointInstruction = | |
288 (SPECIAL << kOpcodeShift) | (BREAK << kFunctionShift); | |
289 | |
290 // Get the raw instruction bits. | |
291 inline int32_t InstructionBits() const { | |
292 return reinterpret_cast<int32_t>(this); | |
293 } | |
294 | |
295 // Read one particular bit out of the instruction bits. | |
296 inline int Bit(int nr) const { | |
297 return (InstructionBits() >> nr) & 1; | |
298 } | |
299 | |
300 // Read a bit field out of the instruction bits. | |
301 inline int Bits(int shift, int count) const { | |
302 return (InstructionBits() >> shift) & ((1 << count) - 1); | |
303 } | |
304 | |
305 // Accessors to the different named fields used in the MIPS encoding. | |
306 inline Opcode OpcodeField() const { | |
307 return static_cast<Opcode>(Bits(kOpcodeShift, kOpcodeBits)); | |
308 } | |
309 | |
310 inline Register RsField() const { | |
311 return static_cast<Register>(Bits(kRsShift, kRsBits)); | |
312 } | |
313 | |
314 inline Register RtField() const { | |
315 return static_cast<Register>(Bits(kRtShift, kRtBits)); | |
316 } | |
317 | |
318 inline Register RdField() const { | |
319 return static_cast<Register>(Bits(kRdShift, kRdBits)); | |
320 } | |
321 | |
322 inline int SaField() const { | |
323 return Bits(kSaShift, kSaBits); | |
324 } | |
325 | |
326 inline int32_t ImmField() const { | |
327 return static_cast<int32_t>(Bits(kImmShift, kImmBits)); | |
328 } | |
329 | |
330 inline SpecialFunction FunctionField() const { | |
331 return static_cast<SpecialFunction>(Bits(kFunctionShift, kFunctionBits)); | |
332 } | |
333 | |
334 // Instructions are read out of a code stream. The only way to get a | |
335 // reference to an instruction is to convert a pc. There is no way | |
336 // to allocate or create instances of class Instr. | |
337 // Use the At(pc) function to create references to Instr. | |
338 static Instr* At(uword pc) { | |
339 return reinterpret_cast<Instr*>(*reinterpret_cast<int32_t*>(pc)); | |
340 } | |
341 | |
342 private: | |
343 DISALLOW_ALLOCATION(); | |
344 DISALLOW_IMPLICIT_CONSTRUCTORS(Instr); | |
345 }; | |
346 | |
109 } // namespace dart | 347 } // namespace dart |
110 | 348 |
111 #endif // VM_CONSTANTS_MIPS_H_ | 349 #endif // VM_CONSTANTS_MIPS_H_ |
OLD | NEW |