2 * Copyright (C) 2009 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "../../CompilerInternals.h"
18 #include "dexdump/OpCodeNames.h"
21 /* Decode and print a ARM register name */
22 static char * decodeRegList(int vector, char *buf)
27 for (i = 0; i < 8; i++, vector >>= 1) {
30 sprintf(buf + strlen(buf), ", r%d", i);
33 sprintf(buf, "r%d", i);
40 static int expandImmediate(int value)
42 int mode = (value & 0xf00) >> 8;
43 u4 bits = value & 0xff;
48 return (bits << 16) | bits;
50 return (bits << 24) | (bits << 8);
52 return (bits << 24) | (bits << 16) | (bits << 8) | bits;
56 bits = (bits | 0x80) << 24;
57 return bits >> (((value & 0xf80) >> 7) - 8);
61 * Interpret a format string and build a string no longer than size
62 * See format key in Assemble.c.
64 static void buildInsnString(char *fmt, ArmLIR *lir, char* buf,
65 unsigned char *baseAddr, int size)
68 char *bufEnd = &buf[size-1];
69 char *fmtEnd = &fmt[strlen(fmt)];
72 while (fmt < fmtEnd) {
82 assert((unsigned)(nc-'0') < 3);
83 operand = lir->operands[nc-'0'];
86 operand = expandImmediate(operand);
87 sprintf(tbuf,"%d [0x%x]", operand, operand);
90 sprintf(tbuf,"s%d",operand & FP_REG_MASK);
93 sprintf(tbuf,"d%d",(operand & FP_REG_MASK) >> 1);
96 sprintf(tbuf,"%04x", operand);
100 sprintf(tbuf,"%d", operand);
103 sprintf(tbuf,"%d", operand+8);
106 sprintf(tbuf,"%d", operand*4);
109 sprintf(tbuf,"%d", operand*2);
143 sprintf(tbuf,"0x%08x",
144 (int) baseAddr + lir->generic.offset + 4 +
148 int offset_1 = lir->operands[0];
149 int offset_2 = NEXT_LIR(lir)->operands[0];
151 ((((intptr_t) baseAddr + lir->generic.offset + 4) &
152 ~3) + (offset_1 << 21 >> 9) + (offset_2 << 1)) &
154 sprintf(tbuf, "%p", (void *) target);
158 /* Nothing to print for BLX_2 */
160 strcpy(tbuf, "see above");
163 decodeRegList(operand, tbuf);
166 strcpy(tbuf,"DecodeError");
169 if (buf+strlen(tbuf) <= bufEnd) {
185 /* Pretty-print a LIR instruction */
186 static void dumpLIRInsn(LIR *arg, unsigned char *baseAddr)
188 ArmLIR *lir = (ArmLIR *) arg;
191 int offset = lir->generic.offset;
192 int dest = lir->operands[0];
193 u2 *cPtr = (u2*)baseAddr;
194 /* Handle pseudo-ops individually, and all regular insns as a group */
195 switch(lir->opCode) {
196 case ARM_PSEUDO_TARGET_LABEL:
198 case ARM_PSEUDO_CHAINING_CELL_NORMAL:
199 LOGD("-------- chaining cell (normal): 0x%04x\n", dest);
201 case ARM_PSEUDO_CHAINING_CELL_HOT:
202 LOGD("-------- chaining cell (hot): 0x%04x\n", dest);
204 case ARM_PSEUDO_CHAINING_CELL_INVOKE_PREDICTED:
205 LOGD("-------- chaining cell (predicted)\n");
207 case ARM_PSEUDO_CHAINING_CELL_INVOKE_SINGLETON:
208 LOGD("-------- chaining cell (invoke singleton): %s/%p\n",
209 ((Method *)dest)->name,
210 ((Method *)dest)->insns);
212 case ARM_PSEUDO_DALVIK_BYTECODE_BOUNDARY:
213 LOGD("-------- dalvik offset: 0x%04x @ %s\n", dest,
214 getOpcodeName(lir->operands[1]));
216 case ARM_PSEUDO_ALIGN4:
217 LOGD("%p (%04x): .align4\n", baseAddr + offset, offset);
219 case ARM_PSEUDO_PC_RECONSTRUCTION_CELL:
220 LOGD("-------- reconstruct dalvik PC : 0x%04x @ +0x%04x\n", dest,
223 case ARM_PSEUDO_PC_RECONSTRUCTION_BLOCK_LABEL:
226 case ARM_PSEUDO_EH_BLOCK_LABEL:
227 LOGD("Exception_Handling:\n");
229 case ARM_PSEUDO_NORMAL_BLOCK_LABEL:
230 LOGD("L%#06x:\n", dest);
236 buildInsnString(EncodingMap[lir->opCode].name, lir, opName,
238 buildInsnString(EncodingMap[lir->opCode].fmt, lir, buf, baseAddr,
240 LOGD("%p (%04x): %-8s%s\n",
241 baseAddr + offset, offset, opName, buf);
246 /* Dump instructions and constant pool contents */
247 void dvmCompilerCodegenDump(CompilationUnit *cUnit)
249 LOGD("Dumping LIR insns\n");
253 LOGD("installed code is at %p\n", cUnit->baseAddr);
254 LOGD("total size is %d bytes\n", cUnit->totalSize);
255 for (lirInsn = cUnit->firstLIRInsn; lirInsn; lirInsn = lirInsn->next) {
256 dumpLIRInsn(lirInsn, cUnit->baseAddr);
258 for (lirInsn = cUnit->wordList; lirInsn; lirInsn = lirInsn->next) {
259 armLIR = (ArmLIR *) lirInsn;
260 LOGD("%p (%04x): .word (0x%x)\n",
261 (char*)cUnit->baseAddr + armLIR->generic.offset, armLIR->generic.offset,
262 armLIR->operands[0]);