blob: 28dafe710d42f5b5eca654d60f8f3ab1a8163b2d [file] [log] [blame]
Ben Chengba4fc8b2009-06-01 13:00:29 -07001/*
2 * Copyright (C) 2009 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 "Dalvik.h"
18#include "libdex/OpCode.h"
19#include "dexdump/OpCodeNames.h"
20
21#include "../../CompilerInternals.h"
Bill Buzbee89efc3d2009-07-28 11:22:22 -070022#include "ArmLIR.h"
Ben Chengba4fc8b2009-06-01 13:00:29 -070023#include <unistd.h> /* for cacheflush */
24
25/*
Bill Buzbee89efc3d2009-07-28 11:22:22 -070026 * opcode: ArmOpCode enum
Ben Chengba4fc8b2009-06-01 13:00:29 -070027 * skeleton: pre-designated bit-pattern for this opcode
Bill Buzbee9bc3df32009-07-30 10:52:29 -070028 * k0: key to applying ds/de
Ben Chengba4fc8b2009-06-01 13:00:29 -070029 * ds: dest start bit position
30 * de: dest end bit position
Bill Buzbee9bc3df32009-07-30 10:52:29 -070031 * k1: key to applying s1s/s1e
Ben Chengba4fc8b2009-06-01 13:00:29 -070032 * s1s: src1 start bit position
33 * s1e: src1 end bit position
Bill Buzbee9bc3df32009-07-30 10:52:29 -070034 * k2: key to applying s2s/s2e
Ben Chengba4fc8b2009-06-01 13:00:29 -070035 * s2s: src2 start bit position
36 * s2e: src2 end bit position
37 * operands: number of operands (for sanity check purposes)
38 * name: mnemonic name
Elliott Hughesb4c05972010-02-24 16:36:18 -080039 * fmt: for pretty-printing
Ben Chengba4fc8b2009-06-01 13:00:29 -070040 */
Bill Buzbee9bc3df32009-07-30 10:52:29 -070041#define ENCODING_MAP(opcode, skeleton, k0, ds, de, k1, s1s, s1e, k2, s2s, s2e, \
Ben Chengdcf3e5d2009-09-11 13:42:05 -070042 k3, k3s, k3e, flags, name, fmt, size) \
Bill Buzbee270c1d62009-08-13 16:58:07 -070043 {skeleton, {{k0, ds, de}, {k1, s1s, s1e}, {k2, s2s, s2e}, \
Ben Chengdcf3e5d2009-09-11 13:42:05 -070044 {k3, k3s, k3e}}, opcode, flags, name, fmt, size}
Ben Chengba4fc8b2009-06-01 13:00:29 -070045
46/* Instruction dump string format keys: !pf, where "!" is the start
47 * of the key, "p" is which numeric operand to use and "f" is the
48 * print format.
49 *
50 * [p]ositions:
51 * 0 -> operands[0] (dest)
52 * 1 -> operands[1] (src1)
53 * 2 -> operands[2] (src2)
Bill Buzbee270c1d62009-08-13 16:58:07 -070054 * 3 -> operands[3] (extra)
Ben Chengba4fc8b2009-06-01 13:00:29 -070055 *
56 * [f]ormats:
57 * h -> 4-digit hex
58 * d -> decimal
Ben Chengba4fc8b2009-06-01 13:00:29 -070059 * E -> decimal*4
60 * F -> decimal*2
61 * c -> branch condition (beq, bne, etc.)
62 * t -> pc-relative target
63 * u -> 1st half of bl[x] target
64 * v -> 2nd half ob bl[x] target
65 * R -> register list
Bill Buzbee9727c3d2009-08-01 11:32:36 -070066 * s -> single precision floating point register
67 * S -> double precision floating point register
Bill Buzbee7ea0f642009-08-10 17:06:51 -070068 * m -> Thumb2 modified immediate
Bill Buzbee270c1d62009-08-13 16:58:07 -070069 * n -> complimented Thumb2 modified immediate
Bill Buzbee7ea0f642009-08-10 17:06:51 -070070 * M -> Thumb2 16-bit zero-extended immediate
Bill Buzbeea4a7f072009-08-27 13:58:09 -070071 * b -> 4-digit binary
Ben Chengba4fc8b2009-06-01 13:00:29 -070072 *
73 * [!] escape. To insert "!", use "!!"
74 */
Bill Buzbee89efc3d2009-07-28 11:22:22 -070075/* NOTE: must be kept in sync with enum ArmOpcode from ArmLIR.h */
Bill Buzbee1465db52009-09-23 17:17:35 -070076ArmEncodingMap EncodingMap[kArmLast] = {
77 ENCODING_MAP(kArm16BitData, 0x0000,
78 kFmtBitBlt, 15, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
79 kFmtUnused, -1, -1, IS_UNARY_OP, "data", "0x!0h(!0d)", 1),
80 ENCODING_MAP(kThumbAdcRR, 0x4140,
81 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
82 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -070083 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES | USES_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -070084 "adcs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -070085 ENCODING_MAP(kThumbAddRRI3, 0x1c00,
86 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
87 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -070088 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -070089 "adds", "r!0d, r!1d, #!2d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -070090 ENCODING_MAP(kThumbAddRI8, 0x3000,
91 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
92 kFmtUnused, -1, -1,
Ben Chengd7d426a2009-09-22 11:23:36 -070093 IS_BINARY_OP | REG_DEF0_USE0 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -070094 "adds", "r!0d, r!0d, #!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -070095 ENCODING_MAP(kThumbAddRRR, 0x1800,
96 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
97 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -070098 IS_TERTIARY_OP | REG_DEF0_USE12 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -070099 "adds", "r!0d, r!1d, r!2d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700100 ENCODING_MAP(kThumbAddRRLH, 0x4440,
101 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
102 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE01,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700103 "add", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700104 ENCODING_MAP(kThumbAddRRHL, 0x4480,
105 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
106 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE01,
Bill Buzbee716f1202009-07-23 13:22:09 -0700107 "add", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700108 ENCODING_MAP(kThumbAddRRHH, 0x44c0,
109 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
110 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE01,
Bill Buzbee716f1202009-07-23 13:22:09 -0700111 "add", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700112 ENCODING_MAP(kThumbAddPcRel, 0xa000,
113 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
114 kFmtUnused, -1, -1, IS_TERTIARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700115 "add", "r!0d, pc, #!1E", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700116 ENCODING_MAP(kThumbAddSpRel, 0xa800,
117 kFmtBitBlt, 10, 8, kFmtUnused, -1, -1, kFmtBitBlt, 7, 0,
118 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF_SP | REG_USE_SP,
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700119 "add", "r!0d, sp, #!2E", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700120 ENCODING_MAP(kThumbAddSpI7, 0xb000,
121 kFmtBitBlt, 6, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
122 kFmtUnused, -1, -1, IS_UNARY_OP | REG_DEF_SP | REG_USE_SP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700123 "add", "sp, #!0d*4", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700124 ENCODING_MAP(kThumbAndRR, 0x4000,
125 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
126 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700127 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700128 "ands", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700129 ENCODING_MAP(kThumbAsrRRI5, 0x1000,
130 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
131 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700132 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700133 "asrs", "r!0d, r!1d, #!2d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700134 ENCODING_MAP(kThumbAsrRR, 0x4100,
135 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
136 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700137 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700138 "asrs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700139 ENCODING_MAP(kThumbBCond, 0xd000,
140 kFmtBitBlt, 7, 0, kFmtBitBlt, 11, 8, kFmtUnused, -1, -1,
141 kFmtUnused, -1, -1, IS_BINARY_OP | IS_BRANCH | USES_CCODES,
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700142 "b!1c", "!0t", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700143 ENCODING_MAP(kThumbBUncond, 0xe000,
144 kFmtBitBlt, 10, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
145 kFmtUnused, -1, -1, NO_OPERAND | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700146 "b", "!0t", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700147 ENCODING_MAP(kThumbBicRR, 0x4380,
148 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
149 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700150 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700151 "bics", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700152 ENCODING_MAP(kThumbBkpt, 0xbe00,
153 kFmtBitBlt, 7, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
154 kFmtUnused, -1, -1, IS_UNARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700155 "bkpt", "!0d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700156 ENCODING_MAP(kThumbBlx1, 0xf000,
157 kFmtBitBlt, 10, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
158 kFmtUnused, -1, -1, IS_BINARY_OP | IS_BRANCH | REG_DEF_LR,
Bill Buzbee716f1202009-07-23 13:22:09 -0700159 "blx_1", "!0u", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700160 ENCODING_MAP(kThumbBlx2, 0xe800,
161 kFmtBitBlt, 10, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
162 kFmtUnused, -1, -1, IS_BINARY_OP | IS_BRANCH | REG_DEF_LR,
Bill Buzbee716f1202009-07-23 13:22:09 -0700163 "blx_2", "!0v", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700164 ENCODING_MAP(kThumbBl1, 0xf000,
165 kFmtBitBlt, 10, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
166 kFmtUnused, -1, -1, IS_UNARY_OP | IS_BRANCH | REG_DEF_LR,
Bill Buzbee716f1202009-07-23 13:22:09 -0700167 "bl_1", "!0u", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700168 ENCODING_MAP(kThumbBl2, 0xf800,
169 kFmtBitBlt, 10, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
170 kFmtUnused, -1, -1, IS_UNARY_OP | IS_BRANCH | REG_DEF_LR,
Bill Buzbee716f1202009-07-23 13:22:09 -0700171 "bl_2", "!0v", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700172 ENCODING_MAP(kThumbBlxR, 0x4780,
173 kFmtBitBlt, 6, 3, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
174 kFmtUnused, -1, -1,
Ben Chengd7d426a2009-09-22 11:23:36 -0700175 IS_UNARY_OP | REG_USE0 | IS_BRANCH | REG_DEF_LR,
Bill Buzbee716f1202009-07-23 13:22:09 -0700176 "blx", "r!0d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700177 ENCODING_MAP(kThumbBx, 0x4700,
178 kFmtBitBlt, 6, 3, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
179 kFmtUnused, -1, -1, IS_UNARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700180 "bx", "r!0d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700181 ENCODING_MAP(kThumbCmnRR, 0x42c0,
182 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
183 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01 | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700184 "cmn", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700185 ENCODING_MAP(kThumbCmpRI8, 0x2800,
186 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
187 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE0 | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700188 "cmp", "r!0d, #!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700189 ENCODING_MAP(kThumbCmpRR, 0x4280,
190 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
191 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01 | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700192 "cmp", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700193 ENCODING_MAP(kThumbCmpLH, 0x4540,
194 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
195 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01 | SETS_CCODES,
Ben Chengd7d426a2009-09-22 11:23:36 -0700196 "cmp", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700197 ENCODING_MAP(kThumbCmpHL, 0x4580,
198 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
199 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01 | SETS_CCODES,
Ben Chengd7d426a2009-09-22 11:23:36 -0700200 "cmp", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700201 ENCODING_MAP(kThumbCmpHH, 0x45c0,
202 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
203 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01 | SETS_CCODES,
Ben Chengd7d426a2009-09-22 11:23:36 -0700204 "cmp", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700205 ENCODING_MAP(kThumbEorRR, 0x4040,
206 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
207 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700208 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700209 "eors", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700210 ENCODING_MAP(kThumbLdmia, 0xc800,
211 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
212 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800213 IS_BINARY_OP | REG_DEF0_USE0 | REG_DEF_LIST1 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700214 "ldmia", "r!0d!!, <!1R>", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700215 ENCODING_MAP(kThumbLdrRRI5, 0x6800,
216 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800217 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700218 "ldr", "r!0d, [r!1d, #!2E]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700219 ENCODING_MAP(kThumbLdrRRR, 0x5800,
220 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800221 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700222 "ldr", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700223 ENCODING_MAP(kThumbLdrPcRel, 0x4800,
224 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800225 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0 | REG_USE_PC
226 | IS_LOAD, "ldr", "r!0d, [pc, #!1E]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700227 ENCODING_MAP(kThumbLdrSpRel, 0x9800,
228 kFmtBitBlt, 10, 8, kFmtUnused, -1, -1, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800229 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0 | REG_USE_SP
230 | IS_LOAD, "ldr", "r!0d, [sp, #!2E]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700231 ENCODING_MAP(kThumbLdrbRRI5, 0x7800,
232 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800233 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700234 "ldrb", "r!0d, [r!1d, #2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700235 ENCODING_MAP(kThumbLdrbRRR, 0x5c00,
236 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800237 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700238 "ldrb", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700239 ENCODING_MAP(kThumbLdrhRRI5, 0x8800,
240 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800241 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700242 "ldrh", "r!0d, [r!1d, #!2F]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700243 ENCODING_MAP(kThumbLdrhRRR, 0x5a00,
244 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800245 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700246 "ldrh", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700247 ENCODING_MAP(kThumbLdrsbRRR, 0x5600,
248 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800249 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700250 "ldrsb", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700251 ENCODING_MAP(kThumbLdrshRRR, 0x5e00,
252 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800253 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700254 "ldrsh", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700255 ENCODING_MAP(kThumbLslRRI5, 0x0000,
256 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
257 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700258 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700259 "lsls", "r!0d, r!1d, #!2d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700260 ENCODING_MAP(kThumbLslRR, 0x4080,
261 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
262 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700263 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700264 "lsls", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700265 ENCODING_MAP(kThumbLsrRRI5, 0x0800,
266 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
267 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700268 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700269 "lsrs", "r!0d, r!1d, #!2d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700270 ENCODING_MAP(kThumbLsrRR, 0x40c0,
271 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
272 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700273 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700274 "lsrs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700275 ENCODING_MAP(kThumbMovImm, 0x2000,
276 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
277 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700278 IS_BINARY_OP | REG_DEF0 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700279 "movs", "r!0d, #!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700280 ENCODING_MAP(kThumbMovRR, 0x1c00,
281 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
282 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700283 IS_BINARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700284 "movs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700285 ENCODING_MAP(kThumbMovRR_H2H, 0x46c0,
286 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
287 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Ben Chengd7d426a2009-09-22 11:23:36 -0700288 "mov", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700289 ENCODING_MAP(kThumbMovRR_H2L, 0x4640,
290 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
291 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Ben Chengd7d426a2009-09-22 11:23:36 -0700292 "mov", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700293 ENCODING_MAP(kThumbMovRR_L2H, 0x4680,
294 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
295 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Ben Chengd7d426a2009-09-22 11:23:36 -0700296 "mov", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700297 ENCODING_MAP(kThumbMul, 0x4340,
298 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
299 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700300 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700301 "muls", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700302 ENCODING_MAP(kThumbMvn, 0x43c0,
303 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
304 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700305 IS_BINARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700306 "mvns", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700307 ENCODING_MAP(kThumbNeg, 0x4240,
308 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
309 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700310 IS_BINARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700311 "negs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700312 ENCODING_MAP(kThumbOrr, 0x4300,
313 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
314 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700315 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700316 "orrs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700317 ENCODING_MAP(kThumbPop, 0xbc00,
318 kFmtBitBlt, 8, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
319 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800320 IS_UNARY_OP | REG_DEF_SP | REG_USE_SP | REG_DEF_LIST0
321 | IS_LOAD, "pop", "<!0R>", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700322 ENCODING_MAP(kThumbPush, 0xb400,
323 kFmtBitBlt, 8, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
324 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800325 IS_UNARY_OP | REG_DEF_SP | REG_USE_SP | REG_USE_LIST0
326 | IS_STORE, "push", "<!0R>", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700327 ENCODING_MAP(kThumbRorRR, 0x41c0,
328 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
329 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700330 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700331 "rors", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700332 ENCODING_MAP(kThumbSbc, 0x4180,
333 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
334 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700335 IS_BINARY_OP | REG_DEF0_USE01 | USES_CCODES | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700336 "sbcs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700337 ENCODING_MAP(kThumbStmia, 0xc000,
338 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
339 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800340 IS_BINARY_OP | REG_DEF0 | REG_USE0 | REG_USE_LIST1 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700341 "stmia", "r!0d!!, <!1R>", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700342 ENCODING_MAP(kThumbStrRRI5, 0x6000,
343 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800344 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700345 "str", "r!0d, [r!1d, #!2E]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700346 ENCODING_MAP(kThumbStrRRR, 0x5000,
347 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800348 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE012 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700349 "str", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700350 ENCODING_MAP(kThumbStrSpRel, 0x9000,
351 kFmtBitBlt, 10, 8, kFmtUnused, -1, -1, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800352 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE0 | REG_USE_SP
353 | IS_STORE, "str", "r!0d, [sp, #!2E]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700354 ENCODING_MAP(kThumbStrbRRI5, 0x7000,
355 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800356 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700357 "strb", "r!0d, [r!1d, #!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700358 ENCODING_MAP(kThumbStrbRRR, 0x5400,
359 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800360 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE012 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700361 "strb", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700362 ENCODING_MAP(kThumbStrhRRI5, 0x8000,
363 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800364 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700365 "strh", "r!0d, [r!1d, #!2F]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700366 ENCODING_MAP(kThumbStrhRRR, 0x5200,
367 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800368 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE012 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700369 "strh", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700370 ENCODING_MAP(kThumbSubRRI3, 0x1e00,
371 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
372 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700373 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700374 "subs", "r!0d, r!1d, #!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700375 ENCODING_MAP(kThumbSubRI8, 0x3800,
376 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
377 kFmtUnused, -1, -1,
Ben Chengd7d426a2009-09-22 11:23:36 -0700378 IS_BINARY_OP | REG_DEF0_USE0 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700379 "subs", "r!0d, #!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700380 ENCODING_MAP(kThumbSubRRR, 0x1a00,
381 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
382 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700383 IS_TERTIARY_OP | REG_DEF0_USE12 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700384 "subs", "r!0d, r!1d, r!2d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700385 ENCODING_MAP(kThumbSubSpI7, 0xb080,
386 kFmtBitBlt, 6, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
387 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700388 IS_UNARY_OP | REG_DEF_SP | REG_USE_SP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700389 "sub", "sp, #!0d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700390 ENCODING_MAP(kThumbSwi, 0xdf00,
391 kFmtBitBlt, 7, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1, kFmtUnused, -1, -1, IS_UNARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700392 "swi", "!0d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700393 ENCODING_MAP(kThumbTst, 0x4200,
394 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
395 kFmtUnused, -1, -1, IS_UNARY_OP | REG_USE01 | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700396 "tst", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700397 ENCODING_MAP(kThumb2Vldrs, 0xed900a00,
398 kFmtSfp, 22, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800399 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700400 "vldr", "!0s, [r!1d, #!2E]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700401 ENCODING_MAP(kThumb2Vldrd, 0xed900b00,
402 kFmtDfp, 22, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800403 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700404 "vldr", "!0S, [r!1d, #!2E]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700405 ENCODING_MAP(kThumb2Vmuls, 0xee200a00,
406 kFmtSfp, 22, 12, kFmtSfp, 7, 16, kFmtSfp, 5, 0,
407 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700408 IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700409 "vmuls", "!0s, !1s, !2s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700410 ENCODING_MAP(kThumb2Vmuld, 0xee200b00,
411 kFmtDfp, 22, 12, kFmtDfp, 7, 16, kFmtDfp, 5, 0,
412 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700413 "vmuld", "!0S, !1S, !2S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700414 ENCODING_MAP(kThumb2Vstrs, 0xed800a00,
415 kFmtSfp, 22, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800416 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700417 "vstr", "!0s, [r!1d, #!2E]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700418 ENCODING_MAP(kThumb2Vstrd, 0xed800b00,
419 kFmtDfp, 22, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800420 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700421 "vstr", "!0S, [r!1d, #!2E]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700422 ENCODING_MAP(kThumb2Vsubs, 0xee300a40,
423 kFmtSfp, 22, 12, kFmtSfp, 7, 16, kFmtSfp, 5, 0,
424 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700425 "vsub", "!0s, !1s, !2s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700426 ENCODING_MAP(kThumb2Vsubd, 0xee300b40,
427 kFmtDfp, 22, 12, kFmtDfp, 7, 16, kFmtDfp, 5, 0,
428 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700429 "vsub", "!0S, !1S, !2S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700430 ENCODING_MAP(kThumb2Vadds, 0xee300a00,
431 kFmtSfp, 22, 12, kFmtSfp, 7, 16, kFmtSfp, 5, 0,
432 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700433 "vadd", "!0s, !1s, !2s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700434 ENCODING_MAP(kThumb2Vaddd, 0xee300b00,
435 kFmtDfp, 22, 12, kFmtDfp, 7, 16, kFmtDfp, 5, 0,
436 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700437 "vadd", "!0S, !1S, !2S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700438 ENCODING_MAP(kThumb2Vdivs, 0xee800a00,
439 kFmtSfp, 22, 12, kFmtSfp, 7, 16, kFmtSfp, 5, 0,
440 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700441 "vdivs", "!0s, !1s, !2s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700442 ENCODING_MAP(kThumb2Vdivd, 0xee800b00,
443 kFmtDfp, 22, 12, kFmtDfp, 7, 16, kFmtDfp, 5, 0,
444 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700445 "vdivd", "!0S, !1S, !2S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700446 ENCODING_MAP(kThumb2VcvtIF, 0xeeb80ac0,
447 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
448 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700449 "vcvt.f32", "!0s, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700450 ENCODING_MAP(kThumb2VcvtID, 0xeeb80bc0,
451 kFmtDfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
452 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700453 "vcvt.f64", "!0S, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700454 ENCODING_MAP(kThumb2VcvtFI, 0xeebd0ac0,
455 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
456 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700457 "vcvt.s32.f32 ", "!0s, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700458 ENCODING_MAP(kThumb2VcvtDI, 0xeebd0bc0,
459 kFmtSfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
460 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700461 "vcvt.s32.f64 ", "!0s, !1S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700462 ENCODING_MAP(kThumb2VcvtFd, 0xeeb70ac0,
463 kFmtDfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
464 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700465 "vcvt.f64.f32 ", "!0S, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700466 ENCODING_MAP(kThumb2VcvtDF, 0xeeb70bc0,
467 kFmtSfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
468 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700469 "vcvt.f32.f64 ", "!0s, !1S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700470 ENCODING_MAP(kThumb2Vsqrts, 0xeeb10ac0,
471 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
472 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700473 "vsqrt.f32 ", "!0s, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700474 ENCODING_MAP(kThumb2Vsqrtd, 0xeeb10bc0,
475 kFmtDfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
476 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700477 "vsqrt.f64 ", "!0S, !1S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700478 ENCODING_MAP(kThumb2MovImmShift, 0xf04f0000, /* no setflags encoding */
479 kFmtBitBlt, 11, 8, kFmtModImm, -1, -1, kFmtUnused, -1, -1,
480 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700481 "mov", "r!0d, #!1m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700482 ENCODING_MAP(kThumb2MovImm16, 0xf2400000,
483 kFmtBitBlt, 11, 8, kFmtImm16, -1, -1, kFmtUnused, -1, -1,
484 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700485 "mov", "r!0d, #!1M", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700486 ENCODING_MAP(kThumb2StrRRI12, 0xf8c00000,
487 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800488 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700489 "str", "r!0d,[r!1d, #!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700490 ENCODING_MAP(kThumb2LdrRRI12, 0xf8d00000,
491 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800492 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700493 "ldr", "r!0d,[r!1d, #!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700494 ENCODING_MAP(kThumb2StrRRI8Predec, 0xf8400c00,
495 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 8, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800496 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700497 "str", "r!0d,[r!1d, #-!2d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700498 ENCODING_MAP(kThumb2LdrRRI8Predec, 0xf8500c00,
499 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 8, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800500 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700501 "ldr", "r!0d,[r!1d, #-!2d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700502 ENCODING_MAP(kThumb2Cbnz, 0xb900, /* Note: does not affect flags */
503 kFmtBitBlt, 2, 0, kFmtImm6, -1, -1, kFmtUnused, -1, -1,
504 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE0 | IS_BRANCH,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700505 "cbnz", "r!0d,!1t", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700506 ENCODING_MAP(kThumb2Cbz, 0xb100, /* Note: does not affect flags */
507 kFmtBitBlt, 2, 0, kFmtImm6, -1, -1, kFmtUnused, -1, -1,
508 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE0 | IS_BRANCH,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700509 "cbz", "r!0d,!1t", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700510 ENCODING_MAP(kThumb2AddRRI12, 0xf2000000,
511 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtImm12, -1, -1,
512 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700513 IS_TERTIARY_OP | REG_DEF0_USE1,/* Note: doesn't affect flags */
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700514 "add", "r!0d,r!1d,#!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700515 ENCODING_MAP(kThumb2MovRR, 0xea4f0000, /* no setflags encoding */
516 kFmtBitBlt, 11, 8, kFmtBitBlt, 3, 0, kFmtUnused, -1, -1,
517 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700518 "mov", "r!0d, r!1d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700519 ENCODING_MAP(kThumb2Vmovs, 0xeeb00a40,
520 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
521 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700522 "vmov.f32 ", " !0s, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700523 ENCODING_MAP(kThumb2Vmovd, 0xeeb00b40,
524 kFmtDfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
525 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700526 "vmov.f64 ", " !0S, !1S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700527 ENCODING_MAP(kThumb2Ldmia, 0xe8900000,
528 kFmtBitBlt, 19, 16, kFmtBitBlt, 15, 0, kFmtUnused, -1, -1,
529 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800530 IS_BINARY_OP | REG_DEF0_USE0 | REG_DEF_LIST1 | IS_LOAD,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700531 "ldmia", "r!0d!!, <!1R>", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700532 ENCODING_MAP(kThumb2Stmia, 0xe8800000,
533 kFmtBitBlt, 19, 16, kFmtBitBlt, 15, 0, kFmtUnused, -1, -1,
534 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800535 IS_BINARY_OP | REG_DEF0_USE0 | REG_USE_LIST1 | IS_STORE,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700536 "stmia", "r!0d!!, <!1R>", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700537 ENCODING_MAP(kThumb2AddRRR, 0xeb100000, /* setflags encoding */
538 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
539 kFmtShift, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700540 IS_QUAD_OP | REG_DEF0_USE12 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700541 "adds", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700542 ENCODING_MAP(kThumb2SubRRR, 0xebb00000, /* setflags enconding */
543 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
544 kFmtShift, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700545 IS_QUAD_OP | REG_DEF0_USE12 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700546 "subs", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700547 ENCODING_MAP(kThumb2SbcRRR, 0xeb700000, /* setflags encoding */
548 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
549 kFmtShift, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700550 IS_QUAD_OP | REG_DEF0_USE12 | USES_CCODES | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700551 "sbcs", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700552 ENCODING_MAP(kThumb2CmpRR, 0xebb00f00,
553 kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0, kFmtShift, -1, -1,
554 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700555 IS_TERTIARY_OP | REG_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700556 "cmp", "r!0d, r!1d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700557 ENCODING_MAP(kThumb2SubRRI12, 0xf2a00000,
558 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtImm12, -1, -1,
559 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700560 IS_TERTIARY_OP | REG_DEF0_USE1,/* Note: doesn't affect flags */
Bill Buzbee270c1d62009-08-13 16:58:07 -0700561 "sub", "r!0d,r!1d,#!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700562 ENCODING_MAP(kThumb2MvnImmShift, 0xf06f0000, /* no setflags encoding */
563 kFmtBitBlt, 11, 8, kFmtModImm, -1, -1, kFmtUnused, -1, -1,
564 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700565 "mvn", "r!0d, #!1n", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700566 ENCODING_MAP(kThumb2Sel, 0xfaa0f080,
567 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
568 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700569 IS_TERTIARY_OP | REG_DEF0_USE12 | USES_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700570 "sel", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700571 ENCODING_MAP(kThumb2Ubfx, 0xf3c00000,
572 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtLsb, -1, -1,
573 kFmtBWidth, 4, 0, IS_QUAD_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700574 "ubfx", "r!0d, r!1d, #!2d, #!3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700575 ENCODING_MAP(kThumb2Sbfx, 0xf3400000,
576 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtLsb, -1, -1,
577 kFmtBWidth, 4, 0, IS_QUAD_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700578 "sbfx", "r!0d, r!1d, #!2d, #!3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700579 ENCODING_MAP(kThumb2LdrRRR, 0xf8500000,
580 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800581 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700582 "ldr", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700583 ENCODING_MAP(kThumb2LdrhRRR, 0xf8300000,
584 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800585 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700586 "ldrh", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700587 ENCODING_MAP(kThumb2LdrshRRR, 0xf9300000,
588 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800589 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700590 "ldrsh", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700591 ENCODING_MAP(kThumb2LdrbRRR, 0xf8100000,
592 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800593 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700594 "ldrb", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700595 ENCODING_MAP(kThumb2LdrsbRRR, 0xf9100000,
596 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800597 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700598 "ldrsb", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700599 ENCODING_MAP(kThumb2StrRRR, 0xf8400000,
600 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800601 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_USE012 | IS_STORE,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700602 "str", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700603 ENCODING_MAP(kThumb2StrhRRR, 0xf8200000,
604 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800605 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_USE012 | IS_STORE,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700606 "strh", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700607 ENCODING_MAP(kThumb2StrbRRR, 0xf8000000,
608 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800609 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_USE012 | IS_STORE,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700610 "strb", "r!0d,[r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700611 ENCODING_MAP(kThumb2LdrhRRI12, 0xf8b00000,
612 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800613 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee1465db52009-09-23 17:17:35 -0700614 "ldrh", "r!0d,[r!1d, #!2d]", 2),
615 ENCODING_MAP(kThumb2LdrshRRI12, 0xf9b00000,
616 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800617 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee1465db52009-09-23 17:17:35 -0700618 "ldrsh", "r!0d,[r!1d, #!2d]", 2),
619 ENCODING_MAP(kThumb2LdrbRRI12, 0xf8900000,
620 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800621 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee1465db52009-09-23 17:17:35 -0700622 "ldrb", "r!0d,[r!1d, #!2d]", 2),
623 ENCODING_MAP(kThumb2LdrsbRRI12, 0xf9900000,
624 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800625 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee1465db52009-09-23 17:17:35 -0700626 "ldrsb", "r!0d,[r!1d, #!2d]", 2),
627 ENCODING_MAP(kThumb2StrhRRI12, 0xf8a00000,
628 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800629 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee1465db52009-09-23 17:17:35 -0700630 "strh", "r!0d,[r!1d, #!2d]", 2),
631 ENCODING_MAP(kThumb2StrbRRI12, 0xf8800000,
632 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800633 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee1465db52009-09-23 17:17:35 -0700634 "strb", "r!0d,[r!1d, #!2d]", 2),
635 ENCODING_MAP(kThumb2Pop, 0xe8bd0000,
636 kFmtBitBlt, 15, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
637 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800638 IS_UNARY_OP | REG_DEF_SP | REG_USE_SP | REG_DEF_LIST0
639 | IS_LOAD, "pop", "<!0R>", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700640 ENCODING_MAP(kThumb2Push, 0xe8ad0000,
641 kFmtBitBlt, 15, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
642 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800643 IS_UNARY_OP | REG_DEF_SP | REG_USE_SP | REG_USE_LIST0
644 | IS_STORE, "push", "<!0R>", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700645 ENCODING_MAP(kThumb2CmpRI8, 0xf1b00f00,
646 kFmtBitBlt, 19, 16, kFmtModImm, -1, -1, kFmtUnused, -1, -1,
647 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700648 IS_BINARY_OP | REG_USE0 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700649 "cmp", "r!0d, #!1m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700650 ENCODING_MAP(kThumb2AdcRRR, 0xeb500000, /* setflags encoding */
651 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
652 kFmtShift, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700653 IS_QUAD_OP | REG_DEF0_USE12 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700654 "acds", "r!0d, r!1d, r!2d, shift !3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700655 ENCODING_MAP(kThumb2AndRRR, 0xea000000,
656 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
657 kFmtShift, -1, -1, IS_QUAD_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700658 "and", "r!0d, r!1d, r!2d, shift !3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700659 ENCODING_MAP(kThumb2BicRRR, 0xea200000,
660 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
661 kFmtShift, -1, -1, IS_QUAD_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700662 "bic", "r!0d, r!1d, r!2d, shift !3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700663 ENCODING_MAP(kThumb2CmnRR, 0xeb000000,
664 kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0, kFmtShift, -1, -1,
665 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700666 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700667 "cmn", "r!0d, r!1d, shift !2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700668 ENCODING_MAP(kThumb2EorRRR, 0xea800000,
669 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
670 kFmtShift, -1, -1, IS_QUAD_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700671 "eor", "r!0d, r!1d, r!2d, shift !3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700672 ENCODING_MAP(kThumb2MulRRR, 0xfb00f000,
673 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
674 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700675 "mul", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700676 ENCODING_MAP(kThumb2MnvRR, 0xea6f0000,
677 kFmtBitBlt, 11, 8, kFmtBitBlt, 3, 0, kFmtShift, -1, -1,
678 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700679 "mvn", "r!0d, r!1d, shift !2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700680 ENCODING_MAP(kThumb2RsubRRI8, 0xf1d00000,
681 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
682 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700683 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700684 "rsb", "r!0d,r!1d,#!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700685 ENCODING_MAP(kThumb2NegRR, 0xf1d00000, /* instance of rsub */
686 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtUnused, -1, -1,
687 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700688 IS_BINARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700689 "neg", "r!0d,r!1d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700690 ENCODING_MAP(kThumb2OrrRRR, 0xea400000,
691 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
692 kFmtShift, -1, -1, IS_QUAD_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700693 "orr", "r!0d, r!1d, r!2d, shift !3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700694 ENCODING_MAP(kThumb2TstRR, 0xea100f00,
695 kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0, kFmtShift, -1, -1,
696 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700697 IS_TERTIARY_OP | REG_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700698 "tst", "r!0d, r!1d, shift !2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700699 ENCODING_MAP(kThumb2LslRRR, 0xfa00f000,
700 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
701 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700702 "lsl", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700703 ENCODING_MAP(kThumb2LsrRRR, 0xfa20f000,
704 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
705 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700706 "lsr", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700707 ENCODING_MAP(kThumb2AsrRRR, 0xfa40f000,
708 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
709 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700710 "asr", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700711 ENCODING_MAP(kThumb2RorRRR, 0xfa60f000,
712 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
713 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700714 "ror", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700715 ENCODING_MAP(kThumb2LslRRI5, 0xea4f0000,
716 kFmtBitBlt, 11, 8, kFmtBitBlt, 3, 0, kFmtShift5, -1, -1,
717 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700718 "lsl", "r!0d, r!1d, #!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700719 ENCODING_MAP(kThumb2LsrRRI5, 0xea4f0010,
720 kFmtBitBlt, 11, 8, kFmtBitBlt, 3, 0, kFmtShift5, -1, -1,
721 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700722 "lsr", "r!0d, r!1d, #!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700723 ENCODING_MAP(kThumb2AsrRRI5, 0xea4f0020,
724 kFmtBitBlt, 11, 8, kFmtBitBlt, 3, 0, kFmtShift5, -1, -1,
725 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700726 "asr", "r!0d, r!1d, #!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700727 ENCODING_MAP(kThumb2RorRRI5, 0xea4f0030,
728 kFmtBitBlt, 11, 8, kFmtBitBlt, 3, 0, kFmtShift5, -1, -1,
729 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700730 "ror", "r!0d, r!1d, #!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700731 ENCODING_MAP(kThumb2BicRRI8, 0xf0200000,
732 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
733 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700734 "bic", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700735 ENCODING_MAP(kThumb2AndRRI8, 0xf0000000,
736 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
737 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700738 "and", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700739 ENCODING_MAP(kThumb2OrrRRI8, 0xf0400000,
740 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
741 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700742 "orr", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700743 ENCODING_MAP(kThumb2EorRRI8, 0xf0800000,
744 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
745 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700746 "eor", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700747 ENCODING_MAP(kThumb2AddRRI8, 0xf1100000,
748 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
749 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700750 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700751 "adds", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700752 ENCODING_MAP(kThumb2AdcRRI8, 0xf1500000,
753 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
754 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700755 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES | USES_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700756 "adcs", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700757 ENCODING_MAP(kThumb2SubRRI8, 0xf1b00000,
758 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
759 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700760 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700761 "subs", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700762 ENCODING_MAP(kThumb2SbcRRI8, 0xf1700000,
763 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
764 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700765 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES | USES_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700766 "sbcs", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700767 ENCODING_MAP(kThumb2It, 0xbf00,
768 kFmtBitBlt, 7, 4, kFmtBitBlt, 3, 0, kFmtModImm, -1, -1,
769 kFmtUnused, -1, -1, IS_BINARY_OP | IS_IT | USES_CCODES,
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700770 "it:!1b", "!0c", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700771 ENCODING_MAP(kThumb2Fmstat, 0xeef1fa10,
772 kFmtUnused, -1, -1, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
773 kFmtUnused, -1, -1, NO_OPERAND | SETS_CCODES,
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700774 "fmstat", "", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700775 ENCODING_MAP(kThumb2Vcmpd, 0xeeb40b40,
776 kFmtDfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
777 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700778 "vcmp.f64", "!0S, !1S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700779 ENCODING_MAP(kThumb2Vcmps, 0xeeb40a40,
780 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
781 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700782 "vcmp.f32", "!0s, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700783 ENCODING_MAP(kThumb2LdrPcRel12, 0xf8df0000,
784 kFmtBitBlt, 15, 12, kFmtBitBlt, 11, 0, kFmtUnused, -1, -1,
785 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800786 IS_TERTIARY_OP | REG_DEF0 | REG_USE_PC | IS_LOAD,
Bill Buzbee1465db52009-09-23 17:17:35 -0700787 "ldr", "r!0d,[rpc, #!1d]", 2),
788 ENCODING_MAP(kThumb2BCond, 0xf0008000,
789 kFmtBrOffset, -1, -1, kFmtBitBlt, 25, 22, kFmtUnused, -1, -1,
790 kFmtUnused, -1, -1,
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700791 IS_BINARY_OP | IS_BRANCH | USES_CCODES,
792 "b!1c", "!0t", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700793 ENCODING_MAP(kThumb2Vmovd_RR, 0xeeb00b40,
794 kFmtDfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
795 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700796 "vmov.f64", "!0S, !1S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700797 ENCODING_MAP(kThumb2Vmovs_RR, 0xeeb00a40,
798 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
799 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
800 "vmov.f32", "!0s, !1s", 2),
801 ENCODING_MAP(kThumb2Fmrs, 0xee100a10,
802 kFmtBitBlt, 15, 12, kFmtSfp, 7, 16, kFmtUnused, -1, -1,
803 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700804 "fmrs", "r!0d, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700805 ENCODING_MAP(kThumb2Fmsr, 0xee000a10,
806 kFmtSfp, 7, 16, kFmtBitBlt, 15, 12, kFmtUnused, -1, -1,
807 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700808 "fmsr", "!0s, r!1d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700809 ENCODING_MAP(kThumb2Fmrrd, 0xec500b10,
810 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtDfp, 5, 0,
811 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF01_USE2,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700812 "fmrrd", "r!0d, r!1d, !2S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700813 ENCODING_MAP(kThumb2Fmdrr, 0xec400b10,
814 kFmtDfp, 5, 0, kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16,
815 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700816 "fmdrr", "!0S, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700817 ENCODING_MAP(kThumb2Vabsd, 0xeeb00bc0,
818 kFmtDfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
819 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
820 "vabs.f64", "!0S, !1S", 2),
821 ENCODING_MAP(kThumb2Vabss, 0xeeb00ac0,
822 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
823 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
824 "vabs.f32", "!0s, !1s", 2),
825 ENCODING_MAP(kThumb2Vnegd, 0xeeb10b40,
826 kFmtDfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
827 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
828 "vneg.f64", "!0S, !1S", 2),
829 ENCODING_MAP(kThumb2Vnegs, 0xeeb10a40,
830 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
831 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
832 "vneg.f32", "!0s, !1s", 2),
833 ENCODING_MAP(kThumb2Vmovs_IMM8, 0xeeb00a00,
834 kFmtSfp, 22, 12, kFmtFPImm, 16, 0, kFmtUnused, -1, -1,
835 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0,
836 "vmov.f32", "!0s, #0x!1h", 2),
837 ENCODING_MAP(kThumb2Vmovd_IMM8, 0xeeb00b00,
838 kFmtDfp, 22, 12, kFmtFPImm, 16, 0, kFmtUnused, -1, -1,
839 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0,
840 "vmov.f64", "!0S, #0x!1h", 2),
841 ENCODING_MAP(kThumb2Mla, 0xfb000000,
842 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
843 kFmtBitBlt, 15, 12,
844 IS_QUAD_OP | REG_DEF0 | REG_USE1 | REG_USE2 | REG_USE3,
845 "mla", "r!0d, r!1d, r!2d, r!3d", 2),
846 ENCODING_MAP(kThumb2Umull, 0xfba00000,
847 kFmtBitBlt, 15, 12, kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16,
848 kFmtBitBlt, 3, 0,
849 IS_QUAD_OP | REG_DEF0 | REG_DEF1 | REG_USE2 | REG_USE3,
850 "umull", "r!0d, r!1d, r!2d, r!3d", 2),
851 ENCODING_MAP(kThumb2Ldrex, 0xe8500f00,
852 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800853 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee1465db52009-09-23 17:17:35 -0700854 "ldrex", "r!0d,[r!1d, #!2E]", 2),
855 ENCODING_MAP(kThumb2Strex, 0xe8400000,
856 kFmtBitBlt, 11, 8, kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16,
Bill Buzbee1f748632010-03-02 16:14:41 -0800857 kFmtBitBlt, 7, 0, IS_QUAD_OP | REG_DEF0_USE12 | IS_STORE,
Bill Buzbee1465db52009-09-23 17:17:35 -0700858 "strex", "r!0d,r!1d, [r!2d, #!2E]", 2),
859 ENCODING_MAP(kThumb2Clrex, 0xf3bf8f2f,
860 kFmtUnused, -1, -1, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800861 kFmtUnused, -1, -1, NO_OPERAND,
862 "clrex", "", 2),
Bill Buzbeed0937ef2009-12-22 16:15:39 -0800863 ENCODING_MAP(kThumb2Bfi, 0xf3600000,
864 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtShift5, -1, -1,
865 kFmtBitBlt, 4, 0, IS_QUAD_OP | REG_DEF0_USE1,
866 "bfi", "r!0d,r!1d,#!2d,#!3d", 2),
867 ENCODING_MAP(kThumb2Bfc, 0xf36f0000,
868 kFmtBitBlt, 11, 8, kFmtShift5, -1, -1, kFmtBitBlt, 4, 0,
869 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0,
870 "bfc", "r!0d,#!1d,#!2d", 2),
Ben Chengba4fc8b2009-06-01 13:00:29 -0700871};
872
Ben Cheng6d576092009-09-01 17:01:58 -0700873/*
874 * The fake NOP of moving r0 to r0 actually will incur data stalls if r0 is
875 * not ready. Since r5 (rFP) is not updated often, it is less likely to
876 * generate unnecessary stall cycles.
877 */
878#define PADDING_MOV_R5_R5 0x1C2D
Ben Chengba4fc8b2009-06-01 13:00:29 -0700879
880/* Write the numbers in the literal pool to the codegen stream */
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700881static void installDataContent(CompilationUnit *cUnit)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700882{
Ben Chenge80cd942009-07-17 15:54:23 -0700883 int *dataPtr = (int *) ((char *) cUnit->baseAddr + cUnit->dataOffset);
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700884 ArmLIR *dataLIR = (ArmLIR *) cUnit->wordList;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700885 while (dataLIR) {
886 *dataPtr++ = dataLIR->operands[0];
887 dataLIR = NEXT_LIR(dataLIR);
888 }
889}
890
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700891/* Returns the size of a Jit trace description */
892static int jitTraceDescriptionSize(const JitTraceDescription *desc)
893{
894 int runCount;
895 for (runCount = 0; ; runCount++) {
896 if (desc->trace[runCount].frag.runEnd)
897 break;
898 }
899 return sizeof(JitCodeDesc) + ((runCount+1) * sizeof(JitTraceRun));
900}
901
Ben Chengba4fc8b2009-06-01 13:00:29 -0700902/* Return TRUE if error happens */
903static bool assembleInstructions(CompilationUnit *cUnit, intptr_t startAddr)
904{
905 short *bufferAddr = (short *) cUnit->codeBuffer;
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700906 ArmLIR *lir;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700907
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700908 for (lir = (ArmLIR *) cUnit->firstLIRInsn; lir; lir = NEXT_LIR(lir)) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700909 if (lir->opCode < 0) {
Bill Buzbee1465db52009-09-23 17:17:35 -0700910 if ((lir->opCode == kArmPseudoPseudoAlign4) &&
Ben Cheng1efc9c52009-06-08 18:25:27 -0700911 /* 1 means padding is needed */
912 (lir->operands[0] == 1)) {
Ben Cheng6d576092009-09-01 17:01:58 -0700913 *bufferAddr++ = PADDING_MOV_R5_R5;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700914 }
915 continue;
916 }
917
Ben Chenge9695e52009-06-16 16:11:47 -0700918 if (lir->isNop) {
919 continue;
920 }
921
Bill Buzbee1465db52009-09-23 17:17:35 -0700922 if (lir->opCode == kThumbLdrPcRel ||
923 lir->opCode == kThumb2LdrPcRel12 ||
924 lir->opCode == kThumbAddPcRel ||
925 ((lir->opCode == kThumb2Vldrs) && (lir->operands[1] == rpc))) {
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700926 ArmLIR *lirTarget = (ArmLIR *) lir->generic.target;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700927 intptr_t pc = (lir->generic.offset + 4) & ~3;
Ben Cheng38329f52009-07-07 14:19:20 -0700928 /*
929 * Allow an offset (stored in operands[2] to be added to the
930 * PC-relative target. Useful to get to a fixed field inside a
931 * chaining cell.
932 */
933 intptr_t target = lirTarget->generic.offset + lir->operands[2];
Ben Chengba4fc8b2009-06-01 13:00:29 -0700934 int delta = target - pc;
935 if (delta & 0x3) {
936 LOGE("PC-rel distance is not multiples of 4: %d\n", delta);
937 dvmAbort();
938 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700939 if ((lir->opCode == kThumb2LdrPcRel12) && (delta > 4091)) {
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700940 return true;
941 } else if (delta > 1020) {
Ben Cheng1efc9c52009-06-08 18:25:27 -0700942 return true;
943 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700944 if (lir->opCode == kThumb2Vldrs) {
945 lir->operands[2] = delta >> 2;
946 } else {
947 lir->operands[1] = (lir->opCode == kThumb2LdrPcRel12) ?
948 delta : delta >> 2;
949 }
950 } else if (lir->opCode == kThumb2Cbnz || lir->opCode == kThumb2Cbz) {
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700951 ArmLIR *targetLIR = (ArmLIR *) lir->generic.target;
952 intptr_t pc = lir->generic.offset + 4;
953 intptr_t target = targetLIR->generic.offset;
954 int delta = target - pc;
955 if (delta > 126 || delta < 0) {
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700956 /*
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700957 * TODO: allow multiple kinds of assembler failure to allow
958 * change of code patterns when things don't fit.
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700959 */
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700960 return true;
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700961 } else {
962 lir->operands[1] = delta >> 1;
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700963 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700964 } else if (lir->opCode == kThumbBCond ||
965 lir->opCode == kThumb2BCond) {
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700966 ArmLIR *targetLIR = (ArmLIR *) lir->generic.target;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700967 intptr_t pc = lir->generic.offset + 4;
968 intptr_t target = targetLIR->generic.offset;
969 int delta = target - pc;
Bill Buzbee1465db52009-09-23 17:17:35 -0700970 if ((lir->opCode == kThumbBCond) && (delta > 254 || delta < -256)) {
Ben Cheng1efc9c52009-06-08 18:25:27 -0700971 return true;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700972 }
973 lir->operands[0] = delta >> 1;
Bill Buzbee1465db52009-09-23 17:17:35 -0700974 } else if (lir->opCode == kThumbBUncond) {
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700975 ArmLIR *targetLIR = (ArmLIR *) lir->generic.target;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700976 intptr_t pc = lir->generic.offset + 4;
977 intptr_t target = targetLIR->generic.offset;
978 int delta = target - pc;
979 if (delta > 2046 || delta < -2048) {
980 LOGE("Unconditional branch distance out of range: %d\n", delta);
981 dvmAbort();
982 }
983 lir->operands[0] = delta >> 1;
Bill Buzbee1465db52009-09-23 17:17:35 -0700984 } else if (lir->opCode == kThumbBlx1) {
985 assert(NEXT_LIR(lir)->opCode == kThumbBlx2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700986 /* curPC is Thumb */
987 intptr_t curPC = (startAddr + lir->generic.offset + 4) & ~3;
988 intptr_t target = lir->operands[1];
989
990 /* Match bit[1] in target with base */
991 if (curPC & 0x2) {
992 target |= 0x2;
993 }
994 int delta = target - curPC;
995 assert((delta >= -(1<<22)) && (delta <= ((1<<22)-2)));
996
997 lir->operands[0] = (delta >> 12) & 0x7ff;
998 NEXT_LIR(lir)->operands[0] = (delta>> 1) & 0x7ff;
999 }
1000
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001001 ArmEncodingMap *encoder = &EncodingMap[lir->opCode];
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001002 u4 bits = encoder->skeleton;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001003 int i;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001004 for (i = 0; i < 4; i++) {
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001005 u4 operand;
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001006 u4 value;
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001007 operand = lir->operands[i];
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001008 switch(encoder->fieldLoc[i].kind) {
Bill Buzbee1465db52009-09-23 17:17:35 -07001009 case kFmtUnused:
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001010 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001011 case kFmtFPImm:
1012 value = ((operand & 0xF0) >> 4) << encoder->fieldLoc[i].end;
1013 value |= (operand & 0x0F) << encoder->fieldLoc[i].start;
1014 bits |= value;
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001015 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001016 case kFmtBrOffset:
1017 /*
1018 * NOTE: branch offsets are not handled here, but
1019 * in the main assembly loop (where label values
1020 * are known). For reference, here is what the
1021 * encoder handing would be:
1022 value = ((operand & 0x80000) >> 19) << 26;
1023 value |= ((operand & 0x40000) >> 18) << 11;
1024 value |= ((operand & 0x20000) >> 17) << 13;
1025 value |= ((operand & 0x1f800) >> 11) << 16;
1026 value |= (operand & 0x007ff);
1027 bits |= value;
1028 */
1029 break;
1030 case kFmtShift5:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001031 value = ((operand & 0x1c) >> 2) << 12;
1032 value |= (operand & 0x03) << 6;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001033 bits |= value;
1034 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001035 case kFmtShift:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001036 value = ((operand & 0x70) >> 4) << 12;
1037 value |= (operand & 0x0f) << 4;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001038 bits |= value;
1039 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001040 case kFmtBWidth:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001041 value = operand - 1;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001042 bits |= value;
1043 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001044 case kFmtLsb:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001045 value = ((operand & 0x1c) >> 2) << 12;
1046 value |= (operand & 0x03) << 6;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001047 bits |= value;
1048 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001049 case kFmtImm6:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001050 value = ((operand & 0x20) >> 5) << 9;
1051 value |= (operand & 0x1f) << 3;
Bill Buzbee7ea0f642009-08-10 17:06:51 -07001052 bits |= value;
1053 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001054 case kFmtBitBlt:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001055 value = (operand << encoder->fieldLoc[i].start) &
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001056 ((1 << (encoder->fieldLoc[i].end + 1)) - 1);
1057 bits |= value;
1058 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001059 case kFmtDfp: {
1060 assert(DOUBLEREG(operand));
1061 assert((operand & 0x1) == 0);
Ben Cheng30f1f462009-10-12 13:46:55 -07001062 int regName = (operand & FP_REG_MASK) >> 1;
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001063 /* Snag the 1-bit slice and position it */
Ben Cheng30f1f462009-10-12 13:46:55 -07001064 value = ((regName & 0x10) >> 4) <<
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001065 encoder->fieldLoc[i].end;
1066 /* Extract and position the 4-bit slice */
Ben Cheng30f1f462009-10-12 13:46:55 -07001067 value |= (regName & 0x0f) <<
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001068 encoder->fieldLoc[i].start;
1069 bits |= value;
1070 break;
Ben Cheng30f1f462009-10-12 13:46:55 -07001071 }
Bill Buzbee1465db52009-09-23 17:17:35 -07001072 case kFmtSfp:
1073 assert(SINGLEREG(operand));
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001074 /* Snag the 1-bit slice and position it */
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001075 value = (operand & 0x1) <<
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001076 encoder->fieldLoc[i].end;
1077 /* Extract and position the 4-bit slice */
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001078 value |= ((operand & 0x1e) >> 1) <<
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001079 encoder->fieldLoc[i].start;
1080 bits |= value;
1081 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001082 case kFmtImm12:
1083 case kFmtModImm:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001084 value = ((operand & 0x800) >> 11) << 26;
1085 value |= ((operand & 0x700) >> 8) << 12;
1086 value |= operand & 0x0ff;
Bill Buzbee7ea0f642009-08-10 17:06:51 -07001087 bits |= value;
1088 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001089 case kFmtImm16:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001090 value = ((operand & 0x0800) >> 11) << 26;
1091 value |= ((operand & 0xf000) >> 12) << 16;
1092 value |= ((operand & 0x0700) >> 8) << 12;
1093 value |= operand & 0x0ff;
Bill Buzbee7ea0f642009-08-10 17:06:51 -07001094 bits |= value;
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001095 break;
1096 default:
1097 assert(0);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001098 }
1099 }
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001100 if (encoder->size == 2) {
1101 *bufferAddr++ = (bits >> 16) & 0xffff;
1102 }
1103 *bufferAddr++ = bits & 0xffff;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001104 }
Ben Cheng1efc9c52009-06-08 18:25:27 -07001105 return false;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001106}
1107
1108/*
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001109 * Translation layout in the code cache. Note that the codeAddress pointer
1110 * in JitTable will point directly to the code body (field codeAddress). The
1111 * chain cell offset codeAddress - 2, and (if present) executionCount is at
1112 * codeAddress - 6.
1113 *
1114 * +----------------------------+
1115 * | Execution count | -> [Optional] 4 bytes
1116 * +----------------------------+
1117 * +--| Offset to chain cell counts| -> 2 bytes
1118 * | +----------------------------+
1119 * | | Code body | -> Start address for translation
1120 * | | | variable in 2-byte chunks
1121 * | . . (JitTable's codeAddress points here)
1122 * | . .
1123 * | | |
1124 * | +----------------------------+
1125 * | | Chaining Cells | -> 8 bytes each, must be 4 byte aligned
1126 * | . .
1127 * | . .
1128 * | | |
1129 * | +----------------------------+
Ben Chengcec26f62010-01-15 15:29:33 -08001130 * | | Gap for large switch stmt | -> # cases >= MAX_CHAINED_SWITCH_CASES
1131 * | +----------------------------+
1132 * +->| Chaining cell counts | -> 8 bytes, chain cell counts by type
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001133 * +----------------------------+
1134 * | Trace description | -> variable sized
1135 * . .
1136 * | |
1137 * +----------------------------+
1138 * | Literal pool | -> 4-byte aligned, variable size
1139 * . .
1140 * . .
1141 * | |
1142 * +----------------------------+
1143 *
Ben Chengba4fc8b2009-06-01 13:00:29 -07001144 * Go over each instruction in the list and calculate the offset from the top
1145 * before sending them off to the assembler. If out-of-range branch distance is
1146 * seen rearrange the instructions a bit to correct it.
1147 */
Bill Buzbee716f1202009-07-23 13:22:09 -07001148void dvmCompilerAssembleLIR(CompilationUnit *cUnit, JitTranslationInfo *info)
Ben Chengba4fc8b2009-06-01 13:00:29 -07001149{
1150 LIR *lir;
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001151 ArmLIR *armLIR;
Ben Cheng1efc9c52009-06-08 18:25:27 -07001152 int offset = 0;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001153 int i;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001154 ChainCellCounts chainCellCounts;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001155 int descSize = jitTraceDescriptionSize(cUnit->traceDesc);
Ben Chengcec26f62010-01-15 15:29:33 -08001156 int chainingCellGap;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001157
Bill Buzbee716f1202009-07-23 13:22:09 -07001158 info->instructionSet = cUnit->instructionSet;
1159
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001160 /* Beginning offset needs to allow space for chain cell offset */
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001161 for (armLIR = (ArmLIR *) cUnit->firstLIRInsn;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001162 armLIR;
1163 armLIR = NEXT_LIR(armLIR)) {
1164 armLIR->generic.offset = offset;
Ben Chenge9695e52009-06-16 16:11:47 -07001165 if (armLIR->opCode >= 0 && !armLIR->isNop) {
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001166 armLIR->size = EncodingMap[armLIR->opCode].size * 2;
1167 offset += armLIR->size;
Bill Buzbee1465db52009-09-23 17:17:35 -07001168 } else if (armLIR->opCode == kArmPseudoPseudoAlign4) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001169 if (offset & 0x2) {
1170 offset += 2;
1171 armLIR->operands[0] = 1;
1172 } else {
1173 armLIR->operands[0] = 0;
1174 }
1175 }
1176 /* Pseudo opcodes don't consume space */
1177 }
1178
1179 /* Const values have to be word aligned */
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001180 offset = (offset + 3) & ~3;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001181
Ben Chengcec26f62010-01-15 15:29:33 -08001182 /*
1183 * Get the gap (# of u4) between the offset of chaining cell count and
1184 * the bottom of real chaining cells. If the translation has chaining
1185 * cells, the gap is guaranteed to be multiples of 4.
1186 */
1187 chainingCellGap = (offset - cUnit->chainingCellBottom->offset) >> 2;
1188
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001189 /* Add space for chain cell counts & trace description */
Ben Cheng1efc9c52009-06-08 18:25:27 -07001190 u4 chainCellOffset = offset;
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001191 ArmLIR *chainCellOffsetLIR = (ArmLIR *) cUnit->chainCellOffsetLIR;
Bill Buzbee6e963e12009-06-17 16:56:19 -07001192 assert(chainCellOffsetLIR);
Ben Cheng1efc9c52009-06-08 18:25:27 -07001193 assert(chainCellOffset < 0x10000);
Bill Buzbee1465db52009-09-23 17:17:35 -07001194 assert(chainCellOffsetLIR->opCode == kArm16BitData &&
Ben Cheng1efc9c52009-06-08 18:25:27 -07001195 chainCellOffsetLIR->operands[0] == CHAIN_CELL_OFFSET_TAG);
1196
Ben Chenge80cd942009-07-17 15:54:23 -07001197 /*
1198 * Replace the CHAIN_CELL_OFFSET_TAG with the real value. If trace
1199 * profiling is enabled, subtract 4 (occupied by the counter word) from
1200 * the absolute offset as the value stored in chainCellOffsetLIR is the
1201 * delta from &chainCellOffsetLIR to &ChainCellCounts.
1202 */
1203 chainCellOffsetLIR->operands[0] =
1204 gDvmJit.profile ? (chainCellOffset - 4) : chainCellOffset;
Ben Cheng1efc9c52009-06-08 18:25:27 -07001205
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001206 offset += sizeof(chainCellCounts) + descSize;
1207
1208 assert((offset & 0x3) == 0); /* Should still be word aligned */
1209
1210 /* Set up offsets for literals */
Ben Chengba4fc8b2009-06-01 13:00:29 -07001211 cUnit->dataOffset = offset;
1212
1213 for (lir = cUnit->wordList; lir; lir = lir->next) {
1214 lir->offset = offset;
1215 offset += 4;
1216 }
1217
1218 cUnit->totalSize = offset;
1219
Ben Cheng7b133ef2010-02-04 16:15:59 -08001220 if (gDvmJit.codeCacheByteUsed + cUnit->totalSize > gDvmJit.codeCacheSize) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001221 gDvmJit.codeCacheFull = true;
1222 cUnit->baseAddr = NULL;
1223 return;
1224 }
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001225
1226 /* Allocate enough space for the code block */
1227 cUnit->codeBuffer = dvmCompilerNew(chainCellOffset, true);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001228 if (cUnit->codeBuffer == NULL) {
1229 LOGE("Code buffer allocation failure\n");
1230 cUnit->baseAddr = NULL;
1231 return;
1232 }
1233
Ben Cheng1efc9c52009-06-08 18:25:27 -07001234 bool assemblerFailure = assembleInstructions(
Ben Chengba4fc8b2009-06-01 13:00:29 -07001235 cUnit, (intptr_t) gDvmJit.codeCache + gDvmJit.codeCacheByteUsed);
1236
Ben Cheng1efc9c52009-06-08 18:25:27 -07001237 /*
1238 * Currently the only reason that can cause the assembler to fail is due to
1239 * trace length - cut it in half and retry.
1240 */
1241 if (assemblerFailure) {
1242 cUnit->halveInstCount = true;
1243 return;
1244 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07001245
Ben Chengccd6c012009-10-15 14:52:45 -07001246 /* Don't go all the way if the goal is just to get the verbose output */
1247 if (info->discardResult) return;
Bill Buzbee6e963e12009-06-17 16:56:19 -07001248
Ben Chengba4fc8b2009-06-01 13:00:29 -07001249 cUnit->baseAddr = (char *) gDvmJit.codeCache + gDvmJit.codeCacheByteUsed;
1250 gDvmJit.codeCacheByteUsed += offset;
1251
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001252 /* Install the code block */
Ben Cheng1efc9c52009-06-08 18:25:27 -07001253 memcpy((char*)cUnit->baseAddr, cUnit->codeBuffer, chainCellOffset);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001254 gDvmJit.numCompilations++;
1255
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001256 /* Install the chaining cell counts */
Ben Chengcec26f62010-01-15 15:29:33 -08001257 for (i=0; i< kChainingCellGap; i++) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001258 chainCellCounts.u.count[i] = cUnit->numChainingCells[i];
1259 }
Ben Chengcec26f62010-01-15 15:29:33 -08001260
1261 /* Set the gap number in the chaining cell count structure */
1262 chainCellCounts.u.count[kChainingCellGap] = chainingCellGap;
1263
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001264 memcpy((char*)cUnit->baseAddr + chainCellOffset, &chainCellCounts,
1265 sizeof(chainCellCounts));
1266
1267 /* Install the trace description */
1268 memcpy((char*)cUnit->baseAddr + chainCellOffset + sizeof(chainCellCounts),
1269 cUnit->traceDesc, descSize);
1270
1271 /* Write the literals directly into the code cache */
1272 installDataContent(cUnit);
1273
Ben Chengba4fc8b2009-06-01 13:00:29 -07001274 /* Flush dcache and invalidate the icache to maintain coherence */
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001275 cacheflush((long)cUnit->baseAddr,
Ben Chenge80cd942009-07-17 15:54:23 -07001276 (long)((char *) cUnit->baseAddr + offset), 0);
Bill Buzbee716f1202009-07-23 13:22:09 -07001277
1278 /* Record code entry point and instruction set */
1279 info->codeAddress = (char*)cUnit->baseAddr + cUnit->headerSize;
Bill Buzbee716f1202009-07-23 13:22:09 -07001280 /* If applicable, mark low bit to denote thumb */
1281 if (info->instructionSet != DALVIK_JIT_ARM)
1282 info->codeAddress = (char*)info->codeAddress + 1;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001283}
1284
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001285/*
1286 * Returns the skeleton bit pattern associated with an opcode. All
1287 * variable fields are zeroed.
1288 */
1289static u4 getSkeleton(ArmOpCode op)
1290{
1291 return EncodingMap[op].skeleton;
1292}
1293
1294static u4 assembleChainingBranch(int branchOffset, bool thumbTarget)
Ben Cheng38329f52009-07-07 14:19:20 -07001295{
1296 u4 thumb1, thumb2;
1297
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001298 if (!thumbTarget) {
1299 thumb1 = (getSkeleton(kThumbBlx1) | ((branchOffset>>12) & 0x7ff));
1300 thumb2 = (getSkeleton(kThumbBlx2) | ((branchOffset>> 1) & 0x7ff));
1301 } else if ((branchOffset < -2048) | (branchOffset > 2046)) {
1302 thumb1 = (getSkeleton(kThumbBl1) | ((branchOffset>>12) & 0x7ff));
1303 thumb2 = (getSkeleton(kThumbBl2) | ((branchOffset>> 1) & 0x7ff));
Ben Cheng38329f52009-07-07 14:19:20 -07001304 } else {
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001305 thumb1 = (getSkeleton(kThumbBUncond) | ((branchOffset>> 1) & 0x7ff));
1306 thumb2 = getSkeleton(kThumbOrr); /* nop -> or r0, r0 */
Ben Cheng38329f52009-07-07 14:19:20 -07001307 }
1308
1309 return thumb2<<16 | thumb1;
1310}
1311
Ben Chengba4fc8b2009-06-01 13:00:29 -07001312/*
1313 * Perform translation chain operation.
1314 * For ARM, we'll use a pair of thumb instructions to generate
1315 * an unconditional chaining branch of up to 4MB in distance.
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001316 * Use a BL, because the generic "interpret" translation needs
1317 * the link register to find the dalvik pc of teh target.
Ben Chengba4fc8b2009-06-01 13:00:29 -07001318 * 111HHooooooooooo
1319 * Where HH is 10 for the 1st inst, and 11 for the second and
1320 * the "o" field is each instruction's 11-bit contribution to the
1321 * 22-bit branch offset.
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001322 * If the target is nearby, use a single-instruction bl.
1323 * If one or more threads is suspended, don't chain.
Ben Chengba4fc8b2009-06-01 13:00:29 -07001324 */
1325void* dvmJitChain(void* tgtAddr, u4* branchAddr)
1326{
1327 int baseAddr = (u4) branchAddr + 4;
1328 int branchOffset = (int) tgtAddr - baseAddr;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001329 u4 newInst;
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001330 bool thumbTarget;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001331
Ben Cheng6999d842010-01-26 16:46:15 -08001332 /*
1333 * Only chain translations when there is no urge to ask all threads to
1334 * suspend themselves via the interpreter.
1335 */
1336 if ((gDvmJit.pProfTable != NULL) && (gDvm.sumThreadSuspendCount == 0) &&
1337 (gDvmJit.codeCacheFull == false)) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001338 assert((branchOffset >= -(1<<22)) && (branchOffset <= ((1<<22)-2)));
Ben Chengba4fc8b2009-06-01 13:00:29 -07001339
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001340 gDvmJit.translationChains++;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001341
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001342 COMPILER_TRACE_CHAINING(
1343 LOGD("Jit Runtime: chaining 0x%x to 0x%x\n",
1344 (int) branchAddr, (int) tgtAddr & -2));
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001345
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001346 /*
1347 * NOTE: normally, all translations are Thumb[2] mode, with
1348 * a single exception: the default TEMPLATE_INTERPRET
1349 * pseudo-translation. If the need ever arises to
1350 * mix Arm & Thumb[2] translations, the following code should be
1351 * generalized.
1352 */
1353 thumbTarget = (tgtAddr != gDvmJit.interpretTemplate);
1354
1355 newInst = assembleChainingBranch(branchOffset, thumbTarget);
Ben Cheng38329f52009-07-07 14:19:20 -07001356
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001357 *branchAddr = newInst;
1358 cacheflush((long)branchAddr, (long)branchAddr + 4, 0);
Ben Cheng6999d842010-01-26 16:46:15 -08001359 gDvmJit.hasNewChain = true;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001360 }
1361
Ben Chengba4fc8b2009-06-01 13:00:29 -07001362 return tgtAddr;
1363}
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001364
1365/*
Ben Cheng6999d842010-01-26 16:46:15 -08001366 * Attempt to enqueue a work order to patch an inline cache for a predicted
1367 * chaining cell for virtual/interface calls.
1368 */
1369bool inlineCachePatchEnqueue(PredictedChainingCell *cellAddr,
1370 PredictedChainingCell *newContent)
1371{
1372 bool result = true;
1373
1374 dvmLockMutex(&gDvmJit.compilerICPatchLock);
1375
1376 if (cellAddr->clazz == NULL &&
1377 cellAddr->branch == PREDICTED_CHAIN_BX_PAIR_INIT) {
1378 /*
1379 * The update order matters - make sure clazz is updated last since it
1380 * will bring the uninitialized chaining cell to life.
1381 */
1382 cellAddr->method = newContent->method;
1383 cellAddr->branch = newContent->branch;
1384 cellAddr->counter = newContent->counter;
1385 cellAddr->clazz = newContent->clazz;
1386 cacheflush((intptr_t) cellAddr, (intptr_t) (cellAddr+1), 0);
1387 }
1388 else if (gDvmJit.compilerICPatchIndex < COMPILER_IC_PATCH_QUEUE_SIZE) {
1389 int index = gDvmJit.compilerICPatchIndex++;
1390 gDvmJit.compilerICPatchQueue[index].cellAddr = cellAddr;
1391 gDvmJit.compilerICPatchQueue[index].cellContent = *newContent;
1392 } else {
1393 result = false;
1394 }
1395
1396 dvmUnlockMutex(&gDvmJit.compilerICPatchLock);
1397 return result;
1398}
1399
1400/*
Ben Cheng38329f52009-07-07 14:19:20 -07001401 * This method is called from the invoke templates for virtual and interface
1402 * methods to speculatively setup a chain to the callee. The templates are
1403 * written in assembly and have setup method, cell, and clazz at r0, r2, and
1404 * r3 respectively, so there is a unused argument in the list. Upon return one
1405 * of the following three results may happen:
1406 * 1) Chain is not setup because the callee is native. Reset the rechain
1407 * count to a big number so that it will take a long time before the next
1408 * rechain attempt to happen.
1409 * 2) Chain is not setup because the callee has not been created yet. Reset
1410 * the rechain count to a small number and retry in the near future.
1411 * 3) Ask all other threads to stop before patching this chaining cell.
1412 * This is required because another thread may have passed the class check
1413 * but hasn't reached the chaining cell yet to follow the chain. If we
1414 * patch the content before halting the other thread, there could be a
1415 * small window for race conditions to happen that it may follow the new
1416 * but wrong chain to invoke a different method.
1417 */
1418const Method *dvmJitToPatchPredictedChain(const Method *method,
1419 void *unused,
1420 PredictedChainingCell *cell,
1421 const ClassObject *clazz)
1422{
Jeff Hao97319a82009-08-12 16:57:15 -07001423#if defined(WITH_SELF_VERIFICATION)
1424 /* Disable chaining and prevent this from triggering again for a while */
1425 cell->counter = PREDICTED_CHAIN_COUNTER_AVOID;
1426 cacheflush((long) cell, (long) (cell+1), 0);
1427 goto done;
1428#else
Ben Cheng38329f52009-07-07 14:19:20 -07001429 /* Don't come back here for a long time if the method is native */
1430 if (dvmIsNativeMethod(method)) {
1431 cell->counter = PREDICTED_CHAIN_COUNTER_AVOID;
1432 cacheflush((long) cell, (long) (cell+1), 0);
1433 COMPILER_TRACE_CHAINING(
1434 LOGD("Jit Runtime: predicted chain %p to native method %s ignored",
1435 cell, method->name));
1436 goto done;
1437 }
1438 int tgtAddr = (int) dvmJitGetCodeAddr(method->insns);
1439
1440 /*
1441 * Compilation not made yet for the callee. Reset the counter to a small
1442 * value and come back to check soon.
1443 */
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001444 if ((tgtAddr == 0) || ((void*)tgtAddr == gDvmJit.interpretTemplate)) {
Ben Cheng38329f52009-07-07 14:19:20 -07001445 /*
1446 * Wait for a few invocations (currently set to be 16) before trying
1447 * to setup the chain again.
1448 */
1449 cell->counter = PREDICTED_CHAIN_COUNTER_DELAY;
1450 cacheflush((long) cell, (long) (cell+1), 0);
1451 COMPILER_TRACE_CHAINING(
Ben Chenga8e64a72009-10-20 13:01:36 -07001452 LOGD("Jit Runtime: predicted chain %p to method %s%s delayed",
1453 cell, method->clazz->descriptor, method->name));
Ben Cheng38329f52009-07-07 14:19:20 -07001454 goto done;
1455 }
1456
Ben Cheng6999d842010-01-26 16:46:15 -08001457 PredictedChainingCell newCell;
Ben Chenga8e64a72009-10-20 13:01:36 -07001458
Ben Cheng6999d842010-01-26 16:46:15 -08001459 /* Avoid back-to-back orders to the same cell */
1460 cell->counter = PREDICTED_CHAIN_COUNTER_AVOID;
Ben Cheng38329f52009-07-07 14:19:20 -07001461
1462 int baseAddr = (int) cell + 4; // PC is cur_addr + 4
1463 int branchOffset = tgtAddr - baseAddr;
1464
Ben Cheng6999d842010-01-26 16:46:15 -08001465 newCell.branch = assembleChainingBranch(branchOffset, true);
1466 newCell.clazz = clazz;
1467 newCell.method = method;
1468 newCell.counter = PREDICTED_CHAIN_COUNTER_RECHAIN;
Ben Cheng38329f52009-07-07 14:19:20 -07001469
Ben Chenga8e64a72009-10-20 13:01:36 -07001470 /*
Ben Cheng6999d842010-01-26 16:46:15 -08001471 * Enter the work order to the queue and the chaining cell will be patched
1472 * the next time a safe point is entered.
Ben Cheng60c24f42010-01-04 12:29:56 -08001473 *
Ben Cheng6999d842010-01-26 16:46:15 -08001474 * If the enqueuing fails reset the rechain count to a normal value so that
1475 * it won't get indefinitely delayed.
Ben Cheng60c24f42010-01-04 12:29:56 -08001476 */
Ben Cheng6999d842010-01-26 16:46:15 -08001477 if (!inlineCachePatchEnqueue(cell, &newCell)) {
1478 cell->counter = PREDICTED_CHAIN_COUNTER_RECHAIN;
1479 }
Ben Cheng60c24f42010-01-04 12:29:56 -08001480#endif
1481done:
1482 return method;
1483}
1484
1485/*
1486 * Patch the inline cache content based on the content passed from the work
1487 * order.
1488 */
Ben Cheng6999d842010-01-26 16:46:15 -08001489void dvmCompilerPatchInlineCache(void)
Ben Cheng60c24f42010-01-04 12:29:56 -08001490{
Ben Cheng6999d842010-01-26 16:46:15 -08001491 int i;
1492 PredictedChainingCell *minAddr, *maxAddr;
Ben Cheng60c24f42010-01-04 12:29:56 -08001493
Ben Cheng6999d842010-01-26 16:46:15 -08001494 /* Nothing to be done */
1495 if (gDvmJit.compilerICPatchIndex == 0) return;
Ben Cheng60c24f42010-01-04 12:29:56 -08001496
Ben Cheng6999d842010-01-26 16:46:15 -08001497 /*
1498 * Since all threads are already stopped we don't really need to acquire
1499 * the lock. But race condition can be easily introduced in the future w/o
1500 * paying attention so we still acquire the lock here.
1501 */
1502 dvmLockMutex(&gDvmJit.compilerICPatchLock);
Ben Cheng7a0bcd02010-01-22 16:45:45 -08001503
Ben Cheng6999d842010-01-26 16:46:15 -08001504 //LOGD("Number of IC patch work orders: %d", gDvmJit.compilerICPatchIndex);
Ben Cheng60c24f42010-01-04 12:29:56 -08001505
Ben Cheng6999d842010-01-26 16:46:15 -08001506 /* Initialize the min/max address range */
1507 minAddr = (PredictedChainingCell *)
Ben Cheng7b133ef2010-02-04 16:15:59 -08001508 ((char *) gDvmJit.codeCache + gDvmJit.codeCacheSize);
Ben Cheng6999d842010-01-26 16:46:15 -08001509 maxAddr = (PredictedChainingCell *) gDvmJit.codeCache;
Ben Cheng60c24f42010-01-04 12:29:56 -08001510
Ben Cheng6999d842010-01-26 16:46:15 -08001511 for (i = 0; i < gDvmJit.compilerICPatchIndex; i++) {
1512 PredictedChainingCell *cellAddr =
1513 gDvmJit.compilerICPatchQueue[i].cellAddr;
1514 PredictedChainingCell *cellContent =
1515 &gDvmJit.compilerICPatchQueue[i].cellContent;
Ben Cheng38329f52009-07-07 14:19:20 -07001516
Ben Cheng6999d842010-01-26 16:46:15 -08001517 if (cellAddr->clazz == NULL) {
1518 COMPILER_TRACE_CHAINING(
1519 LOGD("Jit Runtime: predicted chain %p to %s (%s) initialized",
1520 cellAddr,
1521 cellContent->clazz->descriptor,
1522 cellContent->method->name));
1523 } else {
1524 COMPILER_TRACE_CHAINING(
1525 LOGD("Jit Runtime: predicted chain %p from %s to %s (%s) "
1526 "patched",
1527 cellAddr,
1528 cellAddr->clazz->descriptor,
1529 cellContent->clazz->descriptor,
1530 cellContent->method->name));
1531 }
Ben Cheng38329f52009-07-07 14:19:20 -07001532
Ben Cheng6999d842010-01-26 16:46:15 -08001533 /* Patch the chaining cell */
1534 *cellAddr = *cellContent;
1535 minAddr = (cellAddr < minAddr) ? cellAddr : minAddr;
1536 maxAddr = (cellAddr > maxAddr) ? cellAddr : maxAddr;
1537 }
1538
1539 /* Then synchronize the I/D cache */
1540 cacheflush((long) minAddr, (long) (maxAddr+1), 0);
1541
1542 gDvmJit.compilerICPatchIndex = 0;
1543 dvmUnlockMutex(&gDvmJit.compilerICPatchLock);
Ben Cheng38329f52009-07-07 14:19:20 -07001544}
1545
1546/*
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001547 * Unchain a trace given the starting address of the translation
1548 * in the code cache. Refer to the diagram in dvmCompilerAssembleLIR.
1549 * Returns the address following the last cell unchained. Note that
1550 * the incoming codeAddr is a thumb code address, and therefore has
1551 * the low bit set.
1552 */
1553u4* dvmJitUnchain(void* codeAddr)
1554{
1555 u2* pChainCellOffset = (u2*)((char*)codeAddr - 3);
1556 u2 chainCellOffset = *pChainCellOffset;
1557 ChainCellCounts *pChainCellCounts =
Ben Chenge80cd942009-07-17 15:54:23 -07001558 (ChainCellCounts*)((char*)codeAddr + chainCellOffset - 3);
Ben Cheng38329f52009-07-07 14:19:20 -07001559 int cellSize;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001560 u4* pChainCells;
1561 u4* pStart;
1562 u4 thumb1;
1563 u4 thumb2;
1564 u4 newInst;
1565 int i,j;
Ben Cheng38329f52009-07-07 14:19:20 -07001566 PredictedChainingCell *predChainCell;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001567
1568 /* Get total count of chain cells */
Ben Chengcec26f62010-01-15 15:29:33 -08001569 for (i = 0, cellSize = 0; i < kChainingCellGap; i++) {
Bill Buzbee1465db52009-09-23 17:17:35 -07001570 if (i != kChainingCellInvokePredicted) {
Ben Cheng38329f52009-07-07 14:19:20 -07001571 cellSize += pChainCellCounts->u.count[i] * 2;
1572 } else {
1573 cellSize += pChainCellCounts->u.count[i] * 4;
1574 }
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001575 }
1576
Ben Chengcec26f62010-01-15 15:29:33 -08001577 if (cellSize == 0)
1578 return (u4 *) pChainCellCounts;
1579
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001580 /* Locate the beginning of the chain cell region */
Ben Chengcec26f62010-01-15 15:29:33 -08001581 pStart = pChainCells = ((u4 *) pChainCellCounts) - cellSize -
1582 pChainCellCounts->u.count[kChainingCellGap];
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001583
1584 /* The cells are sorted in order - walk through them and reset */
Ben Chengcec26f62010-01-15 15:29:33 -08001585 for (i = 0; i < kChainingCellGap; i++) {
Ben Cheng38329f52009-07-07 14:19:20 -07001586 int elemSize = 2; /* Most chaining cell has two words */
Bill Buzbee1465db52009-09-23 17:17:35 -07001587 if (i == kChainingCellInvokePredicted) {
Ben Cheng38329f52009-07-07 14:19:20 -07001588 elemSize = 4;
1589 }
1590
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001591 for (j = 0; j < pChainCellCounts->u.count[i]; j++) {
1592 int targetOffset;
1593 switch(i) {
Bill Buzbee1465db52009-09-23 17:17:35 -07001594 case kChainingCellNormal:
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001595 targetOffset = offsetof(InterpState,
1596 jitToInterpEntries.dvmJitToInterpNormal);
1597 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001598 case kChainingCellHot:
1599 case kChainingCellInvokeSingleton:
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001600 targetOffset = offsetof(InterpState,
Ben Cheng40094c12010-02-24 20:58:44 -08001601 jitToInterpEntries.dvmJitToInterpTraceSelect);
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001602 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001603 case kChainingCellInvokePredicted:
Ben Cheng38329f52009-07-07 14:19:20 -07001604 targetOffset = 0;
1605 predChainCell = (PredictedChainingCell *) pChainCells;
Ben Cheng7a0bcd02010-01-22 16:45:45 -08001606 /*
1607 * There could be a race on another mutator thread to use
1608 * this particular predicted cell and the check has passed
1609 * the clazz comparison. So we cannot safely wipe the
1610 * method and branch but it is safe to clear the clazz,
1611 * which serves as the key.
1612 */
Ben Cheng38329f52009-07-07 14:19:20 -07001613 predChainCell->clazz = PREDICTED_CHAIN_CLAZZ_INIT;
Ben Cheng38329f52009-07-07 14:19:20 -07001614 break;
Jeff Hao97319a82009-08-12 16:57:15 -07001615#if defined(WITH_SELF_VERIFICATION)
Bill Buzbee1465db52009-09-23 17:17:35 -07001616 case kChainingCellBackwardBranch:
Jeff Hao97319a82009-08-12 16:57:15 -07001617 targetOffset = offsetof(InterpState,
Ben Cheng40094c12010-02-24 20:58:44 -08001618 jitToInterpEntries.dvmJitToInterpBackwardBranch);
Jeff Hao97319a82009-08-12 16:57:15 -07001619 break;
Bill Buzbee9c4b7c82009-09-10 10:10:38 -07001620#elif defined(WITH_JIT_TUNING)
Bill Buzbee1465db52009-09-23 17:17:35 -07001621 case kChainingCellBackwardBranch:
Bill Buzbee9c4b7c82009-09-10 10:10:38 -07001622 targetOffset = offsetof(InterpState,
1623 jitToInterpEntries.dvmJitToInterpNormal);
1624 break;
Jeff Hao97319a82009-08-12 16:57:15 -07001625#endif
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001626 default:
Ben Chengbb0dce52009-11-03 16:19:11 -08001627 targetOffset = 0; // make gcc happy
1628 LOGE("Unexpected chaining type: %d", i);
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001629 dvmAbort();
1630 }
Ben Cheng38329f52009-07-07 14:19:20 -07001631 COMPILER_TRACE_CHAINING(
1632 LOGD("Jit Runtime: unchaining 0x%x", (int)pChainCells));
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001633 /*
Ben Cheng38329f52009-07-07 14:19:20 -07001634 * Thumb code sequence for a chaining cell is:
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001635 * ldr r0, rGLUE, #<word offset>
1636 * blx r0
1637 */
Bill Buzbee1465db52009-09-23 17:17:35 -07001638 if (i != kChainingCellInvokePredicted) {
Ben Cheng38329f52009-07-07 14:19:20 -07001639 targetOffset = targetOffset >> 2; /* convert to word offset */
1640 thumb1 = 0x6800 | (targetOffset << 6) |
1641 (rGLUE << 3) | (r0 << 0);
1642 thumb2 = 0x4780 | (r0 << 3);
1643 newInst = thumb2<<16 | thumb1;
1644 *pChainCells = newInst;
1645 }
1646 pChainCells += elemSize; /* Advance by a fixed number of words */
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001647 }
1648 }
1649 return pChainCells;
1650}
1651
1652/* Unchain all translation in the cache. */
1653void dvmJitUnchainAll()
1654{
1655 u4* lowAddress = NULL;
1656 u4* highAddress = NULL;
1657 unsigned int i;
1658 if (gDvmJit.pJitEntryTable != NULL) {
1659 COMPILER_TRACE_CHAINING(LOGD("Jit Runtime: unchaining all"));
1660 dvmLockMutex(&gDvmJit.tableLock);
Bill Buzbee27176222009-06-09 09:20:16 -07001661 for (i = 0; i < gDvmJit.jitTableSize; i++) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001662 if (gDvmJit.pJitEntryTable[i].dPC &&
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001663 gDvmJit.pJitEntryTable[i].codeAddress &&
1664 (gDvmJit.pJitEntryTable[i].codeAddress !=
1665 gDvmJit.interpretTemplate)) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001666 u4* lastAddress;
1667 lastAddress =
1668 dvmJitUnchain(gDvmJit.pJitEntryTable[i].codeAddress);
1669 if (lowAddress == NULL ||
1670 (u4*)gDvmJit.pJitEntryTable[i].codeAddress < lowAddress)
1671 lowAddress = lastAddress;
1672 if (lastAddress > highAddress)
1673 highAddress = lastAddress;
1674 }
1675 }
1676 cacheflush((long)lowAddress, (long)highAddress, 0);
1677 dvmUnlockMutex(&gDvmJit.tableLock);
Ben Cheng7a0bcd02010-01-22 16:45:45 -08001678 gDvmJit.translationChains = 0;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001679 }
Ben Cheng6999d842010-01-26 16:46:15 -08001680 gDvmJit.hasNewChain = false;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001681}
Bill Buzbee716f1202009-07-23 13:22:09 -07001682
1683typedef struct jitProfileAddrToLine {
1684 u4 lineNum;
1685 u4 bytecodeOffset;
1686} jitProfileAddrToLine;
1687
1688
1689/* Callback function to track the bytecode offset/line number relationiship */
1690static int addrToLineCb (void *cnxt, u4 bytecodeOffset, u4 lineNum)
1691{
1692 jitProfileAddrToLine *addrToLine = (jitProfileAddrToLine *) cnxt;
1693
1694 /* Best match so far for this offset */
1695 if (addrToLine->bytecodeOffset >= bytecodeOffset) {
1696 addrToLine->lineNum = lineNum;
1697 }
1698 return 0;
1699}
1700
1701char *getTraceBase(const JitEntry *p)
1702{
1703 return (char*)p->codeAddress -
1704 (6 + (p->u.info.instructionSet == DALVIK_JIT_ARM ? 0 : 1));
1705}
1706
1707/* Dumps profile info for a single trace */
Ben Cheng88a0f972010-02-24 15:00:40 -08001708static int dumpTraceProfile(JitEntry *p, bool silent, bool reset,
1709 unsigned long sum)
Bill Buzbee716f1202009-07-23 13:22:09 -07001710{
1711 ChainCellCounts* pCellCounts;
1712 char* traceBase;
1713 u4* pExecutionCount;
Ben Cheng88a0f972010-02-24 15:00:40 -08001714 u4 executionCount;
Bill Buzbee716f1202009-07-23 13:22:09 -07001715 u2* pCellOffset;
1716 JitTraceDescription *desc;
1717 const Method* method;
1718
1719 traceBase = getTraceBase(p);
1720
1721 if (p->codeAddress == NULL) {
Ben Cheng88a0f972010-02-24 15:00:40 -08001722 if (!silent)
1723 LOGD("TRACEPROFILE 0x%08x 0 NULL 0 0", (int)traceBase);
Bill Buzbee716f1202009-07-23 13:22:09 -07001724 return 0;
1725 }
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001726 if (p->codeAddress == gDvmJit.interpretTemplate) {
Ben Cheng88a0f972010-02-24 15:00:40 -08001727 if (!silent)
1728 LOGD("TRACEPROFILE 0x%08x 0 INTERPRET_ONLY 0 0", (int)traceBase);
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001729 return 0;
1730 }
Bill Buzbee716f1202009-07-23 13:22:09 -07001731
1732 pExecutionCount = (u4*) (traceBase);
Ben Cheng88a0f972010-02-24 15:00:40 -08001733 executionCount = *pExecutionCount;
1734 if (reset) {
1735 *pExecutionCount =0;
1736 }
1737 if (silent) {
1738 return executionCount;
1739 }
Bill Buzbee716f1202009-07-23 13:22:09 -07001740 pCellOffset = (u2*) (traceBase + 4);
1741 pCellCounts = (ChainCellCounts*) ((char *)pCellOffset + *pCellOffset);
1742 desc = (JitTraceDescription*) ((char*)pCellCounts + sizeof(*pCellCounts));
1743 method = desc->method;
1744 char *methodDesc = dexProtoCopyMethodDescriptor(&method->prototype);
1745 jitProfileAddrToLine addrToLine = {0, desc->trace[0].frag.startOffset};
1746
1747 /*
1748 * We may end up decoding the debug information for the same method
1749 * multiple times, but the tradeoff is we don't need to allocate extra
1750 * space to store the addr/line mapping. Since this is a debugging feature
1751 * and done infrequently so the slower but simpler mechanism should work
1752 * just fine.
1753 */
1754 dexDecodeDebugInfo(method->clazz->pDvmDex->pDexFile,
1755 dvmGetMethodCode(method),
1756 method->clazz->descriptor,
1757 method->prototype.protoIdx,
1758 method->accessFlags,
1759 addrToLineCb, NULL, &addrToLine);
1760
Ben Cheng88a0f972010-02-24 15:00:40 -08001761 LOGD("TRACEPROFILE 0x%08x % 10d %5.2f%% [%#x(+%d), %d] %s%s;%s",
Bill Buzbee716f1202009-07-23 13:22:09 -07001762 (int)traceBase,
Ben Cheng88a0f972010-02-24 15:00:40 -08001763 executionCount,
1764 ((float ) executionCount) / sum * 100.0,
Bill Buzbee716f1202009-07-23 13:22:09 -07001765 desc->trace[0].frag.startOffset,
1766 desc->trace[0].frag.numInsts,
1767 addrToLine.lineNum,
1768 method->clazz->descriptor, method->name, methodDesc);
1769 free(methodDesc);
1770
Ben Cheng88a0f972010-02-24 15:00:40 -08001771 return executionCount;
Bill Buzbee716f1202009-07-23 13:22:09 -07001772}
1773
Ben Chengccd6c012009-10-15 14:52:45 -07001774/* Create a copy of the trace descriptor of an existing compilation */
Ben Cheng88a0f972010-02-24 15:00:40 -08001775JitTraceDescription *dvmCopyTraceDescriptor(const u2 *pc,
1776 const JitEntry *knownEntry)
Ben Chengccd6c012009-10-15 14:52:45 -07001777{
Ben Cheng88a0f972010-02-24 15:00:40 -08001778 const JitEntry *jitEntry = knownEntry ? knownEntry : dvmFindJitEntry(pc);
Ben Chengccd6c012009-10-15 14:52:45 -07001779 if (jitEntry == NULL) return NULL;
1780
1781 /* Find out the startint point */
1782 char *traceBase = getTraceBase(jitEntry);
1783
1784 /* Then find out the starting point of the chaining cell */
1785 u2 *pCellOffset = (u2*) (traceBase + 4);
1786 ChainCellCounts *pCellCounts =
1787 (ChainCellCounts*) ((char *)pCellOffset + *pCellOffset);
1788
1789 /* From there we can find out the starting point of the trace descriptor */
1790 JitTraceDescription *desc =
1791 (JitTraceDescription*) ((char*)pCellCounts + sizeof(*pCellCounts));
1792
1793 /* Now make a copy and return */
1794 int descSize = jitTraceDescriptionSize(desc);
1795 JitTraceDescription *newCopy = (JitTraceDescription *) malloc(descSize);
1796 memcpy(newCopy, desc, descSize);
1797 return newCopy;
1798}
1799
Bill Buzbee716f1202009-07-23 13:22:09 -07001800/* Handy function to retrieve the profile count */
1801static inline int getProfileCount(const JitEntry *entry)
1802{
1803 if (entry->dPC == 0 || entry->codeAddress == 0)
1804 return 0;
1805 u4 *pExecutionCount = (u4 *) getTraceBase(entry);
1806
1807 return *pExecutionCount;
1808}
1809
1810
1811/* qsort callback function */
1812static int sortTraceProfileCount(const void *entry1, const void *entry2)
1813{
1814 const JitEntry *jitEntry1 = entry1;
1815 const JitEntry *jitEntry2 = entry2;
1816
1817 int count1 = getProfileCount(jitEntry1);
1818 int count2 = getProfileCount(jitEntry2);
1819 return (count1 == count2) ? 0 : ((count1 > count2) ? -1 : 1);
1820}
1821
1822/* Sort the trace profile counts and dump them */
1823void dvmCompilerSortAndPrintTraceProfiles()
1824{
1825 JitEntry *sortedEntries;
1826 int numTraces = 0;
Ben Cheng88a0f972010-02-24 15:00:40 -08001827 unsigned long sum = 0;
Bill Buzbee716f1202009-07-23 13:22:09 -07001828 unsigned int i;
1829
1830 /* Make sure that the table is not changing */
1831 dvmLockMutex(&gDvmJit.tableLock);
1832
1833 /* Sort the entries by descending order */
1834 sortedEntries = malloc(sizeof(JitEntry) * gDvmJit.jitTableSize);
1835 if (sortedEntries == NULL)
1836 goto done;
1837 memcpy(sortedEntries, gDvmJit.pJitEntryTable,
1838 sizeof(JitEntry) * gDvmJit.jitTableSize);
1839 qsort(sortedEntries, gDvmJit.jitTableSize, sizeof(JitEntry),
1840 sortTraceProfileCount);
1841
Ben Cheng88a0f972010-02-24 15:00:40 -08001842 /* Analyze the sorted entries */
Bill Buzbee716f1202009-07-23 13:22:09 -07001843 for (i=0; i < gDvmJit.jitTableSize; i++) {
1844 if (sortedEntries[i].dPC != 0) {
Ben Cheng88a0f972010-02-24 15:00:40 -08001845 sum += dumpTraceProfile(&sortedEntries[i],
1846 true /* silent */,
1847 false /* reset */,
1848 0);
Bill Buzbee716f1202009-07-23 13:22:09 -07001849 numTraces++;
1850 }
1851 }
1852 if (numTraces == 0)
1853 numTraces = 1;
Ben Cheng88a0f972010-02-24 15:00:40 -08001854 if (sum == 0) {
1855 sum = 1;
1856 }
1857
1858 LOGD("JIT: Average execution count -> %d",(int)(sum / numTraces));
1859
1860 /* Dump the sorted entries. The count of each trace will be reset to 0. */
1861 for (i=0; i < gDvmJit.jitTableSize; i++) {
1862 if (sortedEntries[i].dPC != 0) {
1863 dumpTraceProfile(&sortedEntries[i],
1864 false /* silent */,
1865 true /* reset */,
1866 sum);
1867 }
1868 }
1869
1870 for (i=0; i < gDvmJit.jitTableSize && i < 10; i++) {
1871 JitTraceDescription* desc =
1872 dvmCopyTraceDescriptor(NULL, &sortedEntries[i]);
1873 dvmCompilerWorkEnqueue(sortedEntries[i].dPC,
1874 kWorkOrderTraceDebug, desc);
1875 }
Bill Buzbee716f1202009-07-23 13:22:09 -07001876
1877 free(sortedEntries);
1878done:
1879 dvmUnlockMutex(&gDvmJit.tableLock);
1880 return;
1881}
jeffhao9e45c0b2010-02-03 10:24:05 -08001882
1883#if defined(WITH_SELF_VERIFICATION)
1884/*
1885 * The following are used to keep compiled loads and stores from modifying
1886 * memory during self verification mode.
1887 *
1888 * Stores do not modify memory. Instead, the address and value pair are stored
1889 * into heapSpace. Addresses within heapSpace are unique. For accesses smaller
1890 * than a word, the word containing the address is loaded first before being
1891 * updated.
1892 *
1893 * Loads check heapSpace first and return data from there if an entry exists.
1894 * Otherwise, data is loaded from memory as usual.
1895 */
1896
1897/* Used to specify sizes of memory operations */
1898enum {
1899 kSVByte,
1900 kSVSignedByte,
1901 kSVHalfword,
1902 kSVSignedHalfword,
1903 kSVWord,
1904 kSVDoubleword,
jeffhao121ea792010-02-10 10:51:02 -08001905 kSVVariable,
jeffhao9e45c0b2010-02-03 10:24:05 -08001906};
1907
1908/* Load the value of a decoded register from the stack */
1909static int selfVerificationMemRegLoad(int* sp, int reg)
1910{
1911 return *(sp + reg);
1912}
1913
1914/* Load the value of a decoded doubleword register from the stack */
1915static s8 selfVerificationMemRegLoadDouble(int* sp, int reg)
1916{
1917 return *((s8*)(sp + reg));
1918}
1919
1920/* Store the value of a decoded register out to the stack */
1921static void selfVerificationMemRegStore(int* sp, int data, int reg)
1922{
1923 *(sp + reg) = data;
1924}
1925
1926/* Store the value of a decoded doubleword register out to the stack */
1927static void selfVerificationMemRegStoreDouble(int* sp, s8 data, int reg)
1928{
1929 *((s8*)(sp + reg)) = data;
1930}
1931
1932/*
1933 * Load the specified size of data from the specified address, checking
1934 * heapSpace first if Self Verification mode wrote to it previously, and
1935 * falling back to actual memory otherwise.
1936 */
1937static int selfVerificationLoad(int addr, int size)
1938{
1939 Thread *self = dvmThreadSelf();
1940 ShadowSpace *shadowSpace = self->shadowSpace;
1941 ShadowHeap *heapSpacePtr;
1942
1943 int data;
1944 int maskedAddr = addr & 0xFFFFFFFC;
1945 int alignment = addr & 0x3;
1946
1947 for (heapSpacePtr = shadowSpace->heapSpace;
1948 heapSpacePtr != shadowSpace->heapSpaceTail; heapSpacePtr++) {
1949 if (heapSpacePtr->addr == maskedAddr) {
1950 addr = ((unsigned int) &(heapSpacePtr->data)) | alignment;
1951 break;
1952 }
1953 }
1954
1955 switch (size) {
1956 case kSVByte:
1957 data = *((u1*) addr);
1958 break;
1959 case kSVSignedByte:
1960 data = *((s1*) addr);
1961 break;
1962 case kSVHalfword:
1963 data = *((u2*) addr);
1964 break;
1965 case kSVSignedHalfword:
1966 data = *((s2*) addr);
1967 break;
1968 case kSVWord:
1969 data = *((u4*) addr);
jeffhao91080d22010-02-09 14:55:47 -08001970 break;
jeffhaoe8667642010-02-05 15:08:23 -08001971 default:
jeffhao91080d22010-02-09 14:55:47 -08001972 LOGE("*** ERROR: BAD SIZE IN selfVerificationLoad: %d", size);
jeffhaoe8667642010-02-05 15:08:23 -08001973 data = 0;
1974 dvmAbort();
jeffhao9e45c0b2010-02-03 10:24:05 -08001975 }
1976
1977 //LOGD("*** HEAP LOAD: Addr: 0x%x Data: 0x%x Size: %d", addr, data, size);
1978 return data;
1979}
1980
1981/* Like selfVerificationLoad, but specifically for doublewords */
1982static s8 selfVerificationLoadDoubleword(int addr)
1983{
1984 Thread *self = dvmThreadSelf();
1985 ShadowSpace* shadowSpace = self->shadowSpace;
1986 ShadowHeap* heapSpacePtr;
1987
1988 int addr2 = addr+4;
1989 unsigned int data = *((unsigned int*) addr);
1990 unsigned int data2 = *((unsigned int*) addr2);
1991
1992 for (heapSpacePtr = shadowSpace->heapSpace;
1993 heapSpacePtr != shadowSpace->heapSpaceTail; heapSpacePtr++) {
1994 if (heapSpacePtr->addr == addr) {
1995 data = heapSpacePtr->data;
1996 } else if (heapSpacePtr->addr == addr2) {
1997 data2 = heapSpacePtr->data;
1998 }
1999 }
2000
2001 //LOGD("*** HEAP LOAD DOUBLEWORD: Addr: 0x%x Data: 0x%x Data2: 0x%x",
2002 // addr, data, data2);
2003 return (((s8) data2) << 32) | data;
2004}
2005
2006/*
2007 * Handles a store of a specified size of data to a specified address.
2008 * This gets logged as an addr/data pair in heapSpace instead of modifying
2009 * memory. Addresses in heapSpace are unique, and accesses smaller than a
2010 * word pull the entire word from memory first before updating.
2011 */
2012static void selfVerificationStore(int addr, int data, int size)
2013{
2014 Thread *self = dvmThreadSelf();
2015 ShadowSpace *shadowSpace = self->shadowSpace;
2016 ShadowHeap *heapSpacePtr;
2017
2018 int maskedAddr = addr & 0xFFFFFFFC;
2019 int alignment = addr & 0x3;
2020
2021 //LOGD("*** HEAP STORE: Addr: 0x%x Data: 0x%x Size: %d", addr, data, size);
2022
2023 for (heapSpacePtr = shadowSpace->heapSpace;
2024 heapSpacePtr != shadowSpace->heapSpaceTail; heapSpacePtr++) {
2025 if (heapSpacePtr->addr == maskedAddr) break;
2026 }
2027
2028 if (heapSpacePtr == shadowSpace->heapSpaceTail) {
2029 heapSpacePtr->addr = maskedAddr;
2030 heapSpacePtr->data = *((unsigned int*) maskedAddr);
2031 shadowSpace->heapSpaceTail++;
2032 }
2033
2034 addr = ((unsigned int) &(heapSpacePtr->data)) | alignment;
2035 switch (size) {
2036 case kSVByte:
2037 *((u1*) addr) = data;
2038 break;
2039 case kSVSignedByte:
2040 *((s1*) addr) = data;
2041 break;
2042 case kSVHalfword:
2043 *((u2*) addr) = data;
2044 break;
2045 case kSVSignedHalfword:
2046 *((s2*) addr) = data;
2047 break;
2048 case kSVWord:
2049 *((u4*) addr) = data;
jeffhao91080d22010-02-09 14:55:47 -08002050 break;
jeffhaoe8667642010-02-05 15:08:23 -08002051 default:
jeffhao91080d22010-02-09 14:55:47 -08002052 LOGE("*** ERROR: BAD SIZE IN selfVerificationSave: %d", size);
jeffhaoe8667642010-02-05 15:08:23 -08002053 dvmAbort();
jeffhao9e45c0b2010-02-03 10:24:05 -08002054 }
2055}
2056
2057/* Like selfVerificationStore, but specifically for doublewords */
2058static void selfVerificationStoreDoubleword(int addr, s8 double_data)
2059{
2060 Thread *self = dvmThreadSelf();
2061 ShadowSpace *shadowSpace = self->shadowSpace;
2062 ShadowHeap *heapSpacePtr;
2063
2064 int addr2 = addr+4;
2065 int data = double_data;
2066 int data2 = double_data >> 32;
2067 bool store1 = false, store2 = false;
2068
2069 //LOGD("*** HEAP STORE DOUBLEWORD: Addr: 0x%x Data: 0x%x, Data2: 0x%x",
2070 // addr, data, data2);
2071
2072 for (heapSpacePtr = shadowSpace->heapSpace;
2073 heapSpacePtr != shadowSpace->heapSpaceTail; heapSpacePtr++) {
2074 if (heapSpacePtr->addr == addr) {
2075 heapSpacePtr->data = data;
2076 store1 = true;
2077 } else if (heapSpacePtr->addr == addr2) {
2078 heapSpacePtr->data = data2;
2079 store2 = true;
2080 }
2081 }
2082
2083 if (!store1) {
2084 shadowSpace->heapSpaceTail->addr = addr;
2085 shadowSpace->heapSpaceTail->data = data;
2086 shadowSpace->heapSpaceTail++;
2087 }
2088 if (!store2) {
2089 shadowSpace->heapSpaceTail->addr = addr2;
2090 shadowSpace->heapSpaceTail->data = data2;
2091 shadowSpace->heapSpaceTail++;
2092 }
2093}
2094
2095/*
2096 * Decodes the memory instruction at the address specified in the link
2097 * register. All registers (r0-r12,lr) and fp registers (d0-d15) are stored
2098 * consecutively on the stack beginning at the specified stack pointer.
2099 * Calls the proper Self Verification handler for the memory instruction and
2100 * updates the link register to point past the decoded memory instruction.
2101 */
2102void dvmSelfVerificationMemOpDecode(int lr, int* sp)
2103{
2104 enum {
2105 kMemOpLdrPcRel = 0x09, // ldr(3) [01001] rd[10..8] imm_8[7..0]
2106 kMemOpRRR = 0x0A, // Full opcode is 7 bits
2107 kMemOp2Single = 0x0A, // Used for Vstrs and Vldrs
2108 kMemOpRRR2 = 0x0B, // Full opcode is 7 bits
2109 kMemOp2Double = 0x0B, // Used for Vstrd and Vldrd
2110 kMemOpStrRRI5 = 0x0C, // str(1) [01100] imm_5[10..6] rn[5..3] rd[2..0]
2111 kMemOpLdrRRI5 = 0x0D, // ldr(1) [01101] imm_5[10..6] rn[5..3] rd[2..0]
2112 kMemOpStrbRRI5 = 0x0E, // strb(1) [01110] imm_5[10..6] rn[5..3] rd[2..0]
2113 kMemOpLdrbRRI5 = 0x0F, // ldrb(1) [01111] imm_5[10..6] rn[5..3] rd[2..0]
2114 kMemOpStrhRRI5 = 0x10, // strh(1) [10000] imm_5[10..6] rn[5..3] rd[2..0]
2115 kMemOpLdrhRRI5 = 0x11, // ldrh(1) [10001] imm_5[10..6] rn[5..3] rd[2..0]
2116 kMemOpLdrSpRel = 0x13, // ldr(4) [10011] rd[10..8] imm_8[7..0]
jeffhao121ea792010-02-10 10:51:02 -08002117 kMemOpStmia = 0x18, // stmia [11000] rn[10..8] reglist [7..0]
2118 kMemOpLdmia = 0x19, // ldmia [11001] rn[10..8] reglist [7..0]
jeffhao9e45c0b2010-02-03 10:24:05 -08002119 kMemOpStrRRR = 0x28, // str(2) [0101000] rm[8..6] rn[5..3] rd[2..0]
2120 kMemOpStrhRRR = 0x29, // strh(2) [0101001] rm[8..6] rn[5..3] rd[2..0]
2121 kMemOpStrbRRR = 0x2A, // strb(2) [0101010] rm[8..6] rn[5..3] rd[2..0]
2122 kMemOpLdrsbRRR = 0x2B, // ldrsb [0101011] rm[8..6] rn[5..3] rd[2..0]
2123 kMemOpLdrRRR = 0x2C, // ldr(2) [0101100] rm[8..6] rn[5..3] rd[2..0]
2124 kMemOpLdrhRRR = 0x2D, // ldrh(2) [0101101] rm[8..6] rn[5..3] rd[2..0]
2125 kMemOpLdrbRRR = 0x2E, // ldrb(2) [0101110] rm[8..6] rn[5..3] rd[2..0]
2126 kMemOpLdrshRRR = 0x2F, // ldrsh [0101111] rm[8..6] rn[5..3] rd[2..0]
jeffhao121ea792010-02-10 10:51:02 -08002127 kMemOp2Stmia = 0xE88, // stmia [111010001000[ rn[19..16] mask[15..0]
2128 kMemOp2Ldmia = 0xE89, // ldmia [111010001001[ rn[19..16] mask[15..0]
2129 kMemOp2Stmia2 = 0xE8A, // stmia [111010001010[ rn[19..16] mask[15..0]
2130 kMemOp2Ldmia2 = 0xE8B, // ldmia [111010001011[ rn[19..16] mask[15..0]
jeffhao9e45c0b2010-02-03 10:24:05 -08002131 kMemOp2Vstr = 0xED8, // Used for Vstrs and Vstrd
2132 kMemOp2Vldr = 0xED9, // Used for Vldrs and Vldrd
2133 kMemOp2Vstr2 = 0xEDC, // Used for Vstrs and Vstrd
2134 kMemOp2Vldr2 = 0xEDD, // Used for Vstrs and Vstrd
2135 kMemOp2StrbRRR = 0xF80, /* str rt,[rn,rm,LSL #imm] [111110000000]
2136 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2137 kMemOp2LdrbRRR = 0xF81, /* ldrb rt,[rn,rm,LSL #imm] [111110000001]
2138 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2139 kMemOp2StrhRRR = 0xF82, /* str rt,[rn,rm,LSL #imm] [111110000010]
2140 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2141 kMemOp2LdrhRRR = 0xF83, /* ldrh rt,[rn,rm,LSL #imm] [111110000011]
2142 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2143 kMemOp2StrRRR = 0xF84, /* str rt,[rn,rm,LSL #imm] [111110000100]
2144 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2145 kMemOp2LdrRRR = 0xF85, /* ldr rt,[rn,rm,LSL #imm] [111110000101]
2146 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2147 kMemOp2StrbRRI12 = 0xF88, /* strb rt,[rn,#imm12] [111110001000]
2148 rt[15..12] rn[19..16] imm12[11..0] */
2149 kMemOp2LdrbRRI12 = 0xF89, /* ldrb rt,[rn,#imm12] [111110001001]
2150 rt[15..12] rn[19..16] imm12[11..0] */
2151 kMemOp2StrhRRI12 = 0xF8A, /* strh rt,[rn,#imm12] [111110001010]
2152 rt[15..12] rn[19..16] imm12[11..0] */
2153 kMemOp2LdrhRRI12 = 0xF8B, /* ldrh rt,[rn,#imm12] [111110001011]
2154 rt[15..12] rn[19..16] imm12[11..0] */
2155 kMemOp2StrRRI12 = 0xF8C, /* str(Imm,T3) rd,[rn,#imm12] [111110001100]
2156 rn[19..16] rt[15..12] imm12[11..0] */
2157 kMemOp2LdrRRI12 = 0xF8D, /* ldr(Imm,T3) rd,[rn,#imm12] [111110001101]
2158 rn[19..16] rt[15..12] imm12[11..0] */
2159 kMemOp2LdrsbRRR = 0xF91, /* ldrsb rt,[rn,rm,LSL #imm] [111110010001]
2160 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2161 kMemOp2LdrshRRR = 0xF93, /* ldrsh rt,[rn,rm,LSL #imm] [111110010011]
2162 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2163 kMemOp2LdrsbRRI12 = 0xF99, /* ldrsb rt,[rn,#imm12] [111110011001]
2164 rt[15..12] rn[19..16] imm12[11..0] */
2165 kMemOp2LdrshRRI12 = 0xF9B, /* ldrsh rt,[rn,#imm12] [111110011011]
2166 rt[15..12] rn[19..16] imm12[11..0] */
2167 kMemOp2 = 0xE000, // top 3 bits set indicates Thumb2
2168 };
2169
2170 int addr, offset, data;
2171 long long double_data;
2172 int size = kSVWord;
2173 bool store = false;
2174 unsigned int *lr_masked = (unsigned int *) (lr & 0xFFFFFFFE);
2175 unsigned int insn = *lr_masked;
2176
2177 int old_lr;
2178 old_lr = selfVerificationMemRegLoad(sp, 13);
2179
2180 if ((insn & kMemOp2) == kMemOp2) {
2181 insn = (insn << 16) | (insn >> 16);
2182 //LOGD("*** THUMB2 - Addr: 0x%x Insn: 0x%x", lr, insn);
2183
2184 int opcode12 = (insn >> 20) & 0xFFF;
2185 int opcode6 = (insn >> 6) & 0x3F;
2186 int opcode4 = (insn >> 8) & 0xF;
2187 int imm2 = (insn >> 4) & 0x3;
2188 int imm8 = insn & 0xFF;
2189 int imm12 = insn & 0xFFF;
2190 int rd = (insn >> 12) & 0xF;
2191 int rm = insn & 0xF;
2192 int rn = (insn >> 16) & 0xF;
2193 int rt = (insn >> 12) & 0xF;
jeffhao121ea792010-02-10 10:51:02 -08002194 bool wBack = true;
jeffhao9e45c0b2010-02-03 10:24:05 -08002195
2196 // Update the link register
2197 selfVerificationMemRegStore(sp, old_lr+4, 13);
2198
2199 // Determine whether the mem op is a store or load
2200 switch (opcode12) {
jeffhao121ea792010-02-10 10:51:02 -08002201 case kMemOp2Stmia:
2202 case kMemOp2Stmia2:
jeffhao9e45c0b2010-02-03 10:24:05 -08002203 case kMemOp2Vstr:
2204 case kMemOp2Vstr2:
2205 case kMemOp2StrbRRR:
2206 case kMemOp2StrhRRR:
2207 case kMemOp2StrRRR:
2208 case kMemOp2StrbRRI12:
2209 case kMemOp2StrhRRI12:
2210 case kMemOp2StrRRI12:
2211 store = true;
2212 }
2213
2214 // Determine the size of the mem access
2215 switch (opcode12) {
2216 case kMemOp2StrbRRR:
2217 case kMemOp2LdrbRRR:
2218 case kMemOp2StrbRRI12:
2219 case kMemOp2LdrbRRI12:
2220 size = kSVByte;
2221 break;
2222 case kMemOp2LdrsbRRR:
2223 case kMemOp2LdrsbRRI12:
2224 size = kSVSignedByte;
2225 break;
2226 case kMemOp2StrhRRR:
2227 case kMemOp2LdrhRRR:
2228 case kMemOp2StrhRRI12:
2229 case kMemOp2LdrhRRI12:
2230 size = kSVHalfword;
2231 break;
2232 case kMemOp2LdrshRRR:
2233 case kMemOp2LdrshRRI12:
2234 size = kSVSignedHalfword;
2235 break;
2236 case kMemOp2Vstr:
2237 case kMemOp2Vstr2:
2238 case kMemOp2Vldr:
2239 case kMemOp2Vldr2:
2240 if (opcode4 == kMemOp2Double) size = kSVDoubleword;
2241 break;
jeffhao121ea792010-02-10 10:51:02 -08002242 case kMemOp2Stmia:
2243 case kMemOp2Ldmia:
2244 case kMemOp2Stmia2:
2245 case kMemOp2Ldmia2:
2246 size = kSVVariable;
2247 break;
jeffhao9e45c0b2010-02-03 10:24:05 -08002248 }
2249
2250 // Load the value of the address
2251 addr = selfVerificationMemRegLoad(sp, rn);
2252
2253 // Figure out the offset
2254 switch (opcode12) {
2255 case kMemOp2Vstr:
2256 case kMemOp2Vstr2:
2257 case kMemOp2Vldr:
2258 case kMemOp2Vldr2:
2259 offset = imm8 << 2;
2260 if (opcode4 == kMemOp2Single) {
2261 rt = rd << 1;
2262 if (insn & 0x400000) rt |= 0x1;
2263 } else if (opcode4 == kMemOp2Double) {
2264 if (insn & 0x400000) rt |= 0x10;
2265 rt = rt << 1;
2266 } else {
jeffhao91080d22010-02-09 14:55:47 -08002267 LOGE("*** ERROR: UNRECOGNIZED VECTOR MEM OP: %x", opcode4);
jeffhao9e45c0b2010-02-03 10:24:05 -08002268 dvmAbort();
2269 }
2270 rt += 14;
2271 break;
2272 case kMemOp2StrbRRR:
2273 case kMemOp2LdrbRRR:
2274 case kMemOp2StrhRRR:
2275 case kMemOp2LdrhRRR:
2276 case kMemOp2StrRRR:
2277 case kMemOp2LdrRRR:
2278 case kMemOp2LdrsbRRR:
2279 case kMemOp2LdrshRRR:
2280 offset = selfVerificationMemRegLoad(sp, rm) << imm2;
2281 break;
2282 case kMemOp2StrbRRI12:
2283 case kMemOp2LdrbRRI12:
2284 case kMemOp2StrhRRI12:
2285 case kMemOp2LdrhRRI12:
2286 case kMemOp2StrRRI12:
2287 case kMemOp2LdrRRI12:
2288 case kMemOp2LdrsbRRI12:
2289 case kMemOp2LdrshRRI12:
2290 offset = imm12;
2291 break;
jeffhao121ea792010-02-10 10:51:02 -08002292 case kMemOp2Stmia:
2293 case kMemOp2Ldmia:
2294 wBack = false;
2295 case kMemOp2Stmia2:
2296 case kMemOp2Ldmia2:
2297 offset = 0;
2298 break;
jeffhao9e45c0b2010-02-03 10:24:05 -08002299 default:
jeffhao91080d22010-02-09 14:55:47 -08002300 LOGE("*** ERROR: UNRECOGNIZED THUMB2 MEM OP: %x", opcode12);
jeffhaoe8667642010-02-05 15:08:23 -08002301 offset = 0;
jeffhao9e45c0b2010-02-03 10:24:05 -08002302 dvmAbort();
2303 }
2304
2305 // Handle the decoded mem op accordingly
2306 if (store) {
jeffhao121ea792010-02-10 10:51:02 -08002307 if (size == kSVVariable) {
2308 LOGD("*** THUMB2 STMIA CURRENTLY UNUSED (AND UNTESTED)");
2309 int i;
2310 int regList = insn & 0xFFFF;
2311 for (i = 0; i < 16; i++) {
2312 if (regList & 0x1) {
2313 data = selfVerificationMemRegLoad(sp, i);
2314 selfVerificationStore(addr, data, kSVWord);
2315 addr += 4;
2316 }
2317 regList = regList >> 1;
2318 }
2319 if (wBack) selfVerificationMemRegStore(sp, addr, rn);
2320 } else if (size == kSVDoubleword) {
jeffhao9e45c0b2010-02-03 10:24:05 -08002321 double_data = selfVerificationMemRegLoadDouble(sp, rt);
2322 selfVerificationStoreDoubleword(addr+offset, double_data);
2323 } else {
2324 data = selfVerificationMemRegLoad(sp, rt);
2325 selfVerificationStore(addr+offset, data, size);
2326 }
2327 } else {
jeffhao121ea792010-02-10 10:51:02 -08002328 if (size == kSVVariable) {
2329 LOGD("*** THUMB2 LDMIA CURRENTLY UNUSED (AND UNTESTED)");
2330 int i;
2331 int regList = insn & 0xFFFF;
2332 for (i = 0; i < 16; i++) {
2333 if (regList & 0x1) {
2334 data = selfVerificationLoad(addr, kSVWord);
2335 selfVerificationMemRegStore(sp, data, i);
2336 addr += 4;
2337 }
2338 regList = regList >> 1;
2339 }
2340 if (wBack) selfVerificationMemRegStore(sp, addr, rn);
2341 } else if (size == kSVDoubleword) {
jeffhao9e45c0b2010-02-03 10:24:05 -08002342 double_data = selfVerificationLoadDoubleword(addr+offset);
2343 selfVerificationMemRegStoreDouble(sp, double_data, rt);
2344 } else {
2345 data = selfVerificationLoad(addr+offset, size);
2346 selfVerificationMemRegStore(sp, data, rt);
2347 }
2348 }
2349 } else {
2350 //LOGD("*** THUMB - Addr: 0x%x Insn: 0x%x", lr, insn);
2351
2352 // Update the link register
2353 selfVerificationMemRegStore(sp, old_lr+2, 13);
2354
2355 int opcode5 = (insn >> 11) & 0x1F;
2356 int opcode7 = (insn >> 9) & 0x7F;
2357 int imm = (insn >> 6) & 0x1F;
2358 int rd = (insn >> 8) & 0x7;
2359 int rm = (insn >> 6) & 0x7;
2360 int rn = (insn >> 3) & 0x7;
2361 int rt = insn & 0x7;
2362
2363 // Determine whether the mem op is a store or load
2364 switch (opcode5) {
2365 case kMemOpRRR:
2366 switch (opcode7) {
2367 case kMemOpStrRRR:
2368 case kMemOpStrhRRR:
2369 case kMemOpStrbRRR:
2370 store = true;
2371 }
2372 break;
2373 case kMemOpStrRRI5:
2374 case kMemOpStrbRRI5:
2375 case kMemOpStrhRRI5:
jeffhao121ea792010-02-10 10:51:02 -08002376 case kMemOpStmia:
jeffhao9e45c0b2010-02-03 10:24:05 -08002377 store = true;
2378 }
2379
2380 // Determine the size of the mem access
2381 switch (opcode5) {
2382 case kMemOpRRR:
2383 case kMemOpRRR2:
2384 switch (opcode7) {
2385 case kMemOpStrbRRR:
2386 case kMemOpLdrbRRR:
2387 size = kSVByte;
2388 break;
2389 case kMemOpLdrsbRRR:
2390 size = kSVSignedByte;
2391 break;
2392 case kMemOpStrhRRR:
2393 case kMemOpLdrhRRR:
2394 size = kSVHalfword;
2395 break;
2396 case kMemOpLdrshRRR:
2397 size = kSVSignedHalfword;
2398 break;
2399 }
2400 break;
2401 case kMemOpStrbRRI5:
2402 case kMemOpLdrbRRI5:
2403 size = kSVByte;
2404 break;
2405 case kMemOpStrhRRI5:
2406 case kMemOpLdrhRRI5:
2407 size = kSVHalfword;
2408 break;
jeffhao121ea792010-02-10 10:51:02 -08002409 case kMemOpStmia:
2410 case kMemOpLdmia:
2411 size = kSVVariable;
2412 break;
jeffhao9e45c0b2010-02-03 10:24:05 -08002413 }
2414
2415 // Load the value of the address
2416 if (opcode5 == kMemOpLdrPcRel)
2417 addr = selfVerificationMemRegLoad(sp, 4);
jeffhao121ea792010-02-10 10:51:02 -08002418 else if (opcode5 == kMemOpStmia || opcode5 == kMemOpLdmia)
2419 addr = selfVerificationMemRegLoad(sp, rd);
jeffhao9e45c0b2010-02-03 10:24:05 -08002420 else
2421 addr = selfVerificationMemRegLoad(sp, rn);
2422
2423 // Figure out the offset
2424 switch (opcode5) {
2425 case kMemOpLdrPcRel:
2426 offset = (insn & 0xFF) << 2;
2427 rt = rd;
2428 break;
2429 case kMemOpRRR:
2430 case kMemOpRRR2:
2431 offset = selfVerificationMemRegLoad(sp, rm);
2432 break;
2433 case kMemOpStrRRI5:
2434 case kMemOpLdrRRI5:
2435 offset = imm << 2;
2436 break;
2437 case kMemOpStrhRRI5:
2438 case kMemOpLdrhRRI5:
2439 offset = imm << 1;
2440 break;
2441 case kMemOpStrbRRI5:
2442 case kMemOpLdrbRRI5:
2443 offset = imm;
2444 break;
jeffhao121ea792010-02-10 10:51:02 -08002445 case kMemOpStmia:
2446 case kMemOpLdmia:
2447 offset = 0;
2448 break;
jeffhao9e45c0b2010-02-03 10:24:05 -08002449 default:
jeffhao91080d22010-02-09 14:55:47 -08002450 LOGE("*** ERROR: UNRECOGNIZED THUMB MEM OP: %x", opcode5);
jeffhaoe8667642010-02-05 15:08:23 -08002451 offset = 0;
jeffhao9e45c0b2010-02-03 10:24:05 -08002452 dvmAbort();
2453 }
2454
2455 // Handle the decoded mem op accordingly
2456 if (store) {
jeffhao121ea792010-02-10 10:51:02 -08002457 if (size == kSVVariable) {
2458 int i;
2459 int regList = insn & 0xFF;
2460 for (i = 0; i < 8; i++) {
2461 if (regList & 0x1) {
2462 data = selfVerificationMemRegLoad(sp, i);
2463 selfVerificationStore(addr, data, kSVWord);
2464 addr += 4;
2465 }
2466 regList = regList >> 1;
2467 }
2468 selfVerificationMemRegStore(sp, addr, rd);
2469 } else {
2470 data = selfVerificationMemRegLoad(sp, rt);
2471 selfVerificationStore(addr+offset, data, size);
2472 }
jeffhao9e45c0b2010-02-03 10:24:05 -08002473 } else {
jeffhao121ea792010-02-10 10:51:02 -08002474 if (size == kSVVariable) {
2475 bool wBack = true;
2476 int i;
2477 int regList = insn & 0xFF;
2478 for (i = 0; i < 8; i++) {
2479 if (regList & 0x1) {
2480 if (i == rd) wBack = false;
2481 data = selfVerificationLoad(addr, kSVWord);
2482 selfVerificationMemRegStore(sp, data, i);
2483 addr += 4;
2484 }
2485 regList = regList >> 1;
2486 }
2487 if (wBack) selfVerificationMemRegStore(sp, addr, rd);
2488 } else {
2489 data = selfVerificationLoad(addr+offset, size);
2490 selfVerificationMemRegStore(sp, data, rt);
2491 }
jeffhao9e45c0b2010-02-03 10:24:05 -08002492 }
2493 }
2494}
2495#endif