blob: 87a13554fb62c289d599002b71b9d07c38c1b93e [file] [log] [blame]
jeffhao7fbee072012-08-24 17:56:54 -07001/*
jeffhaoc0228b82012-08-29 18:15:05 -07002 * Copyright (C) 2012 The Android Open Source Project
jeffhao7fbee072012-08-24 17:56:54 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_SRC_CONSTANTS_MIPS_H_
18#define ART_SRC_CONSTANTS_MIPS_H_
19
20#include <iosfwd>
Elliott Hughes07ed66b2012-12-12 18:34:25 -080021
22#include "base/logging.h"
Elliott Hughes76160052012-12-12 16:31:20 -080023#include "base/macros.h"
jeffhao7fbee072012-08-24 17:56:54 -070024#include "globals.h"
jeffhao7fbee072012-08-24 17:56:54 -070025
26namespace art {
27namespace mips {
28
29enum Register {
30 ZERO = 0,
Mathieu Chartier67022432012-11-29 18:04:50 -080031 AT = 1, // Assembler temporary.
32 V0 = 2, // Values.
jeffhao7fbee072012-08-24 17:56:54 -070033 V1 = 3,
Mathieu Chartier67022432012-11-29 18:04:50 -080034 A0 = 4, // Arguments.
jeffhao7fbee072012-08-24 17:56:54 -070035 A1 = 5,
36 A2 = 6,
37 A3 = 7,
Mathieu Chartier67022432012-11-29 18:04:50 -080038 T0 = 8, // Temporaries.
jeffhao7fbee072012-08-24 17:56:54 -070039 T1 = 9,
40 T2 = 10,
41 T3 = 11,
42 T4 = 12,
43 T5 = 13,
44 T6 = 14,
45 T7 = 15,
Mathieu Chartier67022432012-11-29 18:04:50 -080046 S0 = 16, // Saved values.
jeffhao7fbee072012-08-24 17:56:54 -070047 S1 = 17,
48 S2 = 18,
49 S3 = 19,
50 S4 = 20,
51 S5 = 21,
52 S6 = 22,
53 S7 = 23,
Mathieu Chartier67022432012-11-29 18:04:50 -080054 T8 = 24, // More temporaries.
jeffhao7fbee072012-08-24 17:56:54 -070055 T9 = 25,
Mathieu Chartier67022432012-11-29 18:04:50 -080056 K0 = 26, // Reserved for trap handler.
jeffhao7fbee072012-08-24 17:56:54 -070057 K1 = 27,
Mathieu Chartier67022432012-11-29 18:04:50 -080058 GP = 28, // Global pointer.
59 SP = 29, // Stack pointer.
60 FP = 30, // Saved value/frame pointer.
61 RA = 31, // Return address.
jeffhao7fbee072012-08-24 17:56:54 -070062 kNumberOfCoreRegisters = 32,
63 kNoRegister = -1 // Signals an illegal register.
64};
65std::ostream& operator<<(std::ostream& os, const Register& rhs);
66
67// Values for single-precision floating point registers.
68enum FRegister {
69 F0 = 0,
70 F1 = 1,
71 F2 = 2,
72 F3 = 3,
73 F4 = 4,
74 F5 = 5,
75 F6 = 6,
76 F7 = 7,
77 F8 = 8,
78 F9 = 9,
79 F10 = 10,
80 F11 = 11,
81 F12 = 12,
82 F13 = 13,
83 F14 = 14,
84 F15 = 15,
85 F16 = 16,
86 F17 = 17,
87 F18 = 18,
88 F19 = 19,
89 F20 = 20,
90 F21 = 21,
91 F22 = 22,
92 F23 = 23,
93 F24 = 24,
94 F25 = 25,
95 F26 = 26,
96 F27 = 27,
97 F28 = 28,
98 F29 = 29,
99 F30 = 30,
100 F31 = 31,
101 kNumberOfFRegisters = 32,
102 kNoFRegister = -1,
103};
104std::ostream& operator<<(std::ostream& os, const FRegister& rhs);
105
106// Values for double-precision floating point registers.
107enum DRegister {
108 D0 = 0,
109 D1 = 1,
110 D2 = 2,
111 D3 = 3,
112 D4 = 4,
113 D5 = 5,
114 D6 = 6,
115 D7 = 7,
116 D8 = 8,
117 D9 = 9,
118 D10 = 10,
119 D11 = 11,
120 D12 = 12,
121 D13 = 13,
122 D14 = 14,
123 D15 = 15,
124 kNumberOfDRegisters = 16,
125 kNumberOfOverlappingDRegisters = 16,
126 kNoDRegister = -1,
127};
128std::ostream& operator<<(std::ostream& os, const DRegister& rhs);
129
130// Constants used for the decoding or encoding of the individual fields of instructions.
131enum InstructionFields {
132 kOpcodeShift = 26,
133 kOpcodeBits = 6,
134 kRsShift = 21,
135 kRsBits = 5,
136 kRtShift = 16,
137 kRtBits = 5,
138 kRdShift = 11,
139 kRdBits = 5,
140 kShamtShift = 6,
141 kShamtBits = 5,
142 kFunctShift = 0,
143 kFunctBits = 6,
144
145 kFmtShift = 21,
146 kFmtBits = 5,
147 kFtShift = 16,
148 kFtBits = 5,
149 kFsShift = 11,
150 kFsBits = 5,
151 kFdShift = 6,
152 kFdBits = 5,
153
154 kBranchOffsetMask = 0x0000ffff,
155 kJumpOffsetMask = 0x03ffffff,
156};
157
158enum ScaleFactor {
159 TIMES_1 = 0,
160 TIMES_2 = 1,
161 TIMES_4 = 2,
162 TIMES_8 = 3
163};
164
165class Instr {
166 public:
167 static const uint32_t kBreakPointInstruction = 0x0000000D;
168
169 bool IsBreakPoint() {
170 return ((*reinterpret_cast<const uint32_t*>(this)) & 0xFC0000CF) == kBreakPointInstruction;
171 }
172
173 // Instructions are read out of a code stream. The only way to get a
174 // reference to an instruction is to convert a pointer. There is no way
175 // to allocate or create instances of class Instr.
176 // Use the At(pc) function to create references to Instr.
177 static Instr* At(uintptr_t pc) { return reinterpret_cast<Instr*>(pc); }
178
179 private:
180 DISALLOW_IMPLICIT_CONSTRUCTORS(Instr);
181};
182
183} // namespace mips
184} // namespace art
185
186#endif // ART_SRC_CONSTANTS_MIPS_H_