blob: 23cee141e6e9c0577fc8b32e533b6ae599deced8 [file] [log] [blame]
buzbeee88dfbf2012-03-05 11:19:57 -08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
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#include "../../CompilerInternals.h"
18#include "X86LIR.h"
19#include "../Ralloc.h"
20
21#include <string>
22
23namespace art {
24
25/* For dumping instructions */
26#define X86_REG_COUNT 16
27static const char *x86RegName[X86_REG_COUNT] = {
28 "rax", "rcx", "rdx", "rbx", "rsp", "rbp", "rsi", "rdi",
29 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15"
30};
31
32/*
33 * Interpret a format string and build a string no longer than size
34 * See format key in Assemble.c.
35 */
36std::string buildInsnString(const char *fmt, LIR *lir, unsigned char* baseAddr)
37{
buzbeee88dfbf2012-03-05 11:19:57 -080038 std::string buf;
39 int i;
40 const char *fmtEnd = &fmt[strlen(fmt)];
41 char tbuf[256];
42 char nc;
43 while (fmt < fmtEnd) {
44 int operand;
45 if (*fmt == '!') {
46 fmt++;
47 DCHECK_LT(fmt, fmtEnd);
48 nc = *fmt++;
49 if (nc=='!') {
50 strcpy(tbuf, "!");
51 } else {
52 DCHECK_LT(fmt, fmtEnd);
53 DCHECK_LT((unsigned)(nc-'0'), 4u);
54 operand = lir->operands[nc-'0'];
55 switch(*fmt++) {
56 case 'b':
57 strcpy(tbuf,"0000");
58 for (i=3; i>= 0; i--) {
59 tbuf[i] += operand & 1;
60 operand >>= 1;
61 }
62 break;
63 case 's':
64 sprintf(tbuf,"$f%d",operand & FP_REG_MASK);
65 break;
66 case 'S':
67 DCHECK_EQ(((operand & FP_REG_MASK) & 1), 0);
68 sprintf(tbuf,"$f%d",operand & FP_REG_MASK);
69 break;
70 case 'h':
71 sprintf(tbuf,"%04x", operand);
72 break;
73 case 'M':
74 case 'd':
75 sprintf(tbuf,"%d", operand);
76 break;
77 case 'D':
78 sprintf(tbuf,"%d", operand+1);
79 break;
80 case 'E':
81 sprintf(tbuf,"%d", operand*4);
82 break;
83 case 'F':
84 sprintf(tbuf,"%d", operand*2);
85 break;
86 case 't':
87 sprintf(tbuf,"0x%08x (L%p)",
88 (int) baseAddr + lir->offset + 4 +
89 (operand << 2),
90 lir->target);
91 break;
92 case 'T':
93 sprintf(tbuf,"0x%08x",
94 (int) (operand << 2));
95 break;
96 case 'u': {
97 int offset_1 = lir->operands[0];
98 int offset_2 = NEXT_LIR(lir)->operands[0];
99 intptr_t target =
100 ((((intptr_t) baseAddr + lir->offset + 4) &
101 ~3) + (offset_1 << 21 >> 9) + (offset_2 << 1)) &
102 0xfffffffc;
103 sprintf(tbuf, "%p", (void *) target);
104 break;
105 }
106
107 /* Nothing to print for BLX_2 */
108 case 'v':
109 strcpy(tbuf, "see above");
110 break;
111 case 'r':
buzbeea7678db2012-03-05 15:35:46 -0800112 DCHECK(operand >= 0 && operand < X86_REG_COUNT);
113 strcpy(tbuf, x86RegName[operand]);
buzbeee88dfbf2012-03-05 11:19:57 -0800114 break;
115 case 'N':
116 // Placeholder for delay slot handling
117 strcpy(tbuf, "; nop");
118 break;
119 default:
120 strcpy(tbuf,"DecodeError");
121 break;
122 }
123 buf += tbuf;
124 }
125 } else {
126 buf += *fmt++;
127 }
128 }
129 return buf;
buzbeee88dfbf2012-03-05 11:19:57 -0800130}
131
132void oatDumpResourceMask(LIR *lir, u8 mask, const char *prefix)
133{
buzbeee88dfbf2012-03-05 11:19:57 -0800134 char buf[256];
135 buf[0] = 0;
buzbeea7678db2012-03-05 15:35:46 -0800136 LIR *x86LIR = (LIR *) lir;
buzbeee88dfbf2012-03-05 11:19:57 -0800137
138 if (mask == ENCODE_ALL) {
139 strcpy(buf, "all");
140 } else {
141 char num[8];
142 int i;
143
144 for (i = 0; i < kRegEnd; i++) {
145 if (mask & (1ULL << i)) {
146 sprintf(num, "%d ", i);
147 strcat(buf, num);
148 }
149 }
150
151 if (mask & ENCODE_CCODE) {
152 strcat(buf, "cc ");
153 }
buzbeee88dfbf2012-03-05 11:19:57 -0800154 /* Memory bits */
buzbeea7678db2012-03-05 15:35:46 -0800155 if (x86LIR && (mask & ENCODE_DALVIK_REG)) {
156 sprintf(buf + strlen(buf), "dr%d%s", x86LIR->aliasInfo & 0xffff,
157 (x86LIR->aliasInfo & 0x80000000) ? "(+1)" : "");
buzbeee88dfbf2012-03-05 11:19:57 -0800158 }
159 if (mask & ENCODE_LITERAL) {
160 strcat(buf, "lit ");
161 }
162
163 if (mask & ENCODE_HEAP_REF) {
164 strcat(buf, "heap ");
165 }
166 if (mask & ENCODE_MUST_NOT_ALIAS) {
167 strcat(buf, "noalias ");
168 }
169 }
170 if (buf[0]) {
171 LOG(INFO) << prefix << ": " << buf;
172 }
buzbeee88dfbf2012-03-05 11:19:57 -0800173}
174
175} // namespace art