1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "../../CompilerInternals.h"
#include "MipsLIR.h"
#include "../Ralloc.h"
#include <string>
namespace art {
RegLocation locCReturn()
{
RegLocation res = MIPS_LOC_C_RETURN;
return res;
}
RegLocation locCReturnWide()
{
RegLocation res = MIPS_LOC_C_RETURN_WIDE;
return res;
}
RegLocation locCReturnFloat()
{
RegLocation res = MIPS_LOC_C_RETURN_FLOAT;
return res;
}
RegLocation locCReturnDouble()
{
RegLocation res = MIPS_LOC_C_RETURN_DOUBLE;
return res;
}
// Return a target-dependent special register.
int targetReg(SpecialTargetRegister reg) {
int res = INVALID_REG;
switch (reg) {
case kSelf: res = rMIPS_SELF; break;
case kSuspend: res = rMIPS_SUSPEND; break;
case kLr: res = rMIPS_LR; break;
case kPc: res = rMIPS_PC; break;
case kSp: res = rMIPS_SP; break;
case kArg0: res = rMIPS_ARG0; break;
case kArg1: res = rMIPS_ARG1; break;
case kArg2: res = rMIPS_ARG2; break;
case kArg3: res = rMIPS_ARG3; break;
case kFArg0: res = rMIPS_FARG0; break;
case kFArg1: res = rMIPS_FARG1; break;
case kFArg2: res = rMIPS_FARG2; break;
case kFArg3: res = rMIPS_FARG3; break;
case kRet0: res = rMIPS_RET0; break;
case kRet1: res = rMIPS_RET1; break;
case kInvokeTgt: res = rMIPS_INVOKE_TGT; break;
case kCount: res = rMIPS_COUNT; break;
}
return res;
}
// Create a double from a pair of singles.
int s2d(int lowReg, int highReg)
{
return MIPS_S2D(lowReg, highReg);
}
// Is reg a single or double?
bool fpReg(int reg)
{
return MIPS_FPREG(reg);
}
// Is reg a single?
bool singleReg(int reg)
{
return MIPS_SINGLEREG(reg);
}
// Is reg a double?
bool doubleReg(int reg)
{
return MIPS_DOUBLEREG(reg);
}
// Return mask to strip off fp reg flags and bias.
uint32_t fpRegMask()
{
return MIPS_FP_REG_MASK;
}
// True if both regs single, both core or both double.
bool sameRegType(int reg1, int reg2)
{
return (MIPS_REGTYPE(reg1) == MIPS_REGTYPE(reg2));
}
/*
* Decode the register id.
*/
u8 getRegMaskCommon(CompilationUnit* cUnit, int reg)
{
u8 seed;
int shift;
int regId;
regId = reg & 0x1f;
/* Each double register is equal to a pair of single-precision FP registers */
seed = MIPS_DOUBLEREG(reg) ? 3 : 1;
/* FP register starts at bit position 16 */
shift = MIPS_FPREG(reg) ? kMipsFPReg0 : 0;
/* Expand the double register id into single offset */
shift += regId;
return (seed << shift);
}
uint64_t getPCUseDefEncoding()
{
return ENCODE_MIPS_REG_PC;
}
void setupTargetResourceMasks(CompilationUnit* cUnit, LIR* lir)
{
DCHECK_EQ(cUnit->instructionSet, kMips);
// Mips-specific resource map setup here.
uint64_t flags = EncodingMap[lir->opcode].flags;
if (flags & REG_DEF_SP) {
lir->defMask |= ENCODE_MIPS_REG_SP;
}
if (flags & REG_USE_SP) {
lir->useMask |= ENCODE_MIPS_REG_SP;
}
if (flags & REG_DEF_LR) {
lir->defMask |= ENCODE_MIPS_REG_LR;
}
}
/* For dumping instructions */
#define MIPS_REG_COUNT 32
static const char *mipsRegName[MIPS_REG_COUNT] = {
"zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
"t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
"s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
"t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra"
};
/*
* Interpret a format string and build a string no longer than size
* See format key in Assemble.c.
*/
std::string buildInsnString(const char *fmt, LIR *lir, unsigned char* baseAddr)
{
std::string buf;
int i;
const char *fmtEnd = &fmt[strlen(fmt)];
char tbuf[256];
char nc;
while (fmt < fmtEnd) {
int operand;
if (*fmt == '!') {
fmt++;
DCHECK_LT(fmt, fmtEnd);
nc = *fmt++;
if (nc=='!') {
strcpy(tbuf, "!");
} else {
DCHECK_LT(fmt, fmtEnd);
DCHECK_LT((unsigned)(nc-'0'), 4u);
operand = lir->operands[nc-'0'];
switch (*fmt++) {
case 'b':
strcpy(tbuf,"0000");
for (i=3; i>= 0; i--) {
tbuf[i] += operand & 1;
operand >>= 1;
}
break;
case 's':
sprintf(tbuf,"$f%d",operand & MIPS_FP_REG_MASK);
break;
case 'S':
DCHECK_EQ(((operand & MIPS_FP_REG_MASK) & 1), 0);
sprintf(tbuf,"$f%d",operand & MIPS_FP_REG_MASK);
break;
case 'h':
sprintf(tbuf,"%04x", operand);
break;
case 'M':
case 'd':
sprintf(tbuf,"%d", operand);
break;
case 'D':
sprintf(tbuf,"%d", operand+1);
break;
case 'E':
sprintf(tbuf,"%d", operand*4);
break;
case 'F':
sprintf(tbuf,"%d", operand*2);
break;
case 't':
sprintf(tbuf,"0x%08x (L%p)", (int) baseAddr + lir->offset + 4 +
(operand << 2), lir->target);
break;
case 'T':
sprintf(tbuf,"0x%08x", (int) (operand << 2));
break;
case 'u': {
int offset_1 = lir->operands[0];
int offset_2 = NEXT_LIR(lir)->operands[0];
intptr_t target =
((((intptr_t) baseAddr + lir->offset + 4) & ~3) +
(offset_1 << 21 >> 9) + (offset_2 << 1)) & 0xfffffffc;
sprintf(tbuf, "%p", (void *) target);
break;
}
/* Nothing to print for BLX_2 */
case 'v':
strcpy(tbuf, "see above");
break;
case 'r':
DCHECK(operand >= 0 && operand < MIPS_REG_COUNT);
strcpy(tbuf, mipsRegName[operand]);
break;
case 'N':
// Placeholder for delay slot handling
strcpy(tbuf, "; nop");
break;
default:
strcpy(tbuf,"DecodeError");
break;
}
buf += tbuf;
}
} else {
buf += *fmt++;
}
}
return buf;
}
// FIXME: need to redo resource maps for MIPS - fix this at that time
void oatDumpResourceMask(LIR *lir, u8 mask, const char *prefix)
{
char buf[256];
buf[0] = 0;
LIR *mipsLIR = (LIR *) lir;
if (mask == ENCODE_ALL) {
strcpy(buf, "all");
} else {
char num[8];
int i;
for (i = 0; i < kMipsRegEnd; i++) {
if (mask & (1ULL << i)) {
sprintf(num, "%d ", i);
strcat(buf, num);
}
}
if (mask & ENCODE_CCODE) {
strcat(buf, "cc ");
}
if (mask & ENCODE_FP_STATUS) {
strcat(buf, "fpcc ");
}
/* Memory bits */
if (mipsLIR && (mask & ENCODE_DALVIK_REG)) {
sprintf(buf + strlen(buf), "dr%d%s", mipsLIR->aliasInfo & 0xffff,
(mipsLIR->aliasInfo & 0x80000000) ? "(+1)" : "");
}
if (mask & ENCODE_LITERAL) {
strcat(buf, "lit ");
}
if (mask & ENCODE_HEAP_REF) {
strcat(buf, "heap ");
}
if (mask & ENCODE_MUST_NOT_ALIAS) {
strcat(buf, "noalias ");
}
}
if (buf[0]) {
LOG(INFO) << prefix << ": " << buf;
}
}
} // namespace art
|