blob: c1b08a3cc046ad2ff32afb296688f94db6186df0 [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"
Andy McFaddenc6b25c72010-06-22 11:01:20 -070019#include "libdex/OpCodeNames.h"
Ben Chengba4fc8b2009-06-01 13:00:29 -070020
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 */
Ben Chengb88ec3c2010-05-17 12:50:33 -070024#include <sys/mman.h> /* for protection change */
Ben Chengba4fc8b2009-06-01 13:00:29 -070025
26/*
Bill Buzbee89efc3d2009-07-28 11:22:22 -070027 * opcode: ArmOpCode enum
Ben Chengba4fc8b2009-06-01 13:00:29 -070028 * skeleton: pre-designated bit-pattern for this opcode
Bill Buzbee9bc3df32009-07-30 10:52:29 -070029 * k0: key to applying ds/de
Ben Chengba4fc8b2009-06-01 13:00:29 -070030 * ds: dest start bit position
31 * de: dest end bit position
Bill Buzbee9bc3df32009-07-30 10:52:29 -070032 * k1: key to applying s1s/s1e
Ben Chengba4fc8b2009-06-01 13:00:29 -070033 * s1s: src1 start bit position
34 * s1e: src1 end bit position
Bill Buzbee9bc3df32009-07-30 10:52:29 -070035 * k2: key to applying s2s/s2e
Ben Chengba4fc8b2009-06-01 13:00:29 -070036 * s2s: src2 start bit position
37 * s2e: src2 end bit position
38 * operands: number of operands (for sanity check purposes)
39 * name: mnemonic name
Elliott Hughesb4c05972010-02-24 16:36:18 -080040 * fmt: for pretty-printing
Ben Chengba4fc8b2009-06-01 13:00:29 -070041 */
Bill Buzbee9bc3df32009-07-30 10:52:29 -070042#define ENCODING_MAP(opcode, skeleton, k0, ds, de, k1, s1s, s1e, k2, s2s, s2e, \
Ben Chengdcf3e5d2009-09-11 13:42:05 -070043 k3, k3s, k3e, flags, name, fmt, size) \
Bill Buzbee270c1d62009-08-13 16:58:07 -070044 {skeleton, {{k0, ds, de}, {k1, s1s, s1e}, {k2, s2s, s2e}, \
Ben Chengdcf3e5d2009-09-11 13:42:05 -070045 {k3, k3s, k3e}}, opcode, flags, name, fmt, size}
Ben Chengba4fc8b2009-06-01 13:00:29 -070046
47/* Instruction dump string format keys: !pf, where "!" is the start
48 * of the key, "p" is which numeric operand to use and "f" is the
49 * print format.
50 *
51 * [p]ositions:
52 * 0 -> operands[0] (dest)
53 * 1 -> operands[1] (src1)
54 * 2 -> operands[2] (src2)
Bill Buzbee270c1d62009-08-13 16:58:07 -070055 * 3 -> operands[3] (extra)
Ben Chengba4fc8b2009-06-01 13:00:29 -070056 *
57 * [f]ormats:
58 * h -> 4-digit hex
59 * d -> decimal
Ben Chengba4fc8b2009-06-01 13:00:29 -070060 * E -> decimal*4
61 * F -> decimal*2
62 * c -> branch condition (beq, bne, etc.)
63 * t -> pc-relative target
64 * u -> 1st half of bl[x] target
65 * v -> 2nd half ob bl[x] target
66 * R -> register list
Bill Buzbee9727c3d2009-08-01 11:32:36 -070067 * s -> single precision floating point register
68 * S -> double precision floating point register
Bill Buzbee7ea0f642009-08-10 17:06:51 -070069 * m -> Thumb2 modified immediate
Bill Buzbee270c1d62009-08-13 16:58:07 -070070 * n -> complimented Thumb2 modified immediate
Bill Buzbee7ea0f642009-08-10 17:06:51 -070071 * M -> Thumb2 16-bit zero-extended immediate
Bill Buzbeea4a7f072009-08-27 13:58:09 -070072 * b -> 4-digit binary
buzbeeecf8f6e2010-07-20 14:53:42 -070073 * B -> dmb option string (sy, st, ish, ishst, nsh, hshst)
Ben Chengba4fc8b2009-06-01 13:00:29 -070074 *
75 * [!] escape. To insert "!", use "!!"
76 */
Bill Buzbee89efc3d2009-07-28 11:22:22 -070077/* NOTE: must be kept in sync with enum ArmOpcode from ArmLIR.h */
Bill Buzbee1465db52009-09-23 17:17:35 -070078ArmEncodingMap EncodingMap[kArmLast] = {
79 ENCODING_MAP(kArm16BitData, 0x0000,
80 kFmtBitBlt, 15, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
81 kFmtUnused, -1, -1, IS_UNARY_OP, "data", "0x!0h(!0d)", 1),
82 ENCODING_MAP(kThumbAdcRR, 0x4140,
83 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
84 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -070085 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES | USES_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -070086 "adcs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -070087 ENCODING_MAP(kThumbAddRRI3, 0x1c00,
88 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
89 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -070090 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -070091 "adds", "r!0d, r!1d, #!2d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -070092 ENCODING_MAP(kThumbAddRI8, 0x3000,
93 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
94 kFmtUnused, -1, -1,
Ben Chengd7d426a2009-09-22 11:23:36 -070095 IS_BINARY_OP | REG_DEF0_USE0 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -070096 "adds", "r!0d, r!0d, #!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -070097 ENCODING_MAP(kThumbAddRRR, 0x1800,
98 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
99 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700100 IS_TERTIARY_OP | REG_DEF0_USE12 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700101 "adds", "r!0d, r!1d, r!2d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700102 ENCODING_MAP(kThumbAddRRLH, 0x4440,
103 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
104 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE01,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700105 "add", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700106 ENCODING_MAP(kThumbAddRRHL, 0x4480,
107 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
108 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE01,
Bill Buzbee716f1202009-07-23 13:22:09 -0700109 "add", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700110 ENCODING_MAP(kThumbAddRRHH, 0x44c0,
111 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
112 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE01,
Bill Buzbee716f1202009-07-23 13:22:09 -0700113 "add", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700114 ENCODING_MAP(kThumbAddPcRel, 0xa000,
115 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
116 kFmtUnused, -1, -1, IS_TERTIARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700117 "add", "r!0d, pc, #!1E", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700118 ENCODING_MAP(kThumbAddSpRel, 0xa800,
119 kFmtBitBlt, 10, 8, kFmtUnused, -1, -1, kFmtBitBlt, 7, 0,
120 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF_SP | REG_USE_SP,
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700121 "add", "r!0d, sp, #!2E", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700122 ENCODING_MAP(kThumbAddSpI7, 0xb000,
123 kFmtBitBlt, 6, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
124 kFmtUnused, -1, -1, IS_UNARY_OP | REG_DEF_SP | REG_USE_SP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700125 "add", "sp, #!0d*4", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700126 ENCODING_MAP(kThumbAndRR, 0x4000,
127 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
128 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700129 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700130 "ands", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700131 ENCODING_MAP(kThumbAsrRRI5, 0x1000,
132 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
133 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700134 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700135 "asrs", "r!0d, r!1d, #!2d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700136 ENCODING_MAP(kThumbAsrRR, 0x4100,
137 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
138 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700139 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700140 "asrs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700141 ENCODING_MAP(kThumbBCond, 0xd000,
142 kFmtBitBlt, 7, 0, kFmtBitBlt, 11, 8, kFmtUnused, -1, -1,
143 kFmtUnused, -1, -1, IS_BINARY_OP | IS_BRANCH | USES_CCODES,
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700144 "b!1c", "!0t", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700145 ENCODING_MAP(kThumbBUncond, 0xe000,
146 kFmtBitBlt, 10, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
147 kFmtUnused, -1, -1, NO_OPERAND | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700148 "b", "!0t", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700149 ENCODING_MAP(kThumbBicRR, 0x4380,
150 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
151 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700152 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700153 "bics", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700154 ENCODING_MAP(kThumbBkpt, 0xbe00,
155 kFmtBitBlt, 7, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
156 kFmtUnused, -1, -1, IS_UNARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700157 "bkpt", "!0d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700158 ENCODING_MAP(kThumbBlx1, 0xf000,
159 kFmtBitBlt, 10, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
160 kFmtUnused, -1, -1, IS_BINARY_OP | IS_BRANCH | REG_DEF_LR,
Bill Buzbee716f1202009-07-23 13:22:09 -0700161 "blx_1", "!0u", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700162 ENCODING_MAP(kThumbBlx2, 0xe800,
163 kFmtBitBlt, 10, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
164 kFmtUnused, -1, -1, IS_BINARY_OP | IS_BRANCH | REG_DEF_LR,
Bill Buzbee716f1202009-07-23 13:22:09 -0700165 "blx_2", "!0v", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700166 ENCODING_MAP(kThumbBl1, 0xf000,
167 kFmtBitBlt, 10, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
168 kFmtUnused, -1, -1, IS_UNARY_OP | IS_BRANCH | REG_DEF_LR,
Bill Buzbee716f1202009-07-23 13:22:09 -0700169 "bl_1", "!0u", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700170 ENCODING_MAP(kThumbBl2, 0xf800,
171 kFmtBitBlt, 10, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
172 kFmtUnused, -1, -1, IS_UNARY_OP | IS_BRANCH | REG_DEF_LR,
Bill Buzbee716f1202009-07-23 13:22:09 -0700173 "bl_2", "!0v", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700174 ENCODING_MAP(kThumbBlxR, 0x4780,
175 kFmtBitBlt, 6, 3, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
176 kFmtUnused, -1, -1,
Ben Chengd7d426a2009-09-22 11:23:36 -0700177 IS_UNARY_OP | REG_USE0 | IS_BRANCH | REG_DEF_LR,
Bill Buzbee716f1202009-07-23 13:22:09 -0700178 "blx", "r!0d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700179 ENCODING_MAP(kThumbBx, 0x4700,
180 kFmtBitBlt, 6, 3, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
181 kFmtUnused, -1, -1, IS_UNARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700182 "bx", "r!0d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700183 ENCODING_MAP(kThumbCmnRR, 0x42c0,
184 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
185 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01 | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700186 "cmn", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700187 ENCODING_MAP(kThumbCmpRI8, 0x2800,
188 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
189 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE0 | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700190 "cmp", "r!0d, #!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700191 ENCODING_MAP(kThumbCmpRR, 0x4280,
192 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
193 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01 | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700194 "cmp", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700195 ENCODING_MAP(kThumbCmpLH, 0x4540,
196 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
197 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01 | SETS_CCODES,
Ben Chengd7d426a2009-09-22 11:23:36 -0700198 "cmp", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700199 ENCODING_MAP(kThumbCmpHL, 0x4580,
200 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
201 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01 | SETS_CCODES,
Ben Chengd7d426a2009-09-22 11:23:36 -0700202 "cmp", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700203 ENCODING_MAP(kThumbCmpHH, 0x45c0,
204 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
205 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01 | SETS_CCODES,
Ben Chengd7d426a2009-09-22 11:23:36 -0700206 "cmp", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700207 ENCODING_MAP(kThumbEorRR, 0x4040,
208 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
209 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700210 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700211 "eors", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700212 ENCODING_MAP(kThumbLdmia, 0xc800,
213 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
214 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800215 IS_BINARY_OP | REG_DEF0_USE0 | REG_DEF_LIST1 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700216 "ldmia", "r!0d!!, <!1R>", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700217 ENCODING_MAP(kThumbLdrRRI5, 0x6800,
218 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800219 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700220 "ldr", "r!0d, [r!1d, #!2E]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700221 ENCODING_MAP(kThumbLdrRRR, 0x5800,
222 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800223 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700224 "ldr", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700225 ENCODING_MAP(kThumbLdrPcRel, 0x4800,
226 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800227 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0 | REG_USE_PC
228 | IS_LOAD, "ldr", "r!0d, [pc, #!1E]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700229 ENCODING_MAP(kThumbLdrSpRel, 0x9800,
230 kFmtBitBlt, 10, 8, kFmtUnused, -1, -1, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800231 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0 | REG_USE_SP
232 | IS_LOAD, "ldr", "r!0d, [sp, #!2E]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700233 ENCODING_MAP(kThumbLdrbRRI5, 0x7800,
234 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800235 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700236 "ldrb", "r!0d, [r!1d, #2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700237 ENCODING_MAP(kThumbLdrbRRR, 0x5c00,
238 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800239 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700240 "ldrb", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700241 ENCODING_MAP(kThumbLdrhRRI5, 0x8800,
242 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800243 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700244 "ldrh", "r!0d, [r!1d, #!2F]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700245 ENCODING_MAP(kThumbLdrhRRR, 0x5a00,
246 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800247 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700248 "ldrh", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700249 ENCODING_MAP(kThumbLdrsbRRR, 0x5600,
250 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800251 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700252 "ldrsb", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700253 ENCODING_MAP(kThumbLdrshRRR, 0x5e00,
254 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800255 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12 | IS_LOAD,
Bill Buzbee716f1202009-07-23 13:22:09 -0700256 "ldrsh", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700257 ENCODING_MAP(kThumbLslRRI5, 0x0000,
258 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
259 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700260 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700261 "lsls", "r!0d, r!1d, #!2d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700262 ENCODING_MAP(kThumbLslRR, 0x4080,
263 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
264 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700265 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700266 "lsls", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700267 ENCODING_MAP(kThumbLsrRRI5, 0x0800,
268 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
269 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700270 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700271 "lsrs", "r!0d, r!1d, #!2d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700272 ENCODING_MAP(kThumbLsrRR, 0x40c0,
273 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
274 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700275 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700276 "lsrs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700277 ENCODING_MAP(kThumbMovImm, 0x2000,
278 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
279 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700280 IS_BINARY_OP | REG_DEF0 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700281 "movs", "r!0d, #!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700282 ENCODING_MAP(kThumbMovRR, 0x1c00,
283 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
284 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700285 IS_BINARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700286 "movs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700287 ENCODING_MAP(kThumbMovRR_H2H, 0x46c0,
288 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
289 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Ben Chengd7d426a2009-09-22 11:23:36 -0700290 "mov", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700291 ENCODING_MAP(kThumbMovRR_H2L, 0x4640,
292 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
293 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Ben Chengd7d426a2009-09-22 11:23:36 -0700294 "mov", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700295 ENCODING_MAP(kThumbMovRR_L2H, 0x4680,
296 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
297 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Ben Chengd7d426a2009-09-22 11:23:36 -0700298 "mov", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700299 ENCODING_MAP(kThumbMul, 0x4340,
300 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
301 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700302 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700303 "muls", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700304 ENCODING_MAP(kThumbMvn, 0x43c0,
305 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
306 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700307 IS_BINARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700308 "mvns", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700309 ENCODING_MAP(kThumbNeg, 0x4240,
310 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
311 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700312 IS_BINARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700313 "negs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700314 ENCODING_MAP(kThumbOrr, 0x4300,
315 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
316 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700317 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700318 "orrs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700319 ENCODING_MAP(kThumbPop, 0xbc00,
320 kFmtBitBlt, 8, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
321 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800322 IS_UNARY_OP | REG_DEF_SP | REG_USE_SP | REG_DEF_LIST0
323 | IS_LOAD, "pop", "<!0R>", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700324 ENCODING_MAP(kThumbPush, 0xb400,
325 kFmtBitBlt, 8, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
326 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800327 IS_UNARY_OP | REG_DEF_SP | REG_USE_SP | REG_USE_LIST0
328 | IS_STORE, "push", "<!0R>", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700329 ENCODING_MAP(kThumbRorRR, 0x41c0,
330 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
331 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700332 IS_BINARY_OP | REG_DEF0_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700333 "rors", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700334 ENCODING_MAP(kThumbSbc, 0x4180,
335 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
336 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700337 IS_BINARY_OP | REG_DEF0_USE01 | USES_CCODES | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700338 "sbcs", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700339 ENCODING_MAP(kThumbStmia, 0xc000,
340 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
341 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800342 IS_BINARY_OP | REG_DEF0 | REG_USE0 | REG_USE_LIST1 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700343 "stmia", "r!0d!!, <!1R>", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700344 ENCODING_MAP(kThumbStrRRI5, 0x6000,
345 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800346 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700347 "str", "r!0d, [r!1d, #!2E]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700348 ENCODING_MAP(kThumbStrRRR, 0x5000,
349 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800350 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE012 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700351 "str", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700352 ENCODING_MAP(kThumbStrSpRel, 0x9000,
353 kFmtBitBlt, 10, 8, kFmtUnused, -1, -1, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800354 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE0 | REG_USE_SP
355 | IS_STORE, "str", "r!0d, [sp, #!2E]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700356 ENCODING_MAP(kThumbStrbRRI5, 0x7000,
357 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800358 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700359 "strb", "r!0d, [r!1d, #!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700360 ENCODING_MAP(kThumbStrbRRR, 0x5400,
361 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800362 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE012 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700363 "strb", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700364 ENCODING_MAP(kThumbStrhRRI5, 0x8000,
365 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 10, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800366 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700367 "strh", "r!0d, [r!1d, #!2F]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700368 ENCODING_MAP(kThumbStrhRRR, 0x5200,
369 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
Bill Buzbee1f748632010-03-02 16:14:41 -0800370 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE012 | IS_STORE,
Bill Buzbee716f1202009-07-23 13:22:09 -0700371 "strh", "r!0d, [r!1d, r!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700372 ENCODING_MAP(kThumbSubRRI3, 0x1e00,
373 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
374 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700375 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700376 "subs", "r!0d, r!1d, #!2d]", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700377 ENCODING_MAP(kThumbSubRI8, 0x3800,
378 kFmtBitBlt, 10, 8, kFmtBitBlt, 7, 0, kFmtUnused, -1, -1,
379 kFmtUnused, -1, -1,
Ben Chengd7d426a2009-09-22 11:23:36 -0700380 IS_BINARY_OP | REG_DEF0_USE0 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700381 "subs", "r!0d, #!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700382 ENCODING_MAP(kThumbSubRRR, 0x1a00,
383 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtBitBlt, 8, 6,
384 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700385 IS_TERTIARY_OP | REG_DEF0_USE12 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700386 "subs", "r!0d, r!1d, r!2d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700387 ENCODING_MAP(kThumbSubSpI7, 0xb080,
388 kFmtBitBlt, 6, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
389 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700390 IS_UNARY_OP | REG_DEF_SP | REG_USE_SP,
Bill Buzbee716f1202009-07-23 13:22:09 -0700391 "sub", "sp, #!0d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700392 ENCODING_MAP(kThumbSwi, 0xdf00,
393 kFmtBitBlt, 7, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1, kFmtUnused, -1, -1, IS_UNARY_OP | IS_BRANCH,
Bill Buzbee716f1202009-07-23 13:22:09 -0700394 "swi", "!0d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700395 ENCODING_MAP(kThumbTst, 0x4200,
396 kFmtBitBlt, 2, 0, kFmtBitBlt, 5, 3, kFmtUnused, -1, -1,
397 kFmtUnused, -1, -1, IS_UNARY_OP | REG_USE01 | SETS_CCODES,
Bill Buzbee716f1202009-07-23 13:22:09 -0700398 "tst", "r!0d, r!1d", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700399 ENCODING_MAP(kThumb2Vldrs, 0xed900a00,
400 kFmtSfp, 22, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800401 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700402 "vldr", "!0s, [r!1d, #!2E]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700403 ENCODING_MAP(kThumb2Vldrd, 0xed900b00,
404 kFmtDfp, 22, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800405 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700406 "vldr", "!0S, [r!1d, #!2E]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700407 ENCODING_MAP(kThumb2Vmuls, 0xee200a00,
408 kFmtSfp, 22, 12, kFmtSfp, 7, 16, kFmtSfp, 5, 0,
409 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700410 IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700411 "vmuls", "!0s, !1s, !2s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700412 ENCODING_MAP(kThumb2Vmuld, 0xee200b00,
413 kFmtDfp, 22, 12, kFmtDfp, 7, 16, kFmtDfp, 5, 0,
414 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700415 "vmuld", "!0S, !1S, !2S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700416 ENCODING_MAP(kThumb2Vstrs, 0xed800a00,
417 kFmtSfp, 22, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800418 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700419 "vstr", "!0s, [r!1d, #!2E]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700420 ENCODING_MAP(kThumb2Vstrd, 0xed800b00,
421 kFmtDfp, 22, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800422 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700423 "vstr", "!0S, [r!1d, #!2E]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700424 ENCODING_MAP(kThumb2Vsubs, 0xee300a40,
425 kFmtSfp, 22, 12, kFmtSfp, 7, 16, kFmtSfp, 5, 0,
426 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700427 "vsub", "!0s, !1s, !2s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700428 ENCODING_MAP(kThumb2Vsubd, 0xee300b40,
429 kFmtDfp, 22, 12, kFmtDfp, 7, 16, kFmtDfp, 5, 0,
430 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700431 "vsub", "!0S, !1S, !2S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700432 ENCODING_MAP(kThumb2Vadds, 0xee300a00,
433 kFmtSfp, 22, 12, kFmtSfp, 7, 16, kFmtSfp, 5, 0,
434 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700435 "vadd", "!0s, !1s, !2s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700436 ENCODING_MAP(kThumb2Vaddd, 0xee300b00,
437 kFmtDfp, 22, 12, kFmtDfp, 7, 16, kFmtDfp, 5, 0,
438 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700439 "vadd", "!0S, !1S, !2S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700440 ENCODING_MAP(kThumb2Vdivs, 0xee800a00,
441 kFmtSfp, 22, 12, kFmtSfp, 7, 16, kFmtSfp, 5, 0,
442 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700443 "vdivs", "!0s, !1s, !2s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700444 ENCODING_MAP(kThumb2Vdivd, 0xee800b00,
445 kFmtDfp, 22, 12, kFmtDfp, 7, 16, kFmtDfp, 5, 0,
446 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700447 "vdivd", "!0S, !1S, !2S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700448 ENCODING_MAP(kThumb2VcvtIF, 0xeeb80ac0,
449 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
450 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700451 "vcvt.f32", "!0s, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700452 ENCODING_MAP(kThumb2VcvtID, 0xeeb80bc0,
453 kFmtDfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
454 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700455 "vcvt.f64", "!0S, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700456 ENCODING_MAP(kThumb2VcvtFI, 0xeebd0ac0,
457 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
458 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700459 "vcvt.s32.f32 ", "!0s, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700460 ENCODING_MAP(kThumb2VcvtDI, 0xeebd0bc0,
461 kFmtSfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
462 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700463 "vcvt.s32.f64 ", "!0s, !1S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700464 ENCODING_MAP(kThumb2VcvtFd, 0xeeb70ac0,
465 kFmtDfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
466 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700467 "vcvt.f64.f32 ", "!0S, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700468 ENCODING_MAP(kThumb2VcvtDF, 0xeeb70bc0,
469 kFmtSfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
470 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700471 "vcvt.f32.f64 ", "!0s, !1S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700472 ENCODING_MAP(kThumb2Vsqrts, 0xeeb10ac0,
473 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
474 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700475 "vsqrt.f32 ", "!0s, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700476 ENCODING_MAP(kThumb2Vsqrtd, 0xeeb10bc0,
477 kFmtDfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
478 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee9727c3d2009-08-01 11:32:36 -0700479 "vsqrt.f64 ", "!0S, !1S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700480 ENCODING_MAP(kThumb2MovImmShift, 0xf04f0000, /* no setflags encoding */
481 kFmtBitBlt, 11, 8, kFmtModImm, -1, -1, kFmtUnused, -1, -1,
482 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700483 "mov", "r!0d, #!1m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700484 ENCODING_MAP(kThumb2MovImm16, 0xf2400000,
485 kFmtBitBlt, 11, 8, kFmtImm16, -1, -1, kFmtUnused, -1, -1,
486 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700487 "mov", "r!0d, #!1M", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700488 ENCODING_MAP(kThumb2StrRRI12, 0xf8c00000,
489 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800490 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700491 "str", "r!0d, [r!1d, #!2d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700492 ENCODING_MAP(kThumb2LdrRRI12, 0xf8d00000,
493 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800494 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700495 "ldr", "r!0d, [r!1d, #!2d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700496 ENCODING_MAP(kThumb2StrRRI8Predec, 0xf8400c00,
497 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 8, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800498 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700499 "str", "r!0d, [r!1d, #-!2d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700500 ENCODING_MAP(kThumb2LdrRRI8Predec, 0xf8500c00,
501 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 8, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800502 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700503 "ldr", "r!0d, [r!1d, #-!2d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700504 ENCODING_MAP(kThumb2Cbnz, 0xb900, /* Note: does not affect flags */
505 kFmtBitBlt, 2, 0, kFmtImm6, -1, -1, kFmtUnused, -1, -1,
506 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE0 | IS_BRANCH,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700507 "cbnz", "r!0d,!1t", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700508 ENCODING_MAP(kThumb2Cbz, 0xb100, /* Note: does not affect flags */
509 kFmtBitBlt, 2, 0, kFmtImm6, -1, -1, kFmtUnused, -1, -1,
510 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE0 | IS_BRANCH,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700511 "cbz", "r!0d,!1t", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700512 ENCODING_MAP(kThumb2AddRRI12, 0xf2000000,
513 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtImm12, -1, -1,
514 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700515 IS_TERTIARY_OP | REG_DEF0_USE1,/* Note: doesn't affect flags */
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700516 "add", "r!0d,r!1d,#!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700517 ENCODING_MAP(kThumb2MovRR, 0xea4f0000, /* no setflags encoding */
518 kFmtBitBlt, 11, 8, kFmtBitBlt, 3, 0, kFmtUnused, -1, -1,
519 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700520 "mov", "r!0d, r!1d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700521 ENCODING_MAP(kThumb2Vmovs, 0xeeb00a40,
522 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
523 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700524 "vmov.f32 ", " !0s, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700525 ENCODING_MAP(kThumb2Vmovd, 0xeeb00b40,
526 kFmtDfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
527 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700528 "vmov.f64 ", " !0S, !1S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700529 ENCODING_MAP(kThumb2Ldmia, 0xe8900000,
530 kFmtBitBlt, 19, 16, kFmtBitBlt, 15, 0, kFmtUnused, -1, -1,
531 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800532 IS_BINARY_OP | REG_DEF0_USE0 | REG_DEF_LIST1 | IS_LOAD,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700533 "ldmia", "r!0d!!, <!1R>", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700534 ENCODING_MAP(kThumb2Stmia, 0xe8800000,
535 kFmtBitBlt, 19, 16, kFmtBitBlt, 15, 0, kFmtUnused, -1, -1,
536 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800537 IS_BINARY_OP | REG_DEF0_USE0 | REG_USE_LIST1 | IS_STORE,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700538 "stmia", "r!0d!!, <!1R>", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700539 ENCODING_MAP(kThumb2AddRRR, 0xeb100000, /* setflags encoding */
540 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
541 kFmtShift, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700542 IS_QUAD_OP | REG_DEF0_USE12 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700543 "adds", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700544 ENCODING_MAP(kThumb2SubRRR, 0xebb00000, /* setflags enconding */
545 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
546 kFmtShift, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700547 IS_QUAD_OP | REG_DEF0_USE12 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700548 "subs", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700549 ENCODING_MAP(kThumb2SbcRRR, 0xeb700000, /* setflags encoding */
550 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
551 kFmtShift, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700552 IS_QUAD_OP | REG_DEF0_USE12 | USES_CCODES | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700553 "sbcs", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700554 ENCODING_MAP(kThumb2CmpRR, 0xebb00f00,
555 kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0, kFmtShift, -1, -1,
556 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700557 IS_TERTIARY_OP | REG_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700558 "cmp", "r!0d, r!1d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700559 ENCODING_MAP(kThumb2SubRRI12, 0xf2a00000,
560 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtImm12, -1, -1,
561 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700562 IS_TERTIARY_OP | REG_DEF0_USE1,/* Note: doesn't affect flags */
Bill Buzbee270c1d62009-08-13 16:58:07 -0700563 "sub", "r!0d,r!1d,#!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700564 ENCODING_MAP(kThumb2MvnImmShift, 0xf06f0000, /* no setflags encoding */
565 kFmtBitBlt, 11, 8, kFmtModImm, -1, -1, kFmtUnused, -1, -1,
566 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700567 "mvn", "r!0d, #!1n", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700568 ENCODING_MAP(kThumb2Sel, 0xfaa0f080,
569 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
570 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700571 IS_TERTIARY_OP | REG_DEF0_USE12 | USES_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700572 "sel", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700573 ENCODING_MAP(kThumb2Ubfx, 0xf3c00000,
574 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtLsb, -1, -1,
575 kFmtBWidth, 4, 0, IS_QUAD_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700576 "ubfx", "r!0d, r!1d, #!2d, #!3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700577 ENCODING_MAP(kThumb2Sbfx, 0xf3400000,
578 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtLsb, -1, -1,
579 kFmtBWidth, 4, 0, IS_QUAD_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700580 "sbfx", "r!0d, r!1d, #!2d, #!3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700581 ENCODING_MAP(kThumb2LdrRRR, 0xf8500000,
582 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800583 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_DEF0_USE12 | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700584 "ldr", "r!0d, [r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700585 ENCODING_MAP(kThumb2LdrhRRR, 0xf8300000,
586 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800587 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_DEF0_USE12 | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700588 "ldrh", "r!0d, [r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700589 ENCODING_MAP(kThumb2LdrshRRR, 0xf9300000,
590 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800591 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_DEF0_USE12 | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700592 "ldrsh", "r!0d, [r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700593 ENCODING_MAP(kThumb2LdrbRRR, 0xf8100000,
594 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800595 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_DEF0_USE12 | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700596 "ldrb", "r!0d, [r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700597 ENCODING_MAP(kThumb2LdrsbRRR, 0xf9100000,
598 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800599 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_DEF0_USE12 | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700600 "ldrsb", "r!0d, [r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700601 ENCODING_MAP(kThumb2StrRRR, 0xf8400000,
602 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800603 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_USE012 | IS_STORE,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700604 "str", "r!0d, [r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700605 ENCODING_MAP(kThumb2StrhRRR, 0xf8200000,
606 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800607 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_USE012 | IS_STORE,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700608 "strh", "r!0d, [r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700609 ENCODING_MAP(kThumb2StrbRRR, 0xf8000000,
610 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800611 kFmtBitBlt, 5, 4, IS_QUAD_OP | REG_USE012 | IS_STORE,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700612 "strb", "r!0d, [r!1d, r!2d, LSL #!3d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700613 ENCODING_MAP(kThumb2LdrhRRI12, 0xf8b00000,
614 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800615 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700616 "ldrh", "r!0d, [r!1d, #!2d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700617 ENCODING_MAP(kThumb2LdrshRRI12, 0xf9b00000,
618 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800619 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700620 "ldrsh", "r!0d, [r!1d, #!2d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700621 ENCODING_MAP(kThumb2LdrbRRI12, 0xf8900000,
622 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800623 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700624 "ldrb", "r!0d, [r!1d, #!2d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700625 ENCODING_MAP(kThumb2LdrsbRRI12, 0xf9900000,
626 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800627 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700628 "ldrsb", "r!0d, [r!1d, #!2d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700629 ENCODING_MAP(kThumb2StrhRRI12, 0xf8a00000,
630 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800631 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700632 "strh", "r!0d, [r!1d, #!2d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700633 ENCODING_MAP(kThumb2StrbRRI12, 0xf8800000,
634 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 11, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800635 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_USE01 | IS_STORE,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700636 "strb", "r!0d, [r!1d, #!2d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700637 ENCODING_MAP(kThumb2Pop, 0xe8bd0000,
638 kFmtBitBlt, 15, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
639 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800640 IS_UNARY_OP | REG_DEF_SP | REG_USE_SP | REG_DEF_LIST0
641 | IS_LOAD, "pop", "<!0R>", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700642 ENCODING_MAP(kThumb2Push, 0xe8ad0000,
643 kFmtBitBlt, 15, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
644 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800645 IS_UNARY_OP | REG_DEF_SP | REG_USE_SP | REG_USE_LIST0
646 | IS_STORE, "push", "<!0R>", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700647 ENCODING_MAP(kThumb2CmpRI8, 0xf1b00f00,
648 kFmtBitBlt, 19, 16, kFmtModImm, -1, -1, kFmtUnused, -1, -1,
649 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700650 IS_BINARY_OP | REG_USE0 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700651 "cmp", "r!0d, #!1m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700652 ENCODING_MAP(kThumb2AdcRRR, 0xeb500000, /* setflags encoding */
653 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
654 kFmtShift, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700655 IS_QUAD_OP | REG_DEF0_USE12 | SETS_CCODES,
Elliott Hughesee34f592010-04-05 18:13:52 -0700656 "adcs", "r!0d, r!1d, r!2d, shift !3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700657 ENCODING_MAP(kThumb2AndRRR, 0xea000000,
658 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
659 kFmtShift, -1, -1, IS_QUAD_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700660 "and", "r!0d, r!1d, r!2d, shift !3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700661 ENCODING_MAP(kThumb2BicRRR, 0xea200000,
662 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
663 kFmtShift, -1, -1, IS_QUAD_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700664 "bic", "r!0d, r!1d, r!2d, shift !3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700665 ENCODING_MAP(kThumb2CmnRR, 0xeb000000,
666 kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0, kFmtShift, -1, -1,
667 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700668 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700669 "cmn", "r!0d, r!1d, shift !2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700670 ENCODING_MAP(kThumb2EorRRR, 0xea800000,
671 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
672 kFmtShift, -1, -1, IS_QUAD_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700673 "eor", "r!0d, r!1d, r!2d, shift !3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700674 ENCODING_MAP(kThumb2MulRRR, 0xfb00f000,
675 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
676 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700677 "mul", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700678 ENCODING_MAP(kThumb2MnvRR, 0xea6f0000,
679 kFmtBitBlt, 11, 8, kFmtBitBlt, 3, 0, kFmtShift, -1, -1,
680 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700681 "mvn", "r!0d, r!1d, shift !2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700682 ENCODING_MAP(kThumb2RsubRRI8, 0xf1d00000,
683 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
684 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700685 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700686 "rsb", "r!0d,r!1d,#!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700687 ENCODING_MAP(kThumb2NegRR, 0xf1d00000, /* instance of rsub */
688 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtUnused, -1, -1,
689 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700690 IS_BINARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700691 "neg", "r!0d,r!1d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700692 ENCODING_MAP(kThumb2OrrRRR, 0xea400000,
693 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
694 kFmtShift, -1, -1, IS_QUAD_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700695 "orr", "r!0d, r!1d, r!2d, shift !3d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700696 ENCODING_MAP(kThumb2TstRR, 0xea100f00,
697 kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0, kFmtShift, -1, -1,
698 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700699 IS_TERTIARY_OP | REG_USE01 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700700 "tst", "r!0d, r!1d, shift !2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700701 ENCODING_MAP(kThumb2LslRRR, 0xfa00f000,
702 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
703 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700704 "lsl", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700705 ENCODING_MAP(kThumb2LsrRRR, 0xfa20f000,
706 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
707 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700708 "lsr", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700709 ENCODING_MAP(kThumb2AsrRRR, 0xfa40f000,
710 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
711 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700712 "asr", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700713 ENCODING_MAP(kThumb2RorRRR, 0xfa60f000,
714 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
715 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700716 "ror", "r!0d, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700717 ENCODING_MAP(kThumb2LslRRI5, 0xea4f0000,
718 kFmtBitBlt, 11, 8, kFmtBitBlt, 3, 0, kFmtShift5, -1, -1,
719 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700720 "lsl", "r!0d, r!1d, #!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700721 ENCODING_MAP(kThumb2LsrRRI5, 0xea4f0010,
722 kFmtBitBlt, 11, 8, kFmtBitBlt, 3, 0, kFmtShift5, -1, -1,
723 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700724 "lsr", "r!0d, r!1d, #!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700725 ENCODING_MAP(kThumb2AsrRRI5, 0xea4f0020,
726 kFmtBitBlt, 11, 8, kFmtBitBlt, 3, 0, kFmtShift5, -1, -1,
727 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700728 "asr", "r!0d, r!1d, #!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700729 ENCODING_MAP(kThumb2RorRRI5, 0xea4f0030,
730 kFmtBitBlt, 11, 8, kFmtBitBlt, 3, 0, kFmtShift5, -1, -1,
731 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700732 "ror", "r!0d, r!1d, #!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700733 ENCODING_MAP(kThumb2BicRRI8, 0xf0200000,
734 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
735 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700736 "bic", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700737 ENCODING_MAP(kThumb2AndRRI8, 0xf0000000,
738 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
739 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700740 "and", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700741 ENCODING_MAP(kThumb2OrrRRI8, 0xf0400000,
742 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
743 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700744 "orr", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700745 ENCODING_MAP(kThumb2EorRRI8, 0xf0800000,
746 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
747 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700748 "eor", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700749 ENCODING_MAP(kThumb2AddRRI8, 0xf1100000,
750 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
751 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700752 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700753 "adds", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700754 ENCODING_MAP(kThumb2AdcRRI8, 0xf1500000,
755 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
756 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700757 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES | USES_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700758 "adcs", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700759 ENCODING_MAP(kThumb2SubRRI8, 0xf1b00000,
760 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
761 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700762 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700763 "subs", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700764 ENCODING_MAP(kThumb2SbcRRI8, 0xf1700000,
765 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtModImm, -1, -1,
766 kFmtUnused, -1, -1,
Ben Chengdcf3e5d2009-09-11 13:42:05 -0700767 IS_TERTIARY_OP | REG_DEF0_USE1 | SETS_CCODES | USES_CCODES,
Bill Buzbee270c1d62009-08-13 16:58:07 -0700768 "sbcs", "r!0d, r!1d, #!2m", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700769 ENCODING_MAP(kThumb2It, 0xbf00,
770 kFmtBitBlt, 7, 4, kFmtBitBlt, 3, 0, kFmtModImm, -1, -1,
771 kFmtUnused, -1, -1, IS_BINARY_OP | IS_IT | USES_CCODES,
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700772 "it:!1b", "!0c", 1),
Bill Buzbee1465db52009-09-23 17:17:35 -0700773 ENCODING_MAP(kThumb2Fmstat, 0xeef1fa10,
774 kFmtUnused, -1, -1, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
775 kFmtUnused, -1, -1, NO_OPERAND | SETS_CCODES,
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700776 "fmstat", "", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700777 ENCODING_MAP(kThumb2Vcmpd, 0xeeb40b40,
778 kFmtDfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
779 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700780 "vcmp.f64", "!0S, !1S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700781 ENCODING_MAP(kThumb2Vcmps, 0xeeb40a40,
782 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
783 kFmtUnused, -1, -1, IS_BINARY_OP | REG_USE01,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700784 "vcmp.f32", "!0s, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700785 ENCODING_MAP(kThumb2LdrPcRel12, 0xf8df0000,
786 kFmtBitBlt, 15, 12, kFmtBitBlt, 11, 0, kFmtUnused, -1, -1,
787 kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800788 IS_TERTIARY_OP | REG_DEF0 | REG_USE_PC | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700789 "ldr", "r!0d, [rpc, #!1d]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700790 ENCODING_MAP(kThumb2BCond, 0xf0008000,
791 kFmtBrOffset, -1, -1, kFmtBitBlt, 25, 22, kFmtUnused, -1, -1,
792 kFmtUnused, -1, -1,
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700793 IS_BINARY_OP | IS_BRANCH | USES_CCODES,
794 "b!1c", "!0t", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700795 ENCODING_MAP(kThumb2Vmovd_RR, 0xeeb00b40,
796 kFmtDfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
797 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700798 "vmov.f64", "!0S, !1S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700799 ENCODING_MAP(kThumb2Vmovs_RR, 0xeeb00a40,
800 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
801 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
802 "vmov.f32", "!0s, !1s", 2),
803 ENCODING_MAP(kThumb2Fmrs, 0xee100a10,
804 kFmtBitBlt, 15, 12, kFmtSfp, 7, 16, kFmtUnused, -1, -1,
805 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700806 "fmrs", "r!0d, !1s", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700807 ENCODING_MAP(kThumb2Fmsr, 0xee000a10,
808 kFmtSfp, 7, 16, kFmtBitBlt, 15, 12, kFmtUnused, -1, -1,
809 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700810 "fmsr", "!0s, r!1d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700811 ENCODING_MAP(kThumb2Fmrrd, 0xec500b10,
812 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtDfp, 5, 0,
813 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF01_USE2,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700814 "fmrrd", "r!0d, r!1d, !2S", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700815 ENCODING_MAP(kThumb2Fmdrr, 0xec400b10,
816 kFmtDfp, 5, 0, kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16,
817 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE12,
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700818 "fmdrr", "!0S, r!1d, r!2d", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700819 ENCODING_MAP(kThumb2Vabsd, 0xeeb00bc0,
820 kFmtDfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
821 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
822 "vabs.f64", "!0S, !1S", 2),
823 ENCODING_MAP(kThumb2Vabss, 0xeeb00ac0,
824 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
825 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
826 "vabs.f32", "!0s, !1s", 2),
827 ENCODING_MAP(kThumb2Vnegd, 0xeeb10b40,
828 kFmtDfp, 22, 12, kFmtDfp, 5, 0, kFmtUnused, -1, -1,
829 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
830 "vneg.f64", "!0S, !1S", 2),
831 ENCODING_MAP(kThumb2Vnegs, 0xeeb10a40,
832 kFmtSfp, 22, 12, kFmtSfp, 5, 0, kFmtUnused, -1, -1,
833 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0_USE1,
834 "vneg.f32", "!0s, !1s", 2),
835 ENCODING_MAP(kThumb2Vmovs_IMM8, 0xeeb00a00,
836 kFmtSfp, 22, 12, kFmtFPImm, 16, 0, kFmtUnused, -1, -1,
837 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0,
838 "vmov.f32", "!0s, #0x!1h", 2),
839 ENCODING_MAP(kThumb2Vmovd_IMM8, 0xeeb00b00,
840 kFmtDfp, 22, 12, kFmtFPImm, 16, 0, kFmtUnused, -1, -1,
841 kFmtUnused, -1, -1, IS_BINARY_OP | REG_DEF0,
842 "vmov.f64", "!0S, #0x!1h", 2),
843 ENCODING_MAP(kThumb2Mla, 0xfb000000,
844 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtBitBlt, 3, 0,
845 kFmtBitBlt, 15, 12,
846 IS_QUAD_OP | REG_DEF0 | REG_USE1 | REG_USE2 | REG_USE3,
847 "mla", "r!0d, r!1d, r!2d, r!3d", 2),
848 ENCODING_MAP(kThumb2Umull, 0xfba00000,
849 kFmtBitBlt, 15, 12, kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16,
850 kFmtBitBlt, 3, 0,
851 IS_QUAD_OP | REG_DEF0 | REG_DEF1 | REG_USE2 | REG_USE3,
852 "umull", "r!0d, r!1d, r!2d, r!3d", 2),
853 ENCODING_MAP(kThumb2Ldrex, 0xe8500f00,
854 kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16, kFmtBitBlt, 7, 0,
Bill Buzbee1f748632010-03-02 16:14:41 -0800855 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0_USE1 | IS_LOAD,
Elliott Hughesd1660a52010-06-29 16:56:52 -0700856 "ldrex", "r!0d, [r!1d, #!2E]", 2),
Bill Buzbee1465db52009-09-23 17:17:35 -0700857 ENCODING_MAP(kThumb2Strex, 0xe8400000,
858 kFmtBitBlt, 11, 8, kFmtBitBlt, 15, 12, kFmtBitBlt, 19, 16,
Bill Buzbee1f748632010-03-02 16:14:41 -0800859 kFmtBitBlt, 7, 0, IS_QUAD_OP | REG_DEF0_USE12 | IS_STORE,
Bill Buzbee1465db52009-09-23 17:17:35 -0700860 "strex", "r!0d,r!1d, [r!2d, #!2E]", 2),
861 ENCODING_MAP(kThumb2Clrex, 0xf3bf8f2f,
862 kFmtUnused, -1, -1, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
Bill Buzbee1f748632010-03-02 16:14:41 -0800863 kFmtUnused, -1, -1, NO_OPERAND,
864 "clrex", "", 2),
Bill Buzbeed0937ef2009-12-22 16:15:39 -0800865 ENCODING_MAP(kThumb2Bfi, 0xf3600000,
866 kFmtBitBlt, 11, 8, kFmtBitBlt, 19, 16, kFmtShift5, -1, -1,
867 kFmtBitBlt, 4, 0, IS_QUAD_OP | REG_DEF0_USE1,
868 "bfi", "r!0d,r!1d,#!2d,#!3d", 2),
869 ENCODING_MAP(kThumb2Bfc, 0xf36f0000,
870 kFmtBitBlt, 11, 8, kFmtShift5, -1, -1, kFmtBitBlt, 4, 0,
871 kFmtUnused, -1, -1, IS_TERTIARY_OP | REG_DEF0,
872 "bfc", "r!0d,#!1d,#!2d", 2),
buzbeeecf8f6e2010-07-20 14:53:42 -0700873 ENCODING_MAP(kThumb2Dmb, 0xf3bf8f50,
874 kFmtBitBlt, 3, 0, kFmtUnused, -1, -1, kFmtUnused, -1, -1,
875 kFmtUnused, -1, -1, IS_UNARY_OP,
876 "dmb","#!0B",2),
Ben Chengba4fc8b2009-06-01 13:00:29 -0700877};
878
Ben Cheng6d576092009-09-01 17:01:58 -0700879/*
880 * The fake NOP of moving r0 to r0 actually will incur data stalls if r0 is
881 * not ready. Since r5 (rFP) is not updated often, it is less likely to
882 * generate unnecessary stall cycles.
883 */
884#define PADDING_MOV_R5_R5 0x1C2D
Ben Chengba4fc8b2009-06-01 13:00:29 -0700885
Ben Cheng978738d2010-05-13 13:45:57 -0700886/* Track the number of times that the code cache is patched */
887#if defined(WITH_JIT_TUNING)
888#define UPDATE_CODE_CACHE_PATCHES() (gDvmJit.codeCachePatches++)
889#else
890#define UPDATE_CODE_CACHE_PATCHES()
891#endif
892
Ben Chengba4fc8b2009-06-01 13:00:29 -0700893/* Write the numbers in the literal pool to the codegen stream */
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700894static void installDataContent(CompilationUnit *cUnit)
Ben Chengba4fc8b2009-06-01 13:00:29 -0700895{
Ben Chenge80cd942009-07-17 15:54:23 -0700896 int *dataPtr = (int *) ((char *) cUnit->baseAddr + cUnit->dataOffset);
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700897 ArmLIR *dataLIR = (ArmLIR *) cUnit->wordList;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700898 while (dataLIR) {
899 *dataPtr++ = dataLIR->operands[0];
900 dataLIR = NEXT_LIR(dataLIR);
901 }
902}
903
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700904/* Returns the size of a Jit trace description */
905static int jitTraceDescriptionSize(const JitTraceDescription *desc)
906{
907 int runCount;
Ben Cheng7a2697d2010-06-07 13:44:23 -0700908 /* Trace end is always of non-meta type (ie isCode == true) */
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700909 for (runCount = 0; ; runCount++) {
Ben Cheng7a2697d2010-06-07 13:44:23 -0700910 if (desc->trace[runCount].frag.isCode &&
911 desc->trace[runCount].frag.runEnd)
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700912 break;
913 }
Ben Cheng7a2697d2010-06-07 13:44:23 -0700914 return sizeof(JitTraceDescription) + ((runCount+1) * sizeof(JitTraceRun));
Bill Buzbee46cd5b62009-06-05 15:36:06 -0700915}
916
Ben Chengba4fc8b2009-06-01 13:00:29 -0700917/* Return TRUE if error happens */
918static bool assembleInstructions(CompilationUnit *cUnit, intptr_t startAddr)
919{
920 short *bufferAddr = (short *) cUnit->codeBuffer;
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700921 ArmLIR *lir;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700922
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700923 for (lir = (ArmLIR *) cUnit->firstLIRInsn; lir; lir = NEXT_LIR(lir)) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700924 if (lir->opCode < 0) {
Bill Buzbee1465db52009-09-23 17:17:35 -0700925 if ((lir->opCode == kArmPseudoPseudoAlign4) &&
Ben Cheng1efc9c52009-06-08 18:25:27 -0700926 /* 1 means padding is needed */
927 (lir->operands[0] == 1)) {
Ben Cheng6d576092009-09-01 17:01:58 -0700928 *bufferAddr++ = PADDING_MOV_R5_R5;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700929 }
930 continue;
931 }
932
Ben Chenge9695e52009-06-16 16:11:47 -0700933 if (lir->isNop) {
934 continue;
935 }
936
Bill Buzbee1465db52009-09-23 17:17:35 -0700937 if (lir->opCode == kThumbLdrPcRel ||
938 lir->opCode == kThumb2LdrPcRel12 ||
939 lir->opCode == kThumbAddPcRel ||
940 ((lir->opCode == kThumb2Vldrs) && (lir->operands[1] == rpc))) {
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700941 ArmLIR *lirTarget = (ArmLIR *) lir->generic.target;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700942 intptr_t pc = (lir->generic.offset + 4) & ~3;
Ben Cheng38329f52009-07-07 14:19:20 -0700943 /*
944 * Allow an offset (stored in operands[2] to be added to the
945 * PC-relative target. Useful to get to a fixed field inside a
946 * chaining cell.
947 */
948 intptr_t target = lirTarget->generic.offset + lir->operands[2];
Ben Chengba4fc8b2009-06-01 13:00:29 -0700949 int delta = target - pc;
950 if (delta & 0x3) {
951 LOGE("PC-rel distance is not multiples of 4: %d\n", delta);
Bill Buzbeefc519dc2010-03-06 23:30:57 -0800952 dvmCompilerAbort(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700953 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700954 if ((lir->opCode == kThumb2LdrPcRel12) && (delta > 4091)) {
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700955 return true;
956 } else if (delta > 1020) {
Ben Cheng1efc9c52009-06-08 18:25:27 -0700957 return true;
958 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700959 if (lir->opCode == kThumb2Vldrs) {
960 lir->operands[2] = delta >> 2;
961 } else {
962 lir->operands[1] = (lir->opCode == kThumb2LdrPcRel12) ?
963 delta : delta >> 2;
964 }
965 } else if (lir->opCode == kThumb2Cbnz || lir->opCode == kThumb2Cbz) {
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700966 ArmLIR *targetLIR = (ArmLIR *) lir->generic.target;
967 intptr_t pc = lir->generic.offset + 4;
968 intptr_t target = targetLIR->generic.offset;
969 int delta = target - pc;
970 if (delta > 126 || delta < 0) {
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700971 /*
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700972 * TODO: allow multiple kinds of assembler failure to allow
973 * change of code patterns when things don't fit.
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700974 */
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700975 return true;
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700976 } else {
977 lir->operands[1] = delta >> 1;
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700978 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700979 } else if (lir->opCode == kThumbBCond ||
980 lir->opCode == kThumb2BCond) {
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700981 ArmLIR *targetLIR = (ArmLIR *) lir->generic.target;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700982 intptr_t pc = lir->generic.offset + 4;
983 intptr_t target = targetLIR->generic.offset;
984 int delta = target - pc;
Bill Buzbee1465db52009-09-23 17:17:35 -0700985 if ((lir->opCode == kThumbBCond) && (delta > 254 || delta < -256)) {
Ben Cheng1efc9c52009-06-08 18:25:27 -0700986 return true;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700987 }
988 lir->operands[0] = delta >> 1;
Bill Buzbee1465db52009-09-23 17:17:35 -0700989 } else if (lir->opCode == kThumbBUncond) {
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700990 ArmLIR *targetLIR = (ArmLIR *) lir->generic.target;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700991 intptr_t pc = lir->generic.offset + 4;
992 intptr_t target = targetLIR->generic.offset;
993 int delta = target - pc;
994 if (delta > 2046 || delta < -2048) {
995 LOGE("Unconditional branch distance out of range: %d\n", delta);
Bill Buzbeefc519dc2010-03-06 23:30:57 -0800996 dvmCompilerAbort(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700997 }
998 lir->operands[0] = delta >> 1;
Bill Buzbee1465db52009-09-23 17:17:35 -0700999 } else if (lir->opCode == kThumbBlx1) {
1000 assert(NEXT_LIR(lir)->opCode == kThumbBlx2);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001001 /* curPC is Thumb */
1002 intptr_t curPC = (startAddr + lir->generic.offset + 4) & ~3;
1003 intptr_t target = lir->operands[1];
1004
1005 /* Match bit[1] in target with base */
1006 if (curPC & 0x2) {
1007 target |= 0x2;
1008 }
1009 int delta = target - curPC;
1010 assert((delta >= -(1<<22)) && (delta <= ((1<<22)-2)));
1011
1012 lir->operands[0] = (delta >> 12) & 0x7ff;
1013 NEXT_LIR(lir)->operands[0] = (delta>> 1) & 0x7ff;
1014 }
1015
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001016 ArmEncodingMap *encoder = &EncodingMap[lir->opCode];
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001017 u4 bits = encoder->skeleton;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001018 int i;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001019 for (i = 0; i < 4; i++) {
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001020 u4 operand;
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001021 u4 value;
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001022 operand = lir->operands[i];
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001023 switch(encoder->fieldLoc[i].kind) {
Bill Buzbee1465db52009-09-23 17:17:35 -07001024 case kFmtUnused:
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001025 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001026 case kFmtFPImm:
1027 value = ((operand & 0xF0) >> 4) << encoder->fieldLoc[i].end;
1028 value |= (operand & 0x0F) << encoder->fieldLoc[i].start;
1029 bits |= value;
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001030 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001031 case kFmtBrOffset:
1032 /*
1033 * NOTE: branch offsets are not handled here, but
1034 * in the main assembly loop (where label values
1035 * are known). For reference, here is what the
1036 * encoder handing would be:
1037 value = ((operand & 0x80000) >> 19) << 26;
1038 value |= ((operand & 0x40000) >> 18) << 11;
1039 value |= ((operand & 0x20000) >> 17) << 13;
1040 value |= ((operand & 0x1f800) >> 11) << 16;
1041 value |= (operand & 0x007ff);
1042 bits |= value;
1043 */
1044 break;
1045 case kFmtShift5:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001046 value = ((operand & 0x1c) >> 2) << 12;
1047 value |= (operand & 0x03) << 6;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001048 bits |= value;
1049 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001050 case kFmtShift:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001051 value = ((operand & 0x70) >> 4) << 12;
1052 value |= (operand & 0x0f) << 4;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001053 bits |= value;
1054 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001055 case kFmtBWidth:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001056 value = operand - 1;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001057 bits |= value;
1058 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001059 case kFmtLsb:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001060 value = ((operand & 0x1c) >> 2) << 12;
1061 value |= (operand & 0x03) << 6;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001062 bits |= value;
1063 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001064 case kFmtImm6:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001065 value = ((operand & 0x20) >> 5) << 9;
1066 value |= (operand & 0x1f) << 3;
Bill Buzbee7ea0f642009-08-10 17:06:51 -07001067 bits |= value;
1068 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001069 case kFmtBitBlt:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001070 value = (operand << encoder->fieldLoc[i].start) &
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001071 ((1 << (encoder->fieldLoc[i].end + 1)) - 1);
1072 bits |= value;
1073 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001074 case kFmtDfp: {
1075 assert(DOUBLEREG(operand));
1076 assert((operand & 0x1) == 0);
Ben Cheng30f1f462009-10-12 13:46:55 -07001077 int regName = (operand & FP_REG_MASK) >> 1;
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001078 /* Snag the 1-bit slice and position it */
Ben Cheng30f1f462009-10-12 13:46:55 -07001079 value = ((regName & 0x10) >> 4) <<
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001080 encoder->fieldLoc[i].end;
1081 /* Extract and position the 4-bit slice */
Ben Cheng30f1f462009-10-12 13:46:55 -07001082 value |= (regName & 0x0f) <<
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001083 encoder->fieldLoc[i].start;
1084 bits |= value;
1085 break;
Ben Cheng30f1f462009-10-12 13:46:55 -07001086 }
Bill Buzbee1465db52009-09-23 17:17:35 -07001087 case kFmtSfp:
1088 assert(SINGLEREG(operand));
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001089 /* Snag the 1-bit slice and position it */
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001090 value = (operand & 0x1) <<
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001091 encoder->fieldLoc[i].end;
1092 /* Extract and position the 4-bit slice */
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001093 value |= ((operand & 0x1e) >> 1) <<
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001094 encoder->fieldLoc[i].start;
1095 bits |= value;
1096 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001097 case kFmtImm12:
1098 case kFmtModImm:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001099 value = ((operand & 0x800) >> 11) << 26;
1100 value |= ((operand & 0x700) >> 8) << 12;
1101 value |= operand & 0x0ff;
Bill Buzbee7ea0f642009-08-10 17:06:51 -07001102 bits |= value;
1103 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001104 case kFmtImm16:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001105 value = ((operand & 0x0800) >> 11) << 26;
1106 value |= ((operand & 0xf000) >> 12) << 16;
1107 value |= ((operand & 0x0700) >> 8) << 12;
1108 value |= operand & 0x0ff;
Bill Buzbee7ea0f642009-08-10 17:06:51 -07001109 bits |= value;
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001110 break;
1111 default:
1112 assert(0);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001113 }
1114 }
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001115 if (encoder->size == 2) {
1116 *bufferAddr++ = (bits >> 16) & 0xffff;
1117 }
1118 *bufferAddr++ = bits & 0xffff;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001119 }
Ben Cheng1efc9c52009-06-08 18:25:27 -07001120 return false;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001121}
1122
Ben Cheng9fa39c92010-03-16 16:20:48 -07001123#if defined(SIGNATURE_BREAKPOINT)
Ben Chengdca71432010-03-16 16:04:11 -07001124/* Inspect the assembled instruction stream to find potential matches */
1125static void matchSignatureBreakpoint(const CompilationUnit *cUnit,
1126 unsigned int size)
1127{
1128 unsigned int i, j;
1129 u4 *ptr = (u4 *) cUnit->codeBuffer;
1130
1131 for (i = 0; i < size - gDvmJit.signatureBreakpointSize + 1; i++) {
1132 if (ptr[i] == gDvmJit.signatureBreakpoint[0]) {
1133 for (j = 1; j < gDvmJit.signatureBreakpointSize; j++) {
1134 if (ptr[i+j] != gDvmJit.signatureBreakpoint[j]) {
1135 break;
1136 }
1137 }
1138 if (j == gDvmJit.signatureBreakpointSize) {
1139 LOGD("Signature match starting from offset %#x (%d words)",
1140 i*4, gDvmJit.signatureBreakpointSize);
1141 int descSize = jitTraceDescriptionSize(cUnit->traceDesc);
1142 JitTraceDescription *newCopy =
1143 (JitTraceDescription *) malloc(descSize);
1144 memcpy(newCopy, cUnit->traceDesc, descSize);
1145 dvmCompilerWorkEnqueue(NULL, kWorkOrderTraceDebug, newCopy);
1146 break;
1147 }
1148 }
1149 }
1150}
Ben Cheng9fa39c92010-03-16 16:20:48 -07001151#endif
Ben Chengdca71432010-03-16 16:04:11 -07001152
Ben Chengba4fc8b2009-06-01 13:00:29 -07001153/*
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001154 * Translation layout in the code cache. Note that the codeAddress pointer
1155 * in JitTable will point directly to the code body (field codeAddress). The
1156 * chain cell offset codeAddress - 2, and (if present) executionCount is at
1157 * codeAddress - 6.
1158 *
1159 * +----------------------------+
1160 * | Execution count | -> [Optional] 4 bytes
1161 * +----------------------------+
1162 * +--| Offset to chain cell counts| -> 2 bytes
1163 * | +----------------------------+
1164 * | | Code body | -> Start address for translation
1165 * | | | variable in 2-byte chunks
1166 * | . . (JitTable's codeAddress points here)
1167 * | . .
1168 * | | |
1169 * | +----------------------------+
Bill Buzbeebd047242010-05-13 13:02:53 -07001170 * | | Chaining Cells | -> 12/16 bytes each, must be 4 byte aligned
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001171 * | . .
1172 * | . .
1173 * | | |
1174 * | +----------------------------+
Ben Chengcec26f62010-01-15 15:29:33 -08001175 * | | Gap for large switch stmt | -> # cases >= MAX_CHAINED_SWITCH_CASES
1176 * | +----------------------------+
1177 * +->| Chaining cell counts | -> 8 bytes, chain cell counts by type
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001178 * +----------------------------+
1179 * | Trace description | -> variable sized
1180 * . .
1181 * | |
1182 * +----------------------------+
1183 * | Literal pool | -> 4-byte aligned, variable size
1184 * . .
1185 * . .
1186 * | |
1187 * +----------------------------+
1188 *
Ben Chengba4fc8b2009-06-01 13:00:29 -07001189 * Go over each instruction in the list and calculate the offset from the top
1190 * before sending them off to the assembler. If out-of-range branch distance is
1191 * seen rearrange the instructions a bit to correct it.
1192 */
Bill Buzbee716f1202009-07-23 13:22:09 -07001193void dvmCompilerAssembleLIR(CompilationUnit *cUnit, JitTranslationInfo *info)
Ben Chengba4fc8b2009-06-01 13:00:29 -07001194{
1195 LIR *lir;
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001196 ArmLIR *armLIR;
Ben Cheng1efc9c52009-06-08 18:25:27 -07001197 int offset = 0;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001198 int i;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001199 ChainCellCounts chainCellCounts;
Ben Cheng7a2697d2010-06-07 13:44:23 -07001200 int descSize =
1201 cUnit->wholeMethod ? 0 : jitTraceDescriptionSize(cUnit->traceDesc);
Ben Chengcec26f62010-01-15 15:29:33 -08001202 int chainingCellGap;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001203
Bill Buzbee716f1202009-07-23 13:22:09 -07001204 info->instructionSet = cUnit->instructionSet;
1205
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001206 /* Beginning offset needs to allow space for chain cell offset */
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001207 for (armLIR = (ArmLIR *) cUnit->firstLIRInsn;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001208 armLIR;
1209 armLIR = NEXT_LIR(armLIR)) {
1210 armLIR->generic.offset = offset;
Ben Chenge9695e52009-06-16 16:11:47 -07001211 if (armLIR->opCode >= 0 && !armLIR->isNop) {
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001212 armLIR->size = EncodingMap[armLIR->opCode].size * 2;
1213 offset += armLIR->size;
Bill Buzbee1465db52009-09-23 17:17:35 -07001214 } else if (armLIR->opCode == kArmPseudoPseudoAlign4) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001215 if (offset & 0x2) {
1216 offset += 2;
1217 armLIR->operands[0] = 1;
1218 } else {
1219 armLIR->operands[0] = 0;
1220 }
1221 }
1222 /* Pseudo opcodes don't consume space */
1223 }
1224
1225 /* Const values have to be word aligned */
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001226 offset = (offset + 3) & ~3;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001227
Ben Chengcec26f62010-01-15 15:29:33 -08001228 /*
1229 * Get the gap (# of u4) between the offset of chaining cell count and
1230 * the bottom of real chaining cells. If the translation has chaining
1231 * cells, the gap is guaranteed to be multiples of 4.
1232 */
1233 chainingCellGap = (offset - cUnit->chainingCellBottom->offset) >> 2;
1234
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001235 /* Add space for chain cell counts & trace description */
Ben Cheng1efc9c52009-06-08 18:25:27 -07001236 u4 chainCellOffset = offset;
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001237 ArmLIR *chainCellOffsetLIR = (ArmLIR *) cUnit->chainCellOffsetLIR;
Bill Buzbee6e963e12009-06-17 16:56:19 -07001238 assert(chainCellOffsetLIR);
Ben Cheng1efc9c52009-06-08 18:25:27 -07001239 assert(chainCellOffset < 0x10000);
Bill Buzbee1465db52009-09-23 17:17:35 -07001240 assert(chainCellOffsetLIR->opCode == kArm16BitData &&
Ben Cheng1efc9c52009-06-08 18:25:27 -07001241 chainCellOffsetLIR->operands[0] == CHAIN_CELL_OFFSET_TAG);
1242
Ben Chenge80cd942009-07-17 15:54:23 -07001243 /*
1244 * Replace the CHAIN_CELL_OFFSET_TAG with the real value. If trace
1245 * profiling is enabled, subtract 4 (occupied by the counter word) from
1246 * the absolute offset as the value stored in chainCellOffsetLIR is the
1247 * delta from &chainCellOffsetLIR to &ChainCellCounts.
1248 */
1249 chainCellOffsetLIR->operands[0] =
1250 gDvmJit.profile ? (chainCellOffset - 4) : chainCellOffset;
Ben Cheng1efc9c52009-06-08 18:25:27 -07001251
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001252 offset += sizeof(chainCellCounts) + descSize;
1253
1254 assert((offset & 0x3) == 0); /* Should still be word aligned */
1255
1256 /* Set up offsets for literals */
Ben Chengba4fc8b2009-06-01 13:00:29 -07001257 cUnit->dataOffset = offset;
1258
1259 for (lir = cUnit->wordList; lir; lir = lir->next) {
1260 lir->offset = offset;
1261 offset += 4;
1262 }
1263
1264 cUnit->totalSize = offset;
1265
Ben Cheng7b133ef2010-02-04 16:15:59 -08001266 if (gDvmJit.codeCacheByteUsed + cUnit->totalSize > gDvmJit.codeCacheSize) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001267 gDvmJit.codeCacheFull = true;
1268 cUnit->baseAddr = NULL;
1269 return;
1270 }
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001271
1272 /* Allocate enough space for the code block */
1273 cUnit->codeBuffer = dvmCompilerNew(chainCellOffset, true);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001274 if (cUnit->codeBuffer == NULL) {
1275 LOGE("Code buffer allocation failure\n");
1276 cUnit->baseAddr = NULL;
1277 return;
1278 }
1279
Ben Cheng1efc9c52009-06-08 18:25:27 -07001280 bool assemblerFailure = assembleInstructions(
Ben Chengba4fc8b2009-06-01 13:00:29 -07001281 cUnit, (intptr_t) gDvmJit.codeCache + gDvmJit.codeCacheByteUsed);
1282
Ben Cheng1efc9c52009-06-08 18:25:27 -07001283 /*
1284 * Currently the only reason that can cause the assembler to fail is due to
1285 * trace length - cut it in half and retry.
1286 */
1287 if (assemblerFailure) {
1288 cUnit->halveInstCount = true;
1289 return;
1290 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07001291
Ben Chengdca71432010-03-16 16:04:11 -07001292#if defined(SIGNATURE_BREAKPOINT)
1293 if (info->discardResult == false && gDvmJit.signatureBreakpoint != NULL &&
1294 chainCellOffset/4 >= gDvmJit.signatureBreakpointSize) {
1295 matchSignatureBreakpoint(cUnit, chainCellOffset/4);
1296 }
1297#endif
1298
Ben Chengccd6c012009-10-15 14:52:45 -07001299 /* Don't go all the way if the goal is just to get the verbose output */
1300 if (info->discardResult) return;
Bill Buzbee6e963e12009-06-17 16:56:19 -07001301
Ben Chengba4fc8b2009-06-01 13:00:29 -07001302 cUnit->baseAddr = (char *) gDvmJit.codeCache + gDvmJit.codeCacheByteUsed;
1303 gDvmJit.codeCacheByteUsed += offset;
1304
Ben Chengb88ec3c2010-05-17 12:50:33 -07001305 UNPROTECT_CODE_CACHE(cUnit->baseAddr, offset);
1306
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001307 /* Install the code block */
Ben Cheng1efc9c52009-06-08 18:25:27 -07001308 memcpy((char*)cUnit->baseAddr, cUnit->codeBuffer, chainCellOffset);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001309 gDvmJit.numCompilations++;
1310
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001311 /* Install the chaining cell counts */
Ben Chengcec26f62010-01-15 15:29:33 -08001312 for (i=0; i< kChainingCellGap; i++) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001313 chainCellCounts.u.count[i] = cUnit->numChainingCells[i];
1314 }
Ben Chengcec26f62010-01-15 15:29:33 -08001315
1316 /* Set the gap number in the chaining cell count structure */
1317 chainCellCounts.u.count[kChainingCellGap] = chainingCellGap;
1318
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001319 memcpy((char*)cUnit->baseAddr + chainCellOffset, &chainCellCounts,
1320 sizeof(chainCellCounts));
1321
1322 /* Install the trace description */
1323 memcpy((char*)cUnit->baseAddr + chainCellOffset + sizeof(chainCellCounts),
1324 cUnit->traceDesc, descSize);
1325
1326 /* Write the literals directly into the code cache */
1327 installDataContent(cUnit);
1328
Ben Chengba4fc8b2009-06-01 13:00:29 -07001329 /* Flush dcache and invalidate the icache to maintain coherence */
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001330 cacheflush((long)cUnit->baseAddr,
Ben Chenge80cd942009-07-17 15:54:23 -07001331 (long)((char *) cUnit->baseAddr + offset), 0);
Ben Cheng978738d2010-05-13 13:45:57 -07001332 UPDATE_CODE_CACHE_PATCHES();
Bill Buzbee716f1202009-07-23 13:22:09 -07001333
Ben Chengb88ec3c2010-05-17 12:50:33 -07001334 PROTECT_CODE_CACHE(cUnit->baseAddr, offset);
1335
Bill Buzbee716f1202009-07-23 13:22:09 -07001336 /* Record code entry point and instruction set */
1337 info->codeAddress = (char*)cUnit->baseAddr + cUnit->headerSize;
Bill Buzbee716f1202009-07-23 13:22:09 -07001338 /* If applicable, mark low bit to denote thumb */
1339 if (info->instructionSet != DALVIK_JIT_ARM)
1340 info->codeAddress = (char*)info->codeAddress + 1;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001341}
1342
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001343/*
1344 * Returns the skeleton bit pattern associated with an opcode. All
1345 * variable fields are zeroed.
1346 */
1347static u4 getSkeleton(ArmOpCode op)
1348{
1349 return EncodingMap[op].skeleton;
1350}
1351
1352static u4 assembleChainingBranch(int branchOffset, bool thumbTarget)
Ben Cheng38329f52009-07-07 14:19:20 -07001353{
1354 u4 thumb1, thumb2;
1355
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001356 if (!thumbTarget) {
1357 thumb1 = (getSkeleton(kThumbBlx1) | ((branchOffset>>12) & 0x7ff));
1358 thumb2 = (getSkeleton(kThumbBlx2) | ((branchOffset>> 1) & 0x7ff));
1359 } else if ((branchOffset < -2048) | (branchOffset > 2046)) {
1360 thumb1 = (getSkeleton(kThumbBl1) | ((branchOffset>>12) & 0x7ff));
1361 thumb2 = (getSkeleton(kThumbBl2) | ((branchOffset>> 1) & 0x7ff));
Ben Cheng38329f52009-07-07 14:19:20 -07001362 } else {
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001363 thumb1 = (getSkeleton(kThumbBUncond) | ((branchOffset>> 1) & 0x7ff));
1364 thumb2 = getSkeleton(kThumbOrr); /* nop -> or r0, r0 */
Ben Cheng38329f52009-07-07 14:19:20 -07001365 }
1366
1367 return thumb2<<16 | thumb1;
1368}
1369
Ben Chengba4fc8b2009-06-01 13:00:29 -07001370/*
1371 * Perform translation chain operation.
1372 * For ARM, we'll use a pair of thumb instructions to generate
1373 * an unconditional chaining branch of up to 4MB in distance.
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001374 * Use a BL, because the generic "interpret" translation needs
1375 * the link register to find the dalvik pc of teh target.
Ben Chengba4fc8b2009-06-01 13:00:29 -07001376 * 111HHooooooooooo
1377 * Where HH is 10 for the 1st inst, and 11 for the second and
1378 * the "o" field is each instruction's 11-bit contribution to the
1379 * 22-bit branch offset.
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001380 * If the target is nearby, use a single-instruction bl.
1381 * If one or more threads is suspended, don't chain.
Ben Chengba4fc8b2009-06-01 13:00:29 -07001382 */
1383void* dvmJitChain(void* tgtAddr, u4* branchAddr)
1384{
1385 int baseAddr = (u4) branchAddr + 4;
1386 int branchOffset = (int) tgtAddr - baseAddr;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001387 u4 newInst;
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001388 bool thumbTarget;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001389
Ben Cheng6999d842010-01-26 16:46:15 -08001390 /*
1391 * Only chain translations when there is no urge to ask all threads to
1392 * suspend themselves via the interpreter.
1393 */
1394 if ((gDvmJit.pProfTable != NULL) && (gDvm.sumThreadSuspendCount == 0) &&
1395 (gDvmJit.codeCacheFull == false)) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001396 assert((branchOffset >= -(1<<22)) && (branchOffset <= ((1<<22)-2)));
Ben Chengba4fc8b2009-06-01 13:00:29 -07001397
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001398 gDvmJit.translationChains++;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001399
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001400 COMPILER_TRACE_CHAINING(
1401 LOGD("Jit Runtime: chaining 0x%x to 0x%x\n",
1402 (int) branchAddr, (int) tgtAddr & -2));
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001403
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001404 /*
1405 * NOTE: normally, all translations are Thumb[2] mode, with
1406 * a single exception: the default TEMPLATE_INTERPRET
1407 * pseudo-translation. If the need ever arises to
1408 * mix Arm & Thumb[2] translations, the following code should be
1409 * generalized.
1410 */
Bill Buzbeebd047242010-05-13 13:02:53 -07001411 thumbTarget = (tgtAddr != dvmCompilerGetInterpretTemplate());
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001412
1413 newInst = assembleChainingBranch(branchOffset, thumbTarget);
Ben Cheng38329f52009-07-07 14:19:20 -07001414
Bill Buzbeebd047242010-05-13 13:02:53 -07001415 /*
1416 * The second half-word instruction of the chaining cell must
1417 * either be a nop (which represents initial state), or is the
1418 * same exact branch halfword that we are trying to install.
1419 */
1420 assert( ((*branchAddr >> 16) == getSkeleton(kThumbOrr)) ||
1421 ((*branchAddr >> 16) == (newInst >> 16)));
1422
Ben Chengb88ec3c2010-05-17 12:50:33 -07001423 UNPROTECT_CODE_CACHE(branchAddr, sizeof(*branchAddr));
1424
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001425 *branchAddr = newInst;
1426 cacheflush((long)branchAddr, (long)branchAddr + 4, 0);
Ben Cheng978738d2010-05-13 13:45:57 -07001427 UPDATE_CODE_CACHE_PATCHES();
Ben Chengb88ec3c2010-05-17 12:50:33 -07001428
1429 PROTECT_CODE_CACHE(branchAddr, sizeof(*branchAddr));
1430
Ben Cheng6999d842010-01-26 16:46:15 -08001431 gDvmJit.hasNewChain = true;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001432 }
1433
Ben Chengba4fc8b2009-06-01 13:00:29 -07001434 return tgtAddr;
1435}
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001436
Ben Chengb88ec3c2010-05-17 12:50:33 -07001437#if !defined(WITH_SELF_VERIFICATION)
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001438/*
Ben Cheng6999d842010-01-26 16:46:15 -08001439 * Attempt to enqueue a work order to patch an inline cache for a predicted
1440 * chaining cell for virtual/interface calls.
1441 */
Ben Chengb88ec3c2010-05-17 12:50:33 -07001442static void inlineCachePatchEnqueue(PredictedChainingCell *cellAddr,
Ben Cheng452efba2010-04-30 15:14:00 -07001443 PredictedChainingCell *newContent)
Ben Cheng6999d842010-01-26 16:46:15 -08001444{
Ben Cheng452efba2010-04-30 15:14:00 -07001445 /*
1446 * Make sure only one thread gets here since updating the cell (ie fast
1447 * path and queueing the request (ie the queued path) have to be done
1448 * in an atomic fashion.
1449 */
Ben Cheng6999d842010-01-26 16:46:15 -08001450 dvmLockMutex(&gDvmJit.compilerICPatchLock);
1451
Ben Cheng452efba2010-04-30 15:14:00 -07001452 /* Fast path for uninitialized chaining cell */
Ben Cheng6999d842010-01-26 16:46:15 -08001453 if (cellAddr->clazz == NULL &&
1454 cellAddr->branch == PREDICTED_CHAIN_BX_PAIR_INIT) {
Ben Chengb88ec3c2010-05-17 12:50:33 -07001455
1456 UNPROTECT_CODE_CACHE(cellAddr, sizeof(*cellAddr));
1457
Ben Cheng452efba2010-04-30 15:14:00 -07001458 cellAddr->method = newContent->method;
1459 cellAddr->branch = newContent->branch;
Ben Cheng6999d842010-01-26 16:46:15 -08001460 /*
1461 * The update order matters - make sure clazz is updated last since it
1462 * will bring the uninitialized chaining cell to life.
1463 */
Andy McFadden6e10b9a2010-06-14 15:24:39 -07001464 ANDROID_MEMBAR_FULL();
Ben Cheng6999d842010-01-26 16:46:15 -08001465 cellAddr->clazz = newContent->clazz;
1466 cacheflush((intptr_t) cellAddr, (intptr_t) (cellAddr+1), 0);
Ben Cheng978738d2010-05-13 13:45:57 -07001467 UPDATE_CODE_CACHE_PATCHES();
Ben Chengb88ec3c2010-05-17 12:50:33 -07001468
1469 PROTECT_CODE_CACHE(cellAddr, sizeof(*cellAddr));
1470
Ben Cheng452efba2010-04-30 15:14:00 -07001471#if defined(WITH_JIT_TUNING)
Ben Chengb88ec3c2010-05-17 12:50:33 -07001472 gDvmJit.icPatchInit++;
Ben Cheng452efba2010-04-30 15:14:00 -07001473#endif
Ben Chengb88ec3c2010-05-17 12:50:33 -07001474 /* Check if this is a frequently missed clazz */
1475 } else if (cellAddr->stagedClazz != newContent->clazz) {
1476 /* Not proven to be frequent yet - build up the filter cache */
1477 UNPROTECT_CODE_CACHE(cellAddr, sizeof(*cellAddr));
1478
1479 cellAddr->stagedClazz = newContent->clazz;
1480
1481 UPDATE_CODE_CACHE_PATCHES();
1482 PROTECT_CODE_CACHE(cellAddr, sizeof(*cellAddr));
1483
1484#if defined(WITH_JIT_TUNING)
1485 gDvmJit.icPatchRejected++;
1486#endif
Ben Cheng452efba2010-04-30 15:14:00 -07001487 /*
Ben Chengb88ec3c2010-05-17 12:50:33 -07001488 * Different classes but same method implementation - it is safe to just
1489 * patch the class value without the need to stop the world.
Ben Cheng452efba2010-04-30 15:14:00 -07001490 */
Ben Chengb88ec3c2010-05-17 12:50:33 -07001491 } else if (cellAddr->method == newContent->method) {
1492 UNPROTECT_CODE_CACHE(cellAddr, sizeof(*cellAddr));
1493
1494 cellAddr->clazz = newContent->clazz;
1495 /* No need to flush the cache here since the branch is not patched */
1496 UPDATE_CODE_CACHE_PATCHES();
1497
1498 PROTECT_CODE_CACHE(cellAddr, sizeof(*cellAddr));
1499
1500#if defined(WITH_JIT_TUNING)
1501 gDvmJit.icPatchLockFree++;
1502#endif
1503 /*
1504 * Cannot patch the chaining cell inline - queue it until the next safe
1505 * point.
1506 */
1507 } else if (gDvmJit.compilerICPatchIndex < COMPILER_IC_PATCH_QUEUE_SIZE) {
Ben Cheng6999d842010-01-26 16:46:15 -08001508 int index = gDvmJit.compilerICPatchIndex++;
1509 gDvmJit.compilerICPatchQueue[index].cellAddr = cellAddr;
1510 gDvmJit.compilerICPatchQueue[index].cellContent = *newContent;
Ben Cheng452efba2010-04-30 15:14:00 -07001511#if defined(WITH_JIT_TUNING)
1512 gDvmJit.icPatchQueued++;
1513#endif
Ben Chengb88ec3c2010-05-17 12:50:33 -07001514 } else {
Ben Cheng452efba2010-04-30 15:14:00 -07001515 /* Queue is full - just drop this patch request */
Ben Cheng452efba2010-04-30 15:14:00 -07001516#if defined(WITH_JIT_TUNING)
1517 gDvmJit.icPatchDropped++;
1518#endif
Ben Cheng6999d842010-01-26 16:46:15 -08001519 }
1520
1521 dvmUnlockMutex(&gDvmJit.compilerICPatchLock);
Ben Cheng6999d842010-01-26 16:46:15 -08001522}
Carl Shapiroe3c01da2010-05-20 22:54:18 -07001523#endif
Ben Cheng6999d842010-01-26 16:46:15 -08001524
1525/*
Ben Cheng38329f52009-07-07 14:19:20 -07001526 * This method is called from the invoke templates for virtual and interface
1527 * methods to speculatively setup a chain to the callee. The templates are
1528 * written in assembly and have setup method, cell, and clazz at r0, r2, and
1529 * r3 respectively, so there is a unused argument in the list. Upon return one
1530 * of the following three results may happen:
1531 * 1) Chain is not setup because the callee is native. Reset the rechain
1532 * count to a big number so that it will take a long time before the next
1533 * rechain attempt to happen.
1534 * 2) Chain is not setup because the callee has not been created yet. Reset
1535 * the rechain count to a small number and retry in the near future.
1536 * 3) Ask all other threads to stop before patching this chaining cell.
1537 * This is required because another thread may have passed the class check
1538 * but hasn't reached the chaining cell yet to follow the chain. If we
1539 * patch the content before halting the other thread, there could be a
1540 * small window for race conditions to happen that it may follow the new
1541 * but wrong chain to invoke a different method.
1542 */
1543const Method *dvmJitToPatchPredictedChain(const Method *method,
Ben Chengb88ec3c2010-05-17 12:50:33 -07001544 InterpState *interpState,
Ben Cheng38329f52009-07-07 14:19:20 -07001545 PredictedChainingCell *cell,
1546 const ClassObject *clazz)
1547{
Ben Chengb88ec3c2010-05-17 12:50:33 -07001548 int newRechainCount = PREDICTED_CHAIN_COUNTER_RECHAIN;
Jeff Hao97319a82009-08-12 16:57:15 -07001549#if defined(WITH_SELF_VERIFICATION)
Ben Chengb88ec3c2010-05-17 12:50:33 -07001550 newRechainCount = PREDICTED_CHAIN_COUNTER_AVOID;
Jeff Hao97319a82009-08-12 16:57:15 -07001551 goto done;
1552#else
Ben Cheng38329f52009-07-07 14:19:20 -07001553 if (dvmIsNativeMethod(method)) {
Ben Chengb88ec3c2010-05-17 12:50:33 -07001554 UNPROTECT_CODE_CACHE(cell, sizeof(*cell));
1555
1556 /*
1557 * Put a non-zero/bogus value in the clazz field so that it won't
1558 * trigger immediate patching and will continue to fail to match with
1559 * a real clazz pointer.
1560 */
1561 cell->clazz = (void *) PREDICTED_CHAIN_FAKE_CLAZZ;
1562
Ben Cheng978738d2010-05-13 13:45:57 -07001563 UPDATE_CODE_CACHE_PATCHES();
Ben Chengb88ec3c2010-05-17 12:50:33 -07001564 PROTECT_CODE_CACHE(cell, sizeof(*cell));
Ben Cheng38329f52009-07-07 14:19:20 -07001565 goto done;
1566 }
1567 int tgtAddr = (int) dvmJitGetCodeAddr(method->insns);
1568
1569 /*
1570 * Compilation not made yet for the callee. Reset the counter to a small
1571 * value and come back to check soon.
1572 */
Bill Buzbeebd047242010-05-13 13:02:53 -07001573 if ((tgtAddr == 0) ||
1574 ((void*)tgtAddr == dvmCompilerGetInterpretTemplate())) {
Ben Cheng38329f52009-07-07 14:19:20 -07001575 COMPILER_TRACE_CHAINING(
Ben Chenga8e64a72009-10-20 13:01:36 -07001576 LOGD("Jit Runtime: predicted chain %p to method %s%s delayed",
1577 cell, method->clazz->descriptor, method->name));
Ben Cheng38329f52009-07-07 14:19:20 -07001578 goto done;
1579 }
1580
Ben Cheng6999d842010-01-26 16:46:15 -08001581 PredictedChainingCell newCell;
Ben Chenga8e64a72009-10-20 13:01:36 -07001582
Ben Chengb88ec3c2010-05-17 12:50:33 -07001583 if (cell->clazz == NULL) {
1584 newRechainCount = interpState->icRechainCount;
1585 }
Ben Cheng38329f52009-07-07 14:19:20 -07001586
1587 int baseAddr = (int) cell + 4; // PC is cur_addr + 4
1588 int branchOffset = tgtAddr - baseAddr;
1589
Ben Cheng6999d842010-01-26 16:46:15 -08001590 newCell.branch = assembleChainingBranch(branchOffset, true);
1591 newCell.clazz = clazz;
1592 newCell.method = method;
Ben Cheng38329f52009-07-07 14:19:20 -07001593
Ben Chenga8e64a72009-10-20 13:01:36 -07001594 /*
Ben Cheng6999d842010-01-26 16:46:15 -08001595 * Enter the work order to the queue and the chaining cell will be patched
1596 * the next time a safe point is entered.
Ben Cheng60c24f42010-01-04 12:29:56 -08001597 *
Ben Cheng6999d842010-01-26 16:46:15 -08001598 * If the enqueuing fails reset the rechain count to a normal value so that
1599 * it won't get indefinitely delayed.
Ben Cheng60c24f42010-01-04 12:29:56 -08001600 */
Ben Chengb88ec3c2010-05-17 12:50:33 -07001601 inlineCachePatchEnqueue(cell, &newCell);
Ben Cheng60c24f42010-01-04 12:29:56 -08001602#endif
1603done:
Ben Chengb88ec3c2010-05-17 12:50:33 -07001604 interpState->icRechainCount = newRechainCount;
Ben Cheng60c24f42010-01-04 12:29:56 -08001605 return method;
1606}
1607
1608/*
1609 * Patch the inline cache content based on the content passed from the work
1610 * order.
1611 */
Ben Cheng6999d842010-01-26 16:46:15 -08001612void dvmCompilerPatchInlineCache(void)
Ben Cheng60c24f42010-01-04 12:29:56 -08001613{
Ben Cheng6999d842010-01-26 16:46:15 -08001614 int i;
1615 PredictedChainingCell *minAddr, *maxAddr;
Ben Cheng60c24f42010-01-04 12:29:56 -08001616
Ben Cheng6999d842010-01-26 16:46:15 -08001617 /* Nothing to be done */
1618 if (gDvmJit.compilerICPatchIndex == 0) return;
Ben Cheng60c24f42010-01-04 12:29:56 -08001619
Ben Cheng6999d842010-01-26 16:46:15 -08001620 /*
1621 * Since all threads are already stopped we don't really need to acquire
1622 * the lock. But race condition can be easily introduced in the future w/o
1623 * paying attention so we still acquire the lock here.
1624 */
1625 dvmLockMutex(&gDvmJit.compilerICPatchLock);
Ben Cheng7a0bcd02010-01-22 16:45:45 -08001626
Ben Chengb88ec3c2010-05-17 12:50:33 -07001627 UNPROTECT_CODE_CACHE(gDvmJit.codeCache, gDvmJit.codeCacheByteUsed);
1628
Ben Cheng6999d842010-01-26 16:46:15 -08001629 //LOGD("Number of IC patch work orders: %d", gDvmJit.compilerICPatchIndex);
Ben Cheng60c24f42010-01-04 12:29:56 -08001630
Ben Cheng6999d842010-01-26 16:46:15 -08001631 /* Initialize the min/max address range */
1632 minAddr = (PredictedChainingCell *)
Ben Cheng7b133ef2010-02-04 16:15:59 -08001633 ((char *) gDvmJit.codeCache + gDvmJit.codeCacheSize);
Ben Cheng6999d842010-01-26 16:46:15 -08001634 maxAddr = (PredictedChainingCell *) gDvmJit.codeCache;
Ben Cheng60c24f42010-01-04 12:29:56 -08001635
Ben Cheng6999d842010-01-26 16:46:15 -08001636 for (i = 0; i < gDvmJit.compilerICPatchIndex; i++) {
1637 PredictedChainingCell *cellAddr =
1638 gDvmJit.compilerICPatchQueue[i].cellAddr;
1639 PredictedChainingCell *cellContent =
1640 &gDvmJit.compilerICPatchQueue[i].cellContent;
Ben Cheng38329f52009-07-07 14:19:20 -07001641
Ben Chengb88ec3c2010-05-17 12:50:33 -07001642 COMPILER_TRACE_CHAINING(
1643 LOGD("Jit Runtime: predicted chain %p from %s to %s (%s) "
1644 "patched",
1645 cellAddr,
1646 cellAddr->clazz->descriptor,
1647 cellContent->clazz->descriptor,
1648 cellContent->method->name));
Ben Cheng38329f52009-07-07 14:19:20 -07001649
Ben Cheng6999d842010-01-26 16:46:15 -08001650 /* Patch the chaining cell */
1651 *cellAddr = *cellContent;
1652 minAddr = (cellAddr < minAddr) ? cellAddr : minAddr;
1653 maxAddr = (cellAddr > maxAddr) ? cellAddr : maxAddr;
1654 }
1655
1656 /* Then synchronize the I/D cache */
1657 cacheflush((long) minAddr, (long) (maxAddr+1), 0);
Ben Cheng978738d2010-05-13 13:45:57 -07001658 UPDATE_CODE_CACHE_PATCHES();
Ben Cheng6999d842010-01-26 16:46:15 -08001659
Ben Chengb88ec3c2010-05-17 12:50:33 -07001660 PROTECT_CODE_CACHE(gDvmJit.codeCache, gDvmJit.codeCacheByteUsed);
1661
Ben Cheng6999d842010-01-26 16:46:15 -08001662 gDvmJit.compilerICPatchIndex = 0;
1663 dvmUnlockMutex(&gDvmJit.compilerICPatchLock);
Ben Cheng38329f52009-07-07 14:19:20 -07001664}
1665
1666/*
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001667 * Unchain a trace given the starting address of the translation
1668 * in the code cache. Refer to the diagram in dvmCompilerAssembleLIR.
1669 * Returns the address following the last cell unchained. Note that
1670 * the incoming codeAddr is a thumb code address, and therefore has
1671 * the low bit set.
1672 */
1673u4* dvmJitUnchain(void* codeAddr)
1674{
1675 u2* pChainCellOffset = (u2*)((char*)codeAddr - 3);
1676 u2 chainCellOffset = *pChainCellOffset;
1677 ChainCellCounts *pChainCellCounts =
Ben Chenge80cd942009-07-17 15:54:23 -07001678 (ChainCellCounts*)((char*)codeAddr + chainCellOffset - 3);
Ben Cheng38329f52009-07-07 14:19:20 -07001679 int cellSize;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001680 u4* pChainCells;
1681 u4* pStart;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001682 u4 newInst;
1683 int i,j;
Ben Cheng38329f52009-07-07 14:19:20 -07001684 PredictedChainingCell *predChainCell;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001685
1686 /* Get total count of chain cells */
Ben Chengcec26f62010-01-15 15:29:33 -08001687 for (i = 0, cellSize = 0; i < kChainingCellGap; i++) {
Bill Buzbee1465db52009-09-23 17:17:35 -07001688 if (i != kChainingCellInvokePredicted) {
Bill Buzbeebd047242010-05-13 13:02:53 -07001689 cellSize += pChainCellCounts->u.count[i] * (CHAIN_CELL_NORMAL_SIZE >> 2);
Ben Cheng38329f52009-07-07 14:19:20 -07001690 } else {
Bill Buzbeebd047242010-05-13 13:02:53 -07001691 cellSize += pChainCellCounts->u.count[i] *
1692 (CHAIN_CELL_PREDICTED_SIZE >> 2);
Ben Cheng38329f52009-07-07 14:19:20 -07001693 }
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001694 }
1695
Ben Chengcec26f62010-01-15 15:29:33 -08001696 if (cellSize == 0)
1697 return (u4 *) pChainCellCounts;
1698
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001699 /* Locate the beginning of the chain cell region */
Ben Chengcec26f62010-01-15 15:29:33 -08001700 pStart = pChainCells = ((u4 *) pChainCellCounts) - cellSize -
1701 pChainCellCounts->u.count[kChainingCellGap];
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001702
1703 /* The cells are sorted in order - walk through them and reset */
Ben Chengcec26f62010-01-15 15:29:33 -08001704 for (i = 0; i < kChainingCellGap; i++) {
Bill Buzbeebd047242010-05-13 13:02:53 -07001705 int elemSize = CHAIN_CELL_NORMAL_SIZE >> 2; /* In 32-bit words */
Bill Buzbee1465db52009-09-23 17:17:35 -07001706 if (i == kChainingCellInvokePredicted) {
Bill Buzbeebd047242010-05-13 13:02:53 -07001707 elemSize = CHAIN_CELL_PREDICTED_SIZE >> 2;
Ben Cheng38329f52009-07-07 14:19:20 -07001708 }
1709
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001710 for (j = 0; j < pChainCellCounts->u.count[i]; j++) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001711 switch(i) {
Bill Buzbee1465db52009-09-23 17:17:35 -07001712 case kChainingCellNormal:
Bill Buzbee1465db52009-09-23 17:17:35 -07001713 case kChainingCellHot:
1714 case kChainingCellInvokeSingleton:
Bill Buzbeebd047242010-05-13 13:02:53 -07001715 case kChainingCellBackwardBranch:
1716 /*
1717 * Replace the 1st half-word of the cell with an
1718 * unconditional branch, leaving the 2nd half-word
1719 * untouched. This avoids problems with a thread
1720 * that is suspended between the two halves when
1721 * this unchaining takes place.
1722 */
1723 newInst = *pChainCells;
1724 newInst &= 0xFFFF0000;
1725 newInst |= getSkeleton(kThumbBUncond); /* b offset is 0 */
1726 *pChainCells = newInst;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001727 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001728 case kChainingCellInvokePredicted:
Ben Cheng38329f52009-07-07 14:19:20 -07001729 predChainCell = (PredictedChainingCell *) pChainCells;
Ben Cheng7a0bcd02010-01-22 16:45:45 -08001730 /*
1731 * There could be a race on another mutator thread to use
1732 * this particular predicted cell and the check has passed
1733 * the clazz comparison. So we cannot safely wipe the
1734 * method and branch but it is safe to clear the clazz,
1735 * which serves as the key.
1736 */
Ben Cheng38329f52009-07-07 14:19:20 -07001737 predChainCell->clazz = PREDICTED_CHAIN_CLAZZ_INIT;
Ben Cheng38329f52009-07-07 14:19:20 -07001738 break;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001739 default:
Ben Chengbb0dce52009-11-03 16:19:11 -08001740 LOGE("Unexpected chaining type: %d", i);
Bill Buzbeefc519dc2010-03-06 23:30:57 -08001741 dvmAbort(); // dvmAbort OK here - can't safely recover
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001742 }
Ben Cheng38329f52009-07-07 14:19:20 -07001743 COMPILER_TRACE_CHAINING(
1744 LOGD("Jit Runtime: unchaining 0x%x", (int)pChainCells));
Ben Cheng38329f52009-07-07 14:19:20 -07001745 pChainCells += elemSize; /* Advance by a fixed number of words */
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001746 }
1747 }
1748 return pChainCells;
1749}
1750
1751/* Unchain all translation in the cache. */
1752void dvmJitUnchainAll()
1753{
1754 u4* lowAddress = NULL;
1755 u4* highAddress = NULL;
1756 unsigned int i;
1757 if (gDvmJit.pJitEntryTable != NULL) {
1758 COMPILER_TRACE_CHAINING(LOGD("Jit Runtime: unchaining all"));
1759 dvmLockMutex(&gDvmJit.tableLock);
Ben Chengb88ec3c2010-05-17 12:50:33 -07001760
1761 UNPROTECT_CODE_CACHE(gDvmJit.codeCache, gDvmJit.codeCacheByteUsed);
1762
Bill Buzbee27176222009-06-09 09:20:16 -07001763 for (i = 0; i < gDvmJit.jitTableSize; i++) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001764 if (gDvmJit.pJitEntryTable[i].dPC &&
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001765 gDvmJit.pJitEntryTable[i].codeAddress &&
1766 (gDvmJit.pJitEntryTable[i].codeAddress !=
Bill Buzbeebd047242010-05-13 13:02:53 -07001767 dvmCompilerGetInterpretTemplate())) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001768 u4* lastAddress;
1769 lastAddress =
1770 dvmJitUnchain(gDvmJit.pJitEntryTable[i].codeAddress);
1771 if (lowAddress == NULL ||
1772 (u4*)gDvmJit.pJitEntryTable[i].codeAddress < lowAddress)
1773 lowAddress = lastAddress;
1774 if (lastAddress > highAddress)
1775 highAddress = lastAddress;
1776 }
1777 }
1778 cacheflush((long)lowAddress, (long)highAddress, 0);
Ben Cheng978738d2010-05-13 13:45:57 -07001779 UPDATE_CODE_CACHE_PATCHES();
Ben Chengb88ec3c2010-05-17 12:50:33 -07001780
1781 PROTECT_CODE_CACHE(gDvmJit.codeCache, gDvmJit.codeCacheByteUsed);
1782
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001783 dvmUnlockMutex(&gDvmJit.tableLock);
Ben Cheng7a0bcd02010-01-22 16:45:45 -08001784 gDvmJit.translationChains = 0;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001785 }
Ben Cheng6999d842010-01-26 16:46:15 -08001786 gDvmJit.hasNewChain = false;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001787}
Bill Buzbee716f1202009-07-23 13:22:09 -07001788
1789typedef struct jitProfileAddrToLine {
1790 u4 lineNum;
1791 u4 bytecodeOffset;
1792} jitProfileAddrToLine;
1793
1794
1795/* Callback function to track the bytecode offset/line number relationiship */
1796static int addrToLineCb (void *cnxt, u4 bytecodeOffset, u4 lineNum)
1797{
1798 jitProfileAddrToLine *addrToLine = (jitProfileAddrToLine *) cnxt;
1799
1800 /* Best match so far for this offset */
1801 if (addrToLine->bytecodeOffset >= bytecodeOffset) {
1802 addrToLine->lineNum = lineNum;
1803 }
1804 return 0;
1805}
1806
Ben Chengb88ec3c2010-05-17 12:50:33 -07001807static char *getTraceBase(const JitEntry *p)
Bill Buzbee716f1202009-07-23 13:22:09 -07001808{
1809 return (char*)p->codeAddress -
1810 (6 + (p->u.info.instructionSet == DALVIK_JIT_ARM ? 0 : 1));
1811}
1812
1813/* Dumps profile info for a single trace */
Ben Cheng88a0f972010-02-24 15:00:40 -08001814static int dumpTraceProfile(JitEntry *p, bool silent, bool reset,
1815 unsigned long sum)
Bill Buzbee716f1202009-07-23 13:22:09 -07001816{
1817 ChainCellCounts* pCellCounts;
1818 char* traceBase;
1819 u4* pExecutionCount;
Ben Cheng88a0f972010-02-24 15:00:40 -08001820 u4 executionCount;
Bill Buzbee716f1202009-07-23 13:22:09 -07001821 u2* pCellOffset;
1822 JitTraceDescription *desc;
1823 const Method* method;
1824
1825 traceBase = getTraceBase(p);
1826
1827 if (p->codeAddress == NULL) {
Ben Cheng88a0f972010-02-24 15:00:40 -08001828 if (!silent)
1829 LOGD("TRACEPROFILE 0x%08x 0 NULL 0 0", (int)traceBase);
Bill Buzbee716f1202009-07-23 13:22:09 -07001830 return 0;
1831 }
Bill Buzbeebd047242010-05-13 13:02:53 -07001832 if (p->codeAddress == dvmCompilerGetInterpretTemplate()) {
Ben Cheng88a0f972010-02-24 15:00:40 -08001833 if (!silent)
1834 LOGD("TRACEPROFILE 0x%08x 0 INTERPRET_ONLY 0 0", (int)traceBase);
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001835 return 0;
1836 }
Bill Buzbee716f1202009-07-23 13:22:09 -07001837
1838 pExecutionCount = (u4*) (traceBase);
Ben Cheng88a0f972010-02-24 15:00:40 -08001839 executionCount = *pExecutionCount;
1840 if (reset) {
1841 *pExecutionCount =0;
1842 }
1843 if (silent) {
1844 return executionCount;
1845 }
Bill Buzbee716f1202009-07-23 13:22:09 -07001846 pCellOffset = (u2*) (traceBase + 4);
1847 pCellCounts = (ChainCellCounts*) ((char *)pCellOffset + *pCellOffset);
1848 desc = (JitTraceDescription*) ((char*)pCellCounts + sizeof(*pCellCounts));
1849 method = desc->method;
1850 char *methodDesc = dexProtoCopyMethodDescriptor(&method->prototype);
1851 jitProfileAddrToLine addrToLine = {0, desc->trace[0].frag.startOffset};
1852
1853 /*
1854 * We may end up decoding the debug information for the same method
1855 * multiple times, but the tradeoff is we don't need to allocate extra
1856 * space to store the addr/line mapping. Since this is a debugging feature
1857 * and done infrequently so the slower but simpler mechanism should work
1858 * just fine.
1859 */
1860 dexDecodeDebugInfo(method->clazz->pDvmDex->pDexFile,
1861 dvmGetMethodCode(method),
1862 method->clazz->descriptor,
1863 method->prototype.protoIdx,
1864 method->accessFlags,
1865 addrToLineCb, NULL, &addrToLine);
1866
Ben Cheng88a0f972010-02-24 15:00:40 -08001867 LOGD("TRACEPROFILE 0x%08x % 10d %5.2f%% [%#x(+%d), %d] %s%s;%s",
Bill Buzbee716f1202009-07-23 13:22:09 -07001868 (int)traceBase,
Ben Cheng88a0f972010-02-24 15:00:40 -08001869 executionCount,
1870 ((float ) executionCount) / sum * 100.0,
Bill Buzbee716f1202009-07-23 13:22:09 -07001871 desc->trace[0].frag.startOffset,
1872 desc->trace[0].frag.numInsts,
1873 addrToLine.lineNum,
1874 method->clazz->descriptor, method->name, methodDesc);
1875 free(methodDesc);
1876
Ben Cheng88a0f972010-02-24 15:00:40 -08001877 return executionCount;
Bill Buzbee716f1202009-07-23 13:22:09 -07001878}
1879
Ben Chengccd6c012009-10-15 14:52:45 -07001880/* Create a copy of the trace descriptor of an existing compilation */
Ben Cheng88a0f972010-02-24 15:00:40 -08001881JitTraceDescription *dvmCopyTraceDescriptor(const u2 *pc,
1882 const JitEntry *knownEntry)
Ben Chengccd6c012009-10-15 14:52:45 -07001883{
Ben Cheng88a0f972010-02-24 15:00:40 -08001884 const JitEntry *jitEntry = knownEntry ? knownEntry : dvmFindJitEntry(pc);
Ben Chengccd6c012009-10-15 14:52:45 -07001885 if (jitEntry == NULL) return NULL;
1886
1887 /* Find out the startint point */
1888 char *traceBase = getTraceBase(jitEntry);
1889
1890 /* Then find out the starting point of the chaining cell */
1891 u2 *pCellOffset = (u2*) (traceBase + 4);
1892 ChainCellCounts *pCellCounts =
1893 (ChainCellCounts*) ((char *)pCellOffset + *pCellOffset);
1894
1895 /* From there we can find out the starting point of the trace descriptor */
1896 JitTraceDescription *desc =
1897 (JitTraceDescription*) ((char*)pCellCounts + sizeof(*pCellCounts));
1898
1899 /* Now make a copy and return */
1900 int descSize = jitTraceDescriptionSize(desc);
1901 JitTraceDescription *newCopy = (JitTraceDescription *) malloc(descSize);
1902 memcpy(newCopy, desc, descSize);
1903 return newCopy;
1904}
1905
Bill Buzbee716f1202009-07-23 13:22:09 -07001906/* Handy function to retrieve the profile count */
1907static inline int getProfileCount(const JitEntry *entry)
1908{
Ben Chengb88ec3c2010-05-17 12:50:33 -07001909 if (entry->dPC == 0 || entry->codeAddress == 0 ||
1910 entry->codeAddress == dvmCompilerGetInterpretTemplate())
Bill Buzbee716f1202009-07-23 13:22:09 -07001911 return 0;
Ben Chengb88ec3c2010-05-17 12:50:33 -07001912
Bill Buzbee716f1202009-07-23 13:22:09 -07001913 u4 *pExecutionCount = (u4 *) getTraceBase(entry);
1914
1915 return *pExecutionCount;
1916}
1917
1918
1919/* qsort callback function */
1920static int sortTraceProfileCount(const void *entry1, const void *entry2)
1921{
1922 const JitEntry *jitEntry1 = entry1;
1923 const JitEntry *jitEntry2 = entry2;
1924
1925 int count1 = getProfileCount(jitEntry1);
1926 int count2 = getProfileCount(jitEntry2);
1927 return (count1 == count2) ? 0 : ((count1 > count2) ? -1 : 1);
1928}
1929
1930/* Sort the trace profile counts and dump them */
1931void dvmCompilerSortAndPrintTraceProfiles()
1932{
1933 JitEntry *sortedEntries;
1934 int numTraces = 0;
Ben Cheng88a0f972010-02-24 15:00:40 -08001935 unsigned long sum = 0;
Bill Buzbee716f1202009-07-23 13:22:09 -07001936 unsigned int i;
1937
1938 /* Make sure that the table is not changing */
1939 dvmLockMutex(&gDvmJit.tableLock);
1940
1941 /* Sort the entries by descending order */
1942 sortedEntries = malloc(sizeof(JitEntry) * gDvmJit.jitTableSize);
1943 if (sortedEntries == NULL)
1944 goto done;
1945 memcpy(sortedEntries, gDvmJit.pJitEntryTable,
1946 sizeof(JitEntry) * gDvmJit.jitTableSize);
1947 qsort(sortedEntries, gDvmJit.jitTableSize, sizeof(JitEntry),
1948 sortTraceProfileCount);
1949
Ben Cheng88a0f972010-02-24 15:00:40 -08001950 /* Analyze the sorted entries */
Bill Buzbee716f1202009-07-23 13:22:09 -07001951 for (i=0; i < gDvmJit.jitTableSize; i++) {
1952 if (sortedEntries[i].dPC != 0) {
Ben Cheng88a0f972010-02-24 15:00:40 -08001953 sum += dumpTraceProfile(&sortedEntries[i],
1954 true /* silent */,
1955 false /* reset */,
1956 0);
Bill Buzbee716f1202009-07-23 13:22:09 -07001957 numTraces++;
1958 }
1959 }
1960 if (numTraces == 0)
1961 numTraces = 1;
Ben Cheng88a0f972010-02-24 15:00:40 -08001962 if (sum == 0) {
1963 sum = 1;
1964 }
1965
1966 LOGD("JIT: Average execution count -> %d",(int)(sum / numTraces));
1967
1968 /* Dump the sorted entries. The count of each trace will be reset to 0. */
1969 for (i=0; i < gDvmJit.jitTableSize; i++) {
1970 if (sortedEntries[i].dPC != 0) {
1971 dumpTraceProfile(&sortedEntries[i],
1972 false /* silent */,
1973 true /* reset */,
1974 sum);
1975 }
1976 }
1977
1978 for (i=0; i < gDvmJit.jitTableSize && i < 10; i++) {
Ben Chengb88ec3c2010-05-17 12:50:33 -07001979 /* Stip interpreter stubs */
1980 if (sortedEntries[i].codeAddress == dvmCompilerGetInterpretTemplate()) {
1981 continue;
1982 }
Ben Cheng88a0f972010-02-24 15:00:40 -08001983 JitTraceDescription* desc =
1984 dvmCopyTraceDescriptor(NULL, &sortedEntries[i]);
1985 dvmCompilerWorkEnqueue(sortedEntries[i].dPC,
1986 kWorkOrderTraceDebug, desc);
1987 }
Bill Buzbee716f1202009-07-23 13:22:09 -07001988
1989 free(sortedEntries);
1990done:
1991 dvmUnlockMutex(&gDvmJit.tableLock);
1992 return;
1993}
jeffhao9e45c0b2010-02-03 10:24:05 -08001994
1995#if defined(WITH_SELF_VERIFICATION)
1996/*
1997 * The following are used to keep compiled loads and stores from modifying
1998 * memory during self verification mode.
1999 *
2000 * Stores do not modify memory. Instead, the address and value pair are stored
2001 * into heapSpace. Addresses within heapSpace are unique. For accesses smaller
2002 * than a word, the word containing the address is loaded first before being
2003 * updated.
2004 *
2005 * Loads check heapSpace first and return data from there if an entry exists.
2006 * Otherwise, data is loaded from memory as usual.
2007 */
2008
2009/* Used to specify sizes of memory operations */
2010enum {
2011 kSVByte,
2012 kSVSignedByte,
2013 kSVHalfword,
2014 kSVSignedHalfword,
2015 kSVWord,
2016 kSVDoubleword,
jeffhao121ea792010-02-10 10:51:02 -08002017 kSVVariable,
jeffhao9e45c0b2010-02-03 10:24:05 -08002018};
2019
2020/* Load the value of a decoded register from the stack */
2021static int selfVerificationMemRegLoad(int* sp, int reg)
2022{
2023 return *(sp + reg);
2024}
2025
2026/* Load the value of a decoded doubleword register from the stack */
2027static s8 selfVerificationMemRegLoadDouble(int* sp, int reg)
2028{
2029 return *((s8*)(sp + reg));
2030}
2031
2032/* Store the value of a decoded register out to the stack */
2033static void selfVerificationMemRegStore(int* sp, int data, int reg)
2034{
2035 *(sp + reg) = data;
2036}
2037
2038/* Store the value of a decoded doubleword register out to the stack */
2039static void selfVerificationMemRegStoreDouble(int* sp, s8 data, int reg)
2040{
2041 *((s8*)(sp + reg)) = data;
2042}
2043
2044/*
2045 * Load the specified size of data from the specified address, checking
2046 * heapSpace first if Self Verification mode wrote to it previously, and
2047 * falling back to actual memory otherwise.
2048 */
2049static int selfVerificationLoad(int addr, int size)
2050{
2051 Thread *self = dvmThreadSelf();
2052 ShadowSpace *shadowSpace = self->shadowSpace;
2053 ShadowHeap *heapSpacePtr;
2054
2055 int data;
2056 int maskedAddr = addr & 0xFFFFFFFC;
2057 int alignment = addr & 0x3;
2058
2059 for (heapSpacePtr = shadowSpace->heapSpace;
2060 heapSpacePtr != shadowSpace->heapSpaceTail; heapSpacePtr++) {
2061 if (heapSpacePtr->addr == maskedAddr) {
2062 addr = ((unsigned int) &(heapSpacePtr->data)) | alignment;
2063 break;
2064 }
2065 }
2066
2067 switch (size) {
2068 case kSVByte:
2069 data = *((u1*) addr);
2070 break;
2071 case kSVSignedByte:
2072 data = *((s1*) addr);
2073 break;
2074 case kSVHalfword:
2075 data = *((u2*) addr);
2076 break;
2077 case kSVSignedHalfword:
2078 data = *((s2*) addr);
2079 break;
2080 case kSVWord:
2081 data = *((u4*) addr);
jeffhao91080d22010-02-09 14:55:47 -08002082 break;
jeffhaoe8667642010-02-05 15:08:23 -08002083 default:
jeffhao91080d22010-02-09 14:55:47 -08002084 LOGE("*** ERROR: BAD SIZE IN selfVerificationLoad: %d", size);
jeffhaoe8667642010-02-05 15:08:23 -08002085 data = 0;
2086 dvmAbort();
jeffhao9e45c0b2010-02-03 10:24:05 -08002087 }
2088
2089 //LOGD("*** HEAP LOAD: Addr: 0x%x Data: 0x%x Size: %d", addr, data, size);
2090 return data;
2091}
2092
2093/* Like selfVerificationLoad, but specifically for doublewords */
2094static s8 selfVerificationLoadDoubleword(int addr)
2095{
2096 Thread *self = dvmThreadSelf();
2097 ShadowSpace* shadowSpace = self->shadowSpace;
2098 ShadowHeap* heapSpacePtr;
2099
2100 int addr2 = addr+4;
2101 unsigned int data = *((unsigned int*) addr);
2102 unsigned int data2 = *((unsigned int*) addr2);
2103
2104 for (heapSpacePtr = shadowSpace->heapSpace;
2105 heapSpacePtr != shadowSpace->heapSpaceTail; heapSpacePtr++) {
2106 if (heapSpacePtr->addr == addr) {
2107 data = heapSpacePtr->data;
2108 } else if (heapSpacePtr->addr == addr2) {
2109 data2 = heapSpacePtr->data;
2110 }
2111 }
2112
2113 //LOGD("*** HEAP LOAD DOUBLEWORD: Addr: 0x%x Data: 0x%x Data2: 0x%x",
2114 // addr, data, data2);
2115 return (((s8) data2) << 32) | data;
2116}
2117
2118/*
2119 * Handles a store of a specified size of data to a specified address.
2120 * This gets logged as an addr/data pair in heapSpace instead of modifying
2121 * memory. Addresses in heapSpace are unique, and accesses smaller than a
2122 * word pull the entire word from memory first before updating.
2123 */
2124static void selfVerificationStore(int addr, int data, int size)
2125{
2126 Thread *self = dvmThreadSelf();
2127 ShadowSpace *shadowSpace = self->shadowSpace;
2128 ShadowHeap *heapSpacePtr;
2129
2130 int maskedAddr = addr & 0xFFFFFFFC;
2131 int alignment = addr & 0x3;
2132
2133 //LOGD("*** HEAP STORE: Addr: 0x%x Data: 0x%x Size: %d", addr, data, size);
2134
2135 for (heapSpacePtr = shadowSpace->heapSpace;
2136 heapSpacePtr != shadowSpace->heapSpaceTail; heapSpacePtr++) {
2137 if (heapSpacePtr->addr == maskedAddr) break;
2138 }
2139
2140 if (heapSpacePtr == shadowSpace->heapSpaceTail) {
2141 heapSpacePtr->addr = maskedAddr;
2142 heapSpacePtr->data = *((unsigned int*) maskedAddr);
2143 shadowSpace->heapSpaceTail++;
2144 }
2145
2146 addr = ((unsigned int) &(heapSpacePtr->data)) | alignment;
2147 switch (size) {
2148 case kSVByte:
2149 *((u1*) addr) = data;
2150 break;
2151 case kSVSignedByte:
2152 *((s1*) addr) = data;
2153 break;
2154 case kSVHalfword:
2155 *((u2*) addr) = data;
2156 break;
2157 case kSVSignedHalfword:
2158 *((s2*) addr) = data;
2159 break;
2160 case kSVWord:
2161 *((u4*) addr) = data;
jeffhao91080d22010-02-09 14:55:47 -08002162 break;
jeffhaoe8667642010-02-05 15:08:23 -08002163 default:
jeffhao91080d22010-02-09 14:55:47 -08002164 LOGE("*** ERROR: BAD SIZE IN selfVerificationSave: %d", size);
jeffhaoe8667642010-02-05 15:08:23 -08002165 dvmAbort();
jeffhao9e45c0b2010-02-03 10:24:05 -08002166 }
2167}
2168
2169/* Like selfVerificationStore, but specifically for doublewords */
2170static void selfVerificationStoreDoubleword(int addr, s8 double_data)
2171{
2172 Thread *self = dvmThreadSelf();
2173 ShadowSpace *shadowSpace = self->shadowSpace;
2174 ShadowHeap *heapSpacePtr;
2175
2176 int addr2 = addr+4;
2177 int data = double_data;
2178 int data2 = double_data >> 32;
2179 bool store1 = false, store2 = false;
2180
2181 //LOGD("*** HEAP STORE DOUBLEWORD: Addr: 0x%x Data: 0x%x, Data2: 0x%x",
2182 // addr, data, data2);
2183
2184 for (heapSpacePtr = shadowSpace->heapSpace;
2185 heapSpacePtr != shadowSpace->heapSpaceTail; heapSpacePtr++) {
2186 if (heapSpacePtr->addr == addr) {
2187 heapSpacePtr->data = data;
2188 store1 = true;
2189 } else if (heapSpacePtr->addr == addr2) {
2190 heapSpacePtr->data = data2;
2191 store2 = true;
2192 }
2193 }
2194
2195 if (!store1) {
2196 shadowSpace->heapSpaceTail->addr = addr;
2197 shadowSpace->heapSpaceTail->data = data;
2198 shadowSpace->heapSpaceTail++;
2199 }
2200 if (!store2) {
2201 shadowSpace->heapSpaceTail->addr = addr2;
2202 shadowSpace->heapSpaceTail->data = data2;
2203 shadowSpace->heapSpaceTail++;
2204 }
2205}
2206
2207/*
2208 * Decodes the memory instruction at the address specified in the link
2209 * register. All registers (r0-r12,lr) and fp registers (d0-d15) are stored
2210 * consecutively on the stack beginning at the specified stack pointer.
2211 * Calls the proper Self Verification handler for the memory instruction and
2212 * updates the link register to point past the decoded memory instruction.
2213 */
2214void dvmSelfVerificationMemOpDecode(int lr, int* sp)
2215{
2216 enum {
2217 kMemOpLdrPcRel = 0x09, // ldr(3) [01001] rd[10..8] imm_8[7..0]
2218 kMemOpRRR = 0x0A, // Full opcode is 7 bits
2219 kMemOp2Single = 0x0A, // Used for Vstrs and Vldrs
2220 kMemOpRRR2 = 0x0B, // Full opcode is 7 bits
2221 kMemOp2Double = 0x0B, // Used for Vstrd and Vldrd
2222 kMemOpStrRRI5 = 0x0C, // str(1) [01100] imm_5[10..6] rn[5..3] rd[2..0]
2223 kMemOpLdrRRI5 = 0x0D, // ldr(1) [01101] imm_5[10..6] rn[5..3] rd[2..0]
2224 kMemOpStrbRRI5 = 0x0E, // strb(1) [01110] imm_5[10..6] rn[5..3] rd[2..0]
2225 kMemOpLdrbRRI5 = 0x0F, // ldrb(1) [01111] imm_5[10..6] rn[5..3] rd[2..0]
2226 kMemOpStrhRRI5 = 0x10, // strh(1) [10000] imm_5[10..6] rn[5..3] rd[2..0]
2227 kMemOpLdrhRRI5 = 0x11, // ldrh(1) [10001] imm_5[10..6] rn[5..3] rd[2..0]
2228 kMemOpLdrSpRel = 0x13, // ldr(4) [10011] rd[10..8] imm_8[7..0]
jeffhao121ea792010-02-10 10:51:02 -08002229 kMemOpStmia = 0x18, // stmia [11000] rn[10..8] reglist [7..0]
2230 kMemOpLdmia = 0x19, // ldmia [11001] rn[10..8] reglist [7..0]
jeffhao9e45c0b2010-02-03 10:24:05 -08002231 kMemOpStrRRR = 0x28, // str(2) [0101000] rm[8..6] rn[5..3] rd[2..0]
2232 kMemOpStrhRRR = 0x29, // strh(2) [0101001] rm[8..6] rn[5..3] rd[2..0]
2233 kMemOpStrbRRR = 0x2A, // strb(2) [0101010] rm[8..6] rn[5..3] rd[2..0]
2234 kMemOpLdrsbRRR = 0x2B, // ldrsb [0101011] rm[8..6] rn[5..3] rd[2..0]
2235 kMemOpLdrRRR = 0x2C, // ldr(2) [0101100] rm[8..6] rn[5..3] rd[2..0]
2236 kMemOpLdrhRRR = 0x2D, // ldrh(2) [0101101] rm[8..6] rn[5..3] rd[2..0]
2237 kMemOpLdrbRRR = 0x2E, // ldrb(2) [0101110] rm[8..6] rn[5..3] rd[2..0]
2238 kMemOpLdrshRRR = 0x2F, // ldrsh [0101111] rm[8..6] rn[5..3] rd[2..0]
jeffhao121ea792010-02-10 10:51:02 -08002239 kMemOp2Stmia = 0xE88, // stmia [111010001000[ rn[19..16] mask[15..0]
2240 kMemOp2Ldmia = 0xE89, // ldmia [111010001001[ rn[19..16] mask[15..0]
2241 kMemOp2Stmia2 = 0xE8A, // stmia [111010001010[ rn[19..16] mask[15..0]
2242 kMemOp2Ldmia2 = 0xE8B, // ldmia [111010001011[ rn[19..16] mask[15..0]
jeffhao9e45c0b2010-02-03 10:24:05 -08002243 kMemOp2Vstr = 0xED8, // Used for Vstrs and Vstrd
2244 kMemOp2Vldr = 0xED9, // Used for Vldrs and Vldrd
2245 kMemOp2Vstr2 = 0xEDC, // Used for Vstrs and Vstrd
2246 kMemOp2Vldr2 = 0xEDD, // Used for Vstrs and Vstrd
2247 kMemOp2StrbRRR = 0xF80, /* str rt,[rn,rm,LSL #imm] [111110000000]
2248 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2249 kMemOp2LdrbRRR = 0xF81, /* ldrb rt,[rn,rm,LSL #imm] [111110000001]
2250 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2251 kMemOp2StrhRRR = 0xF82, /* str rt,[rn,rm,LSL #imm] [111110000010]
2252 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2253 kMemOp2LdrhRRR = 0xF83, /* ldrh rt,[rn,rm,LSL #imm] [111110000011]
2254 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2255 kMemOp2StrRRR = 0xF84, /* str rt,[rn,rm,LSL #imm] [111110000100]
2256 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2257 kMemOp2LdrRRR = 0xF85, /* ldr rt,[rn,rm,LSL #imm] [111110000101]
2258 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2259 kMemOp2StrbRRI12 = 0xF88, /* strb rt,[rn,#imm12] [111110001000]
2260 rt[15..12] rn[19..16] imm12[11..0] */
2261 kMemOp2LdrbRRI12 = 0xF89, /* ldrb rt,[rn,#imm12] [111110001001]
2262 rt[15..12] rn[19..16] imm12[11..0] */
2263 kMemOp2StrhRRI12 = 0xF8A, /* strh rt,[rn,#imm12] [111110001010]
2264 rt[15..12] rn[19..16] imm12[11..0] */
2265 kMemOp2LdrhRRI12 = 0xF8B, /* ldrh rt,[rn,#imm12] [111110001011]
2266 rt[15..12] rn[19..16] imm12[11..0] */
2267 kMemOp2StrRRI12 = 0xF8C, /* str(Imm,T3) rd,[rn,#imm12] [111110001100]
2268 rn[19..16] rt[15..12] imm12[11..0] */
2269 kMemOp2LdrRRI12 = 0xF8D, /* ldr(Imm,T3) rd,[rn,#imm12] [111110001101]
2270 rn[19..16] rt[15..12] imm12[11..0] */
2271 kMemOp2LdrsbRRR = 0xF91, /* ldrsb rt,[rn,rm,LSL #imm] [111110010001]
2272 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2273 kMemOp2LdrshRRR = 0xF93, /* ldrsh rt,[rn,rm,LSL #imm] [111110010011]
2274 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2275 kMemOp2LdrsbRRI12 = 0xF99, /* ldrsb rt,[rn,#imm12] [111110011001]
2276 rt[15..12] rn[19..16] imm12[11..0] */
2277 kMemOp2LdrshRRI12 = 0xF9B, /* ldrsh rt,[rn,#imm12] [111110011011]
2278 rt[15..12] rn[19..16] imm12[11..0] */
2279 kMemOp2 = 0xE000, // top 3 bits set indicates Thumb2
2280 };
2281
2282 int addr, offset, data;
2283 long long double_data;
2284 int size = kSVWord;
2285 bool store = false;
2286 unsigned int *lr_masked = (unsigned int *) (lr & 0xFFFFFFFE);
2287 unsigned int insn = *lr_masked;
2288
2289 int old_lr;
2290 old_lr = selfVerificationMemRegLoad(sp, 13);
2291
2292 if ((insn & kMemOp2) == kMemOp2) {
2293 insn = (insn << 16) | (insn >> 16);
2294 //LOGD("*** THUMB2 - Addr: 0x%x Insn: 0x%x", lr, insn);
2295
2296 int opcode12 = (insn >> 20) & 0xFFF;
jeffhao9e45c0b2010-02-03 10:24:05 -08002297 int opcode4 = (insn >> 8) & 0xF;
2298 int imm2 = (insn >> 4) & 0x3;
2299 int imm8 = insn & 0xFF;
2300 int imm12 = insn & 0xFFF;
2301 int rd = (insn >> 12) & 0xF;
2302 int rm = insn & 0xF;
2303 int rn = (insn >> 16) & 0xF;
2304 int rt = (insn >> 12) & 0xF;
jeffhao121ea792010-02-10 10:51:02 -08002305 bool wBack = true;
jeffhao9e45c0b2010-02-03 10:24:05 -08002306
2307 // Update the link register
2308 selfVerificationMemRegStore(sp, old_lr+4, 13);
2309
2310 // Determine whether the mem op is a store or load
2311 switch (opcode12) {
jeffhao121ea792010-02-10 10:51:02 -08002312 case kMemOp2Stmia:
2313 case kMemOp2Stmia2:
jeffhao9e45c0b2010-02-03 10:24:05 -08002314 case kMemOp2Vstr:
2315 case kMemOp2Vstr2:
2316 case kMemOp2StrbRRR:
2317 case kMemOp2StrhRRR:
2318 case kMemOp2StrRRR:
2319 case kMemOp2StrbRRI12:
2320 case kMemOp2StrhRRI12:
2321 case kMemOp2StrRRI12:
2322 store = true;
2323 }
2324
2325 // Determine the size of the mem access
2326 switch (opcode12) {
2327 case kMemOp2StrbRRR:
2328 case kMemOp2LdrbRRR:
2329 case kMemOp2StrbRRI12:
2330 case kMemOp2LdrbRRI12:
2331 size = kSVByte;
2332 break;
2333 case kMemOp2LdrsbRRR:
2334 case kMemOp2LdrsbRRI12:
2335 size = kSVSignedByte;
2336 break;
2337 case kMemOp2StrhRRR:
2338 case kMemOp2LdrhRRR:
2339 case kMemOp2StrhRRI12:
2340 case kMemOp2LdrhRRI12:
2341 size = kSVHalfword;
2342 break;
2343 case kMemOp2LdrshRRR:
2344 case kMemOp2LdrshRRI12:
2345 size = kSVSignedHalfword;
2346 break;
2347 case kMemOp2Vstr:
2348 case kMemOp2Vstr2:
2349 case kMemOp2Vldr:
2350 case kMemOp2Vldr2:
2351 if (opcode4 == kMemOp2Double) size = kSVDoubleword;
2352 break;
jeffhao121ea792010-02-10 10:51:02 -08002353 case kMemOp2Stmia:
2354 case kMemOp2Ldmia:
2355 case kMemOp2Stmia2:
2356 case kMemOp2Ldmia2:
2357 size = kSVVariable;
2358 break;
jeffhao9e45c0b2010-02-03 10:24:05 -08002359 }
2360
2361 // Load the value of the address
2362 addr = selfVerificationMemRegLoad(sp, rn);
2363
2364 // Figure out the offset
2365 switch (opcode12) {
2366 case kMemOp2Vstr:
2367 case kMemOp2Vstr2:
2368 case kMemOp2Vldr:
2369 case kMemOp2Vldr2:
2370 offset = imm8 << 2;
2371 if (opcode4 == kMemOp2Single) {
2372 rt = rd << 1;
2373 if (insn & 0x400000) rt |= 0x1;
2374 } else if (opcode4 == kMemOp2Double) {
2375 if (insn & 0x400000) rt |= 0x10;
2376 rt = rt << 1;
2377 } else {
jeffhao91080d22010-02-09 14:55:47 -08002378 LOGE("*** ERROR: UNRECOGNIZED VECTOR MEM OP: %x", opcode4);
jeffhao9e45c0b2010-02-03 10:24:05 -08002379 dvmAbort();
2380 }
2381 rt += 14;
2382 break;
2383 case kMemOp2StrbRRR:
2384 case kMemOp2LdrbRRR:
2385 case kMemOp2StrhRRR:
2386 case kMemOp2LdrhRRR:
2387 case kMemOp2StrRRR:
2388 case kMemOp2LdrRRR:
2389 case kMemOp2LdrsbRRR:
2390 case kMemOp2LdrshRRR:
2391 offset = selfVerificationMemRegLoad(sp, rm) << imm2;
2392 break;
2393 case kMemOp2StrbRRI12:
2394 case kMemOp2LdrbRRI12:
2395 case kMemOp2StrhRRI12:
2396 case kMemOp2LdrhRRI12:
2397 case kMemOp2StrRRI12:
2398 case kMemOp2LdrRRI12:
2399 case kMemOp2LdrsbRRI12:
2400 case kMemOp2LdrshRRI12:
2401 offset = imm12;
2402 break;
jeffhao121ea792010-02-10 10:51:02 -08002403 case kMemOp2Stmia:
2404 case kMemOp2Ldmia:
2405 wBack = false;
2406 case kMemOp2Stmia2:
2407 case kMemOp2Ldmia2:
2408 offset = 0;
2409 break;
jeffhao9e45c0b2010-02-03 10:24:05 -08002410 default:
jeffhao91080d22010-02-09 14:55:47 -08002411 LOGE("*** ERROR: UNRECOGNIZED THUMB2 MEM OP: %x", opcode12);
jeffhaoe8667642010-02-05 15:08:23 -08002412 offset = 0;
jeffhao9e45c0b2010-02-03 10:24:05 -08002413 dvmAbort();
2414 }
2415
2416 // Handle the decoded mem op accordingly
2417 if (store) {
jeffhao121ea792010-02-10 10:51:02 -08002418 if (size == kSVVariable) {
2419 LOGD("*** THUMB2 STMIA CURRENTLY UNUSED (AND UNTESTED)");
2420 int i;
2421 int regList = insn & 0xFFFF;
2422 for (i = 0; i < 16; i++) {
2423 if (regList & 0x1) {
2424 data = selfVerificationMemRegLoad(sp, i);
2425 selfVerificationStore(addr, data, kSVWord);
2426 addr += 4;
2427 }
2428 regList = regList >> 1;
2429 }
2430 if (wBack) selfVerificationMemRegStore(sp, addr, rn);
2431 } else if (size == kSVDoubleword) {
jeffhao9e45c0b2010-02-03 10:24:05 -08002432 double_data = selfVerificationMemRegLoadDouble(sp, rt);
2433 selfVerificationStoreDoubleword(addr+offset, double_data);
2434 } else {
2435 data = selfVerificationMemRegLoad(sp, rt);
2436 selfVerificationStore(addr+offset, data, size);
2437 }
2438 } else {
jeffhao121ea792010-02-10 10:51:02 -08002439 if (size == kSVVariable) {
2440 LOGD("*** THUMB2 LDMIA CURRENTLY UNUSED (AND UNTESTED)");
2441 int i;
2442 int regList = insn & 0xFFFF;
2443 for (i = 0; i < 16; i++) {
2444 if (regList & 0x1) {
2445 data = selfVerificationLoad(addr, kSVWord);
2446 selfVerificationMemRegStore(sp, data, i);
2447 addr += 4;
2448 }
2449 regList = regList >> 1;
2450 }
2451 if (wBack) selfVerificationMemRegStore(sp, addr, rn);
2452 } else if (size == kSVDoubleword) {
jeffhao9e45c0b2010-02-03 10:24:05 -08002453 double_data = selfVerificationLoadDoubleword(addr+offset);
2454 selfVerificationMemRegStoreDouble(sp, double_data, rt);
2455 } else {
2456 data = selfVerificationLoad(addr+offset, size);
2457 selfVerificationMemRegStore(sp, data, rt);
2458 }
2459 }
2460 } else {
2461 //LOGD("*** THUMB - Addr: 0x%x Insn: 0x%x", lr, insn);
2462
2463 // Update the link register
2464 selfVerificationMemRegStore(sp, old_lr+2, 13);
2465
2466 int opcode5 = (insn >> 11) & 0x1F;
2467 int opcode7 = (insn >> 9) & 0x7F;
2468 int imm = (insn >> 6) & 0x1F;
2469 int rd = (insn >> 8) & 0x7;
2470 int rm = (insn >> 6) & 0x7;
2471 int rn = (insn >> 3) & 0x7;
2472 int rt = insn & 0x7;
2473
2474 // Determine whether the mem op is a store or load
2475 switch (opcode5) {
2476 case kMemOpRRR:
2477 switch (opcode7) {
2478 case kMemOpStrRRR:
2479 case kMemOpStrhRRR:
2480 case kMemOpStrbRRR:
2481 store = true;
2482 }
2483 break;
2484 case kMemOpStrRRI5:
2485 case kMemOpStrbRRI5:
2486 case kMemOpStrhRRI5:
jeffhao121ea792010-02-10 10:51:02 -08002487 case kMemOpStmia:
jeffhao9e45c0b2010-02-03 10:24:05 -08002488 store = true;
2489 }
2490
2491 // Determine the size of the mem access
2492 switch (opcode5) {
2493 case kMemOpRRR:
2494 case kMemOpRRR2:
2495 switch (opcode7) {
2496 case kMemOpStrbRRR:
2497 case kMemOpLdrbRRR:
2498 size = kSVByte;
2499 break;
2500 case kMemOpLdrsbRRR:
2501 size = kSVSignedByte;
2502 break;
2503 case kMemOpStrhRRR:
2504 case kMemOpLdrhRRR:
2505 size = kSVHalfword;
2506 break;
2507 case kMemOpLdrshRRR:
2508 size = kSVSignedHalfword;
2509 break;
2510 }
2511 break;
2512 case kMemOpStrbRRI5:
2513 case kMemOpLdrbRRI5:
2514 size = kSVByte;
2515 break;
2516 case kMemOpStrhRRI5:
2517 case kMemOpLdrhRRI5:
2518 size = kSVHalfword;
2519 break;
jeffhao121ea792010-02-10 10:51:02 -08002520 case kMemOpStmia:
2521 case kMemOpLdmia:
2522 size = kSVVariable;
2523 break;
jeffhao9e45c0b2010-02-03 10:24:05 -08002524 }
2525
2526 // Load the value of the address
2527 if (opcode5 == kMemOpLdrPcRel)
2528 addr = selfVerificationMemRegLoad(sp, 4);
jeffhao121ea792010-02-10 10:51:02 -08002529 else if (opcode5 == kMemOpStmia || opcode5 == kMemOpLdmia)
2530 addr = selfVerificationMemRegLoad(sp, rd);
jeffhao9e45c0b2010-02-03 10:24:05 -08002531 else
2532 addr = selfVerificationMemRegLoad(sp, rn);
2533
2534 // Figure out the offset
2535 switch (opcode5) {
2536 case kMemOpLdrPcRel:
2537 offset = (insn & 0xFF) << 2;
2538 rt = rd;
2539 break;
2540 case kMemOpRRR:
2541 case kMemOpRRR2:
2542 offset = selfVerificationMemRegLoad(sp, rm);
2543 break;
2544 case kMemOpStrRRI5:
2545 case kMemOpLdrRRI5:
2546 offset = imm << 2;
2547 break;
2548 case kMemOpStrhRRI5:
2549 case kMemOpLdrhRRI5:
2550 offset = imm << 1;
2551 break;
2552 case kMemOpStrbRRI5:
2553 case kMemOpLdrbRRI5:
2554 offset = imm;
2555 break;
jeffhao121ea792010-02-10 10:51:02 -08002556 case kMemOpStmia:
2557 case kMemOpLdmia:
2558 offset = 0;
2559 break;
jeffhao9e45c0b2010-02-03 10:24:05 -08002560 default:
jeffhao91080d22010-02-09 14:55:47 -08002561 LOGE("*** ERROR: UNRECOGNIZED THUMB MEM OP: %x", opcode5);
jeffhaoe8667642010-02-05 15:08:23 -08002562 offset = 0;
jeffhao9e45c0b2010-02-03 10:24:05 -08002563 dvmAbort();
2564 }
2565
2566 // Handle the decoded mem op accordingly
2567 if (store) {
jeffhao121ea792010-02-10 10:51:02 -08002568 if (size == kSVVariable) {
2569 int i;
2570 int regList = insn & 0xFF;
2571 for (i = 0; i < 8; i++) {
2572 if (regList & 0x1) {
2573 data = selfVerificationMemRegLoad(sp, i);
2574 selfVerificationStore(addr, data, kSVWord);
2575 addr += 4;
2576 }
2577 regList = regList >> 1;
2578 }
2579 selfVerificationMemRegStore(sp, addr, rd);
2580 } else {
2581 data = selfVerificationMemRegLoad(sp, rt);
2582 selfVerificationStore(addr+offset, data, size);
2583 }
jeffhao9e45c0b2010-02-03 10:24:05 -08002584 } else {
jeffhao121ea792010-02-10 10:51:02 -08002585 if (size == kSVVariable) {
2586 bool wBack = true;
2587 int i;
2588 int regList = insn & 0xFF;
2589 for (i = 0; i < 8; i++) {
2590 if (regList & 0x1) {
2591 if (i == rd) wBack = false;
2592 data = selfVerificationLoad(addr, kSVWord);
2593 selfVerificationMemRegStore(sp, data, i);
2594 addr += 4;
2595 }
2596 regList = regList >> 1;
2597 }
2598 if (wBack) selfVerificationMemRegStore(sp, addr, rd);
2599 } else {
2600 data = selfVerificationLoad(addr+offset, size);
2601 selfVerificationMemRegStore(sp, data, rt);
2602 }
jeffhao9e45c0b2010-02-03 10:24:05 -08002603 }
2604 }
2605}
2606#endif