blob: 832ee0fea3753385a8443ee579e5e3bee5edbe24 [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;
908 for (runCount = 0; ; runCount++) {
909 if (desc->trace[runCount].frag.runEnd)
910 break;
911 }
912 return sizeof(JitCodeDesc) + ((runCount+1) * sizeof(JitTraceRun));
913}
914
Ben Chengba4fc8b2009-06-01 13:00:29 -0700915/* Return TRUE if error happens */
916static bool assembleInstructions(CompilationUnit *cUnit, intptr_t startAddr)
917{
918 short *bufferAddr = (short *) cUnit->codeBuffer;
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700919 ArmLIR *lir;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700920
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700921 for (lir = (ArmLIR *) cUnit->firstLIRInsn; lir; lir = NEXT_LIR(lir)) {
Ben Chengba4fc8b2009-06-01 13:00:29 -0700922 if (lir->opCode < 0) {
Bill Buzbee1465db52009-09-23 17:17:35 -0700923 if ((lir->opCode == kArmPseudoPseudoAlign4) &&
Ben Cheng1efc9c52009-06-08 18:25:27 -0700924 /* 1 means padding is needed */
925 (lir->operands[0] == 1)) {
Ben Cheng6d576092009-09-01 17:01:58 -0700926 *bufferAddr++ = PADDING_MOV_R5_R5;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700927 }
928 continue;
929 }
930
Ben Chenge9695e52009-06-16 16:11:47 -0700931 if (lir->isNop) {
932 continue;
933 }
934
Bill Buzbee1465db52009-09-23 17:17:35 -0700935 if (lir->opCode == kThumbLdrPcRel ||
936 lir->opCode == kThumb2LdrPcRel12 ||
937 lir->opCode == kThumbAddPcRel ||
938 ((lir->opCode == kThumb2Vldrs) && (lir->operands[1] == rpc))) {
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700939 ArmLIR *lirTarget = (ArmLIR *) lir->generic.target;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700940 intptr_t pc = (lir->generic.offset + 4) & ~3;
Ben Cheng38329f52009-07-07 14:19:20 -0700941 /*
942 * Allow an offset (stored in operands[2] to be added to the
943 * PC-relative target. Useful to get to a fixed field inside a
944 * chaining cell.
945 */
946 intptr_t target = lirTarget->generic.offset + lir->operands[2];
Ben Chengba4fc8b2009-06-01 13:00:29 -0700947 int delta = target - pc;
948 if (delta & 0x3) {
949 LOGE("PC-rel distance is not multiples of 4: %d\n", delta);
Bill Buzbeefc519dc2010-03-06 23:30:57 -0800950 dvmCompilerAbort(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700951 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700952 if ((lir->opCode == kThumb2LdrPcRel12) && (delta > 4091)) {
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700953 return true;
954 } else if (delta > 1020) {
Ben Cheng1efc9c52009-06-08 18:25:27 -0700955 return true;
956 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700957 if (lir->opCode == kThumb2Vldrs) {
958 lir->operands[2] = delta >> 2;
959 } else {
960 lir->operands[1] = (lir->opCode == kThumb2LdrPcRel12) ?
961 delta : delta >> 2;
962 }
963 } else if (lir->opCode == kThumb2Cbnz || lir->opCode == kThumb2Cbz) {
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700964 ArmLIR *targetLIR = (ArmLIR *) lir->generic.target;
965 intptr_t pc = lir->generic.offset + 4;
966 intptr_t target = targetLIR->generic.offset;
967 int delta = target - pc;
968 if (delta > 126 || delta < 0) {
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700969 /*
Bill Buzbee7fb2edd2009-08-31 10:25:55 -0700970 * TODO: allow multiple kinds of assembler failure to allow
971 * change of code patterns when things don't fit.
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700972 */
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700973 return true;
Bill Buzbeea4a7f072009-08-27 13:58:09 -0700974 } else {
975 lir->operands[1] = delta >> 1;
Bill Buzbee7ea0f642009-08-10 17:06:51 -0700976 }
Bill Buzbee1465db52009-09-23 17:17:35 -0700977 } else if (lir->opCode == kThumbBCond ||
978 lir->opCode == kThumb2BCond) {
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700979 ArmLIR *targetLIR = (ArmLIR *) lir->generic.target;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700980 intptr_t pc = lir->generic.offset + 4;
981 intptr_t target = targetLIR->generic.offset;
982 int delta = target - pc;
Bill Buzbee1465db52009-09-23 17:17:35 -0700983 if ((lir->opCode == kThumbBCond) && (delta > 254 || delta < -256)) {
Ben Cheng1efc9c52009-06-08 18:25:27 -0700984 return true;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700985 }
986 lir->operands[0] = delta >> 1;
Bill Buzbee1465db52009-09-23 17:17:35 -0700987 } else if (lir->opCode == kThumbBUncond) {
Bill Buzbee89efc3d2009-07-28 11:22:22 -0700988 ArmLIR *targetLIR = (ArmLIR *) lir->generic.target;
Ben Chengba4fc8b2009-06-01 13:00:29 -0700989 intptr_t pc = lir->generic.offset + 4;
990 intptr_t target = targetLIR->generic.offset;
991 int delta = target - pc;
992 if (delta > 2046 || delta < -2048) {
993 LOGE("Unconditional branch distance out of range: %d\n", delta);
Bill Buzbeefc519dc2010-03-06 23:30:57 -0800994 dvmCompilerAbort(cUnit);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700995 }
996 lir->operands[0] = delta >> 1;
Bill Buzbee1465db52009-09-23 17:17:35 -0700997 } else if (lir->opCode == kThumbBlx1) {
998 assert(NEXT_LIR(lir)->opCode == kThumbBlx2);
Ben Chengba4fc8b2009-06-01 13:00:29 -0700999 /* curPC is Thumb */
1000 intptr_t curPC = (startAddr + lir->generic.offset + 4) & ~3;
1001 intptr_t target = lir->operands[1];
1002
1003 /* Match bit[1] in target with base */
1004 if (curPC & 0x2) {
1005 target |= 0x2;
1006 }
1007 int delta = target - curPC;
1008 assert((delta >= -(1<<22)) && (delta <= ((1<<22)-2)));
1009
1010 lir->operands[0] = (delta >> 12) & 0x7ff;
1011 NEXT_LIR(lir)->operands[0] = (delta>> 1) & 0x7ff;
1012 }
1013
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001014 ArmEncodingMap *encoder = &EncodingMap[lir->opCode];
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001015 u4 bits = encoder->skeleton;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001016 int i;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001017 for (i = 0; i < 4; i++) {
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001018 u4 operand;
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001019 u4 value;
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001020 operand = lir->operands[i];
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001021 switch(encoder->fieldLoc[i].kind) {
Bill Buzbee1465db52009-09-23 17:17:35 -07001022 case kFmtUnused:
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001023 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001024 case kFmtFPImm:
1025 value = ((operand & 0xF0) >> 4) << encoder->fieldLoc[i].end;
1026 value |= (operand & 0x0F) << encoder->fieldLoc[i].start;
1027 bits |= value;
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001028 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001029 case kFmtBrOffset:
1030 /*
1031 * NOTE: branch offsets are not handled here, but
1032 * in the main assembly loop (where label values
1033 * are known). For reference, here is what the
1034 * encoder handing would be:
1035 value = ((operand & 0x80000) >> 19) << 26;
1036 value |= ((operand & 0x40000) >> 18) << 11;
1037 value |= ((operand & 0x20000) >> 17) << 13;
1038 value |= ((operand & 0x1f800) >> 11) << 16;
1039 value |= (operand & 0x007ff);
1040 bits |= value;
1041 */
1042 break;
1043 case kFmtShift5:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001044 value = ((operand & 0x1c) >> 2) << 12;
1045 value |= (operand & 0x03) << 6;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001046 bits |= value;
1047 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001048 case kFmtShift:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001049 value = ((operand & 0x70) >> 4) << 12;
1050 value |= (operand & 0x0f) << 4;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001051 bits |= value;
1052 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001053 case kFmtBWidth:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001054 value = operand - 1;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001055 bits |= value;
1056 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001057 case kFmtLsb:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001058 value = ((operand & 0x1c) >> 2) << 12;
1059 value |= (operand & 0x03) << 6;
Bill Buzbee270c1d62009-08-13 16:58:07 -07001060 bits |= value;
1061 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001062 case kFmtImm6:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001063 value = ((operand & 0x20) >> 5) << 9;
1064 value |= (operand & 0x1f) << 3;
Bill Buzbee7ea0f642009-08-10 17:06:51 -07001065 bits |= value;
1066 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001067 case kFmtBitBlt:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001068 value = (operand << encoder->fieldLoc[i].start) &
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001069 ((1 << (encoder->fieldLoc[i].end + 1)) - 1);
1070 bits |= value;
1071 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001072 case kFmtDfp: {
1073 assert(DOUBLEREG(operand));
1074 assert((operand & 0x1) == 0);
Ben Cheng30f1f462009-10-12 13:46:55 -07001075 int regName = (operand & FP_REG_MASK) >> 1;
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001076 /* Snag the 1-bit slice and position it */
Ben Cheng30f1f462009-10-12 13:46:55 -07001077 value = ((regName & 0x10) >> 4) <<
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001078 encoder->fieldLoc[i].end;
1079 /* Extract and position the 4-bit slice */
Ben Cheng30f1f462009-10-12 13:46:55 -07001080 value |= (regName & 0x0f) <<
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001081 encoder->fieldLoc[i].start;
1082 bits |= value;
1083 break;
Ben Cheng30f1f462009-10-12 13:46:55 -07001084 }
Bill Buzbee1465db52009-09-23 17:17:35 -07001085 case kFmtSfp:
1086 assert(SINGLEREG(operand));
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001087 /* Snag the 1-bit slice and position it */
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001088 value = (operand & 0x1) <<
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001089 encoder->fieldLoc[i].end;
1090 /* Extract and position the 4-bit slice */
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001091 value |= ((operand & 0x1e) >> 1) <<
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001092 encoder->fieldLoc[i].start;
1093 bits |= value;
1094 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001095 case kFmtImm12:
1096 case kFmtModImm:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001097 value = ((operand & 0x800) >> 11) << 26;
1098 value |= ((operand & 0x700) >> 8) << 12;
1099 value |= operand & 0x0ff;
Bill Buzbee7ea0f642009-08-10 17:06:51 -07001100 bits |= value;
1101 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001102 case kFmtImm16:
Bill Buzbeea4a7f072009-08-27 13:58:09 -07001103 value = ((operand & 0x0800) >> 11) << 26;
1104 value |= ((operand & 0xf000) >> 12) << 16;
1105 value |= ((operand & 0x0700) >> 8) << 12;
1106 value |= operand & 0x0ff;
Bill Buzbee7ea0f642009-08-10 17:06:51 -07001107 bits |= value;
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001108 break;
1109 default:
1110 assert(0);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001111 }
1112 }
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001113 if (encoder->size == 2) {
1114 *bufferAddr++ = (bits >> 16) & 0xffff;
1115 }
1116 *bufferAddr++ = bits & 0xffff;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001117 }
Ben Cheng1efc9c52009-06-08 18:25:27 -07001118 return false;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001119}
1120
Ben Cheng9fa39c92010-03-16 16:20:48 -07001121#if defined(SIGNATURE_BREAKPOINT)
Ben Chengdca71432010-03-16 16:04:11 -07001122/* Inspect the assembled instruction stream to find potential matches */
1123static void matchSignatureBreakpoint(const CompilationUnit *cUnit,
1124 unsigned int size)
1125{
1126 unsigned int i, j;
1127 u4 *ptr = (u4 *) cUnit->codeBuffer;
1128
1129 for (i = 0; i < size - gDvmJit.signatureBreakpointSize + 1; i++) {
1130 if (ptr[i] == gDvmJit.signatureBreakpoint[0]) {
1131 for (j = 1; j < gDvmJit.signatureBreakpointSize; j++) {
1132 if (ptr[i+j] != gDvmJit.signatureBreakpoint[j]) {
1133 break;
1134 }
1135 }
1136 if (j == gDvmJit.signatureBreakpointSize) {
1137 LOGD("Signature match starting from offset %#x (%d words)",
1138 i*4, gDvmJit.signatureBreakpointSize);
1139 int descSize = jitTraceDescriptionSize(cUnit->traceDesc);
1140 JitTraceDescription *newCopy =
1141 (JitTraceDescription *) malloc(descSize);
1142 memcpy(newCopy, cUnit->traceDesc, descSize);
1143 dvmCompilerWorkEnqueue(NULL, kWorkOrderTraceDebug, newCopy);
1144 break;
1145 }
1146 }
1147 }
1148}
Ben Cheng9fa39c92010-03-16 16:20:48 -07001149#endif
Ben Chengdca71432010-03-16 16:04:11 -07001150
Ben Chengba4fc8b2009-06-01 13:00:29 -07001151/*
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001152 * Translation layout in the code cache. Note that the codeAddress pointer
1153 * in JitTable will point directly to the code body (field codeAddress). The
1154 * chain cell offset codeAddress - 2, and (if present) executionCount is at
1155 * codeAddress - 6.
1156 *
1157 * +----------------------------+
1158 * | Execution count | -> [Optional] 4 bytes
1159 * +----------------------------+
1160 * +--| Offset to chain cell counts| -> 2 bytes
1161 * | +----------------------------+
1162 * | | Code body | -> Start address for translation
1163 * | | | variable in 2-byte chunks
1164 * | . . (JitTable's codeAddress points here)
1165 * | . .
1166 * | | |
1167 * | +----------------------------+
Bill Buzbeebd047242010-05-13 13:02:53 -07001168 * | | Chaining Cells | -> 12/16 bytes each, must be 4 byte aligned
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001169 * | . .
1170 * | . .
1171 * | | |
1172 * | +----------------------------+
Ben Chengcec26f62010-01-15 15:29:33 -08001173 * | | Gap for large switch stmt | -> # cases >= MAX_CHAINED_SWITCH_CASES
1174 * | +----------------------------+
1175 * +->| Chaining cell counts | -> 8 bytes, chain cell counts by type
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001176 * +----------------------------+
1177 * | Trace description | -> variable sized
1178 * . .
1179 * | |
1180 * +----------------------------+
1181 * | Literal pool | -> 4-byte aligned, variable size
1182 * . .
1183 * . .
1184 * | |
1185 * +----------------------------+
1186 *
Ben Chengba4fc8b2009-06-01 13:00:29 -07001187 * Go over each instruction in the list and calculate the offset from the top
1188 * before sending them off to the assembler. If out-of-range branch distance is
1189 * seen rearrange the instructions a bit to correct it.
1190 */
Bill Buzbee716f1202009-07-23 13:22:09 -07001191void dvmCompilerAssembleLIR(CompilationUnit *cUnit, JitTranslationInfo *info)
Ben Chengba4fc8b2009-06-01 13:00:29 -07001192{
1193 LIR *lir;
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001194 ArmLIR *armLIR;
Ben Cheng1efc9c52009-06-08 18:25:27 -07001195 int offset = 0;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001196 int i;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001197 ChainCellCounts chainCellCounts;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001198 int descSize = jitTraceDescriptionSize(cUnit->traceDesc);
Ben Chengcec26f62010-01-15 15:29:33 -08001199 int chainingCellGap;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001200
Bill Buzbee716f1202009-07-23 13:22:09 -07001201 info->instructionSet = cUnit->instructionSet;
1202
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001203 /* Beginning offset needs to allow space for chain cell offset */
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001204 for (armLIR = (ArmLIR *) cUnit->firstLIRInsn;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001205 armLIR;
1206 armLIR = NEXT_LIR(armLIR)) {
1207 armLIR->generic.offset = offset;
Ben Chenge9695e52009-06-16 16:11:47 -07001208 if (armLIR->opCode >= 0 && !armLIR->isNop) {
Bill Buzbee9bc3df32009-07-30 10:52:29 -07001209 armLIR->size = EncodingMap[armLIR->opCode].size * 2;
1210 offset += armLIR->size;
Bill Buzbee1465db52009-09-23 17:17:35 -07001211 } else if (armLIR->opCode == kArmPseudoPseudoAlign4) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001212 if (offset & 0x2) {
1213 offset += 2;
1214 armLIR->operands[0] = 1;
1215 } else {
1216 armLIR->operands[0] = 0;
1217 }
1218 }
1219 /* Pseudo opcodes don't consume space */
1220 }
1221
1222 /* Const values have to be word aligned */
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001223 offset = (offset + 3) & ~3;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001224
Ben Chengcec26f62010-01-15 15:29:33 -08001225 /*
1226 * Get the gap (# of u4) between the offset of chaining cell count and
1227 * the bottom of real chaining cells. If the translation has chaining
1228 * cells, the gap is guaranteed to be multiples of 4.
1229 */
1230 chainingCellGap = (offset - cUnit->chainingCellBottom->offset) >> 2;
1231
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001232 /* Add space for chain cell counts & trace description */
Ben Cheng1efc9c52009-06-08 18:25:27 -07001233 u4 chainCellOffset = offset;
Bill Buzbee89efc3d2009-07-28 11:22:22 -07001234 ArmLIR *chainCellOffsetLIR = (ArmLIR *) cUnit->chainCellOffsetLIR;
Bill Buzbee6e963e12009-06-17 16:56:19 -07001235 assert(chainCellOffsetLIR);
Ben Cheng1efc9c52009-06-08 18:25:27 -07001236 assert(chainCellOffset < 0x10000);
Bill Buzbee1465db52009-09-23 17:17:35 -07001237 assert(chainCellOffsetLIR->opCode == kArm16BitData &&
Ben Cheng1efc9c52009-06-08 18:25:27 -07001238 chainCellOffsetLIR->operands[0] == CHAIN_CELL_OFFSET_TAG);
1239
Ben Chenge80cd942009-07-17 15:54:23 -07001240 /*
1241 * Replace the CHAIN_CELL_OFFSET_TAG with the real value. If trace
1242 * profiling is enabled, subtract 4 (occupied by the counter word) from
1243 * the absolute offset as the value stored in chainCellOffsetLIR is the
1244 * delta from &chainCellOffsetLIR to &ChainCellCounts.
1245 */
1246 chainCellOffsetLIR->operands[0] =
1247 gDvmJit.profile ? (chainCellOffset - 4) : chainCellOffset;
Ben Cheng1efc9c52009-06-08 18:25:27 -07001248
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001249 offset += sizeof(chainCellCounts) + descSize;
1250
1251 assert((offset & 0x3) == 0); /* Should still be word aligned */
1252
1253 /* Set up offsets for literals */
Ben Chengba4fc8b2009-06-01 13:00:29 -07001254 cUnit->dataOffset = offset;
1255
1256 for (lir = cUnit->wordList; lir; lir = lir->next) {
1257 lir->offset = offset;
1258 offset += 4;
1259 }
1260
1261 cUnit->totalSize = offset;
1262
Ben Cheng7b133ef2010-02-04 16:15:59 -08001263 if (gDvmJit.codeCacheByteUsed + cUnit->totalSize > gDvmJit.codeCacheSize) {
Ben Chengba4fc8b2009-06-01 13:00:29 -07001264 gDvmJit.codeCacheFull = true;
1265 cUnit->baseAddr = NULL;
1266 return;
1267 }
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001268
1269 /* Allocate enough space for the code block */
1270 cUnit->codeBuffer = dvmCompilerNew(chainCellOffset, true);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001271 if (cUnit->codeBuffer == NULL) {
1272 LOGE("Code buffer allocation failure\n");
1273 cUnit->baseAddr = NULL;
1274 return;
1275 }
1276
Ben Cheng1efc9c52009-06-08 18:25:27 -07001277 bool assemblerFailure = assembleInstructions(
Ben Chengba4fc8b2009-06-01 13:00:29 -07001278 cUnit, (intptr_t) gDvmJit.codeCache + gDvmJit.codeCacheByteUsed);
1279
Ben Cheng1efc9c52009-06-08 18:25:27 -07001280 /*
1281 * Currently the only reason that can cause the assembler to fail is due to
1282 * trace length - cut it in half and retry.
1283 */
1284 if (assemblerFailure) {
1285 cUnit->halveInstCount = true;
1286 return;
1287 }
Ben Chengba4fc8b2009-06-01 13:00:29 -07001288
Ben Chengdca71432010-03-16 16:04:11 -07001289#if defined(SIGNATURE_BREAKPOINT)
1290 if (info->discardResult == false && gDvmJit.signatureBreakpoint != NULL &&
1291 chainCellOffset/4 >= gDvmJit.signatureBreakpointSize) {
1292 matchSignatureBreakpoint(cUnit, chainCellOffset/4);
1293 }
1294#endif
1295
Ben Chengccd6c012009-10-15 14:52:45 -07001296 /* Don't go all the way if the goal is just to get the verbose output */
1297 if (info->discardResult) return;
Bill Buzbee6e963e12009-06-17 16:56:19 -07001298
Ben Chengba4fc8b2009-06-01 13:00:29 -07001299 cUnit->baseAddr = (char *) gDvmJit.codeCache + gDvmJit.codeCacheByteUsed;
1300 gDvmJit.codeCacheByteUsed += offset;
1301
Ben Chengb88ec3c2010-05-17 12:50:33 -07001302 UNPROTECT_CODE_CACHE(cUnit->baseAddr, offset);
1303
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001304 /* Install the code block */
Ben Cheng1efc9c52009-06-08 18:25:27 -07001305 memcpy((char*)cUnit->baseAddr, cUnit->codeBuffer, chainCellOffset);
Ben Chengba4fc8b2009-06-01 13:00:29 -07001306 gDvmJit.numCompilations++;
1307
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001308 /* Install the chaining cell counts */
Ben Chengcec26f62010-01-15 15:29:33 -08001309 for (i=0; i< kChainingCellGap; i++) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001310 chainCellCounts.u.count[i] = cUnit->numChainingCells[i];
1311 }
Ben Chengcec26f62010-01-15 15:29:33 -08001312
1313 /* Set the gap number in the chaining cell count structure */
1314 chainCellCounts.u.count[kChainingCellGap] = chainingCellGap;
1315
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001316 memcpy((char*)cUnit->baseAddr + chainCellOffset, &chainCellCounts,
1317 sizeof(chainCellCounts));
1318
1319 /* Install the trace description */
1320 memcpy((char*)cUnit->baseAddr + chainCellOffset + sizeof(chainCellCounts),
1321 cUnit->traceDesc, descSize);
1322
1323 /* Write the literals directly into the code cache */
1324 installDataContent(cUnit);
1325
Ben Chengba4fc8b2009-06-01 13:00:29 -07001326 /* Flush dcache and invalidate the icache to maintain coherence */
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001327 cacheflush((long)cUnit->baseAddr,
Ben Chenge80cd942009-07-17 15:54:23 -07001328 (long)((char *) cUnit->baseAddr + offset), 0);
Ben Cheng978738d2010-05-13 13:45:57 -07001329 UPDATE_CODE_CACHE_PATCHES();
Bill Buzbee716f1202009-07-23 13:22:09 -07001330
Ben Chengb88ec3c2010-05-17 12:50:33 -07001331 PROTECT_CODE_CACHE(cUnit->baseAddr, offset);
1332
Bill Buzbee716f1202009-07-23 13:22:09 -07001333 /* Record code entry point and instruction set */
1334 info->codeAddress = (char*)cUnit->baseAddr + cUnit->headerSize;
Bill Buzbee716f1202009-07-23 13:22:09 -07001335 /* If applicable, mark low bit to denote thumb */
1336 if (info->instructionSet != DALVIK_JIT_ARM)
1337 info->codeAddress = (char*)info->codeAddress + 1;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001338}
1339
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001340/*
1341 * Returns the skeleton bit pattern associated with an opcode. All
1342 * variable fields are zeroed.
1343 */
1344static u4 getSkeleton(ArmOpCode op)
1345{
1346 return EncodingMap[op].skeleton;
1347}
1348
1349static u4 assembleChainingBranch(int branchOffset, bool thumbTarget)
Ben Cheng38329f52009-07-07 14:19:20 -07001350{
1351 u4 thumb1, thumb2;
1352
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001353 if (!thumbTarget) {
1354 thumb1 = (getSkeleton(kThumbBlx1) | ((branchOffset>>12) & 0x7ff));
1355 thumb2 = (getSkeleton(kThumbBlx2) | ((branchOffset>> 1) & 0x7ff));
1356 } else if ((branchOffset < -2048) | (branchOffset > 2046)) {
1357 thumb1 = (getSkeleton(kThumbBl1) | ((branchOffset>>12) & 0x7ff));
1358 thumb2 = (getSkeleton(kThumbBl2) | ((branchOffset>> 1) & 0x7ff));
Ben Cheng38329f52009-07-07 14:19:20 -07001359 } else {
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001360 thumb1 = (getSkeleton(kThumbBUncond) | ((branchOffset>> 1) & 0x7ff));
1361 thumb2 = getSkeleton(kThumbOrr); /* nop -> or r0, r0 */
Ben Cheng38329f52009-07-07 14:19:20 -07001362 }
1363
1364 return thumb2<<16 | thumb1;
1365}
1366
Ben Chengba4fc8b2009-06-01 13:00:29 -07001367/*
1368 * Perform translation chain operation.
1369 * For ARM, we'll use a pair of thumb instructions to generate
1370 * an unconditional chaining branch of up to 4MB in distance.
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001371 * Use a BL, because the generic "interpret" translation needs
1372 * the link register to find the dalvik pc of teh target.
Ben Chengba4fc8b2009-06-01 13:00:29 -07001373 * 111HHooooooooooo
1374 * Where HH is 10 for the 1st inst, and 11 for the second and
1375 * the "o" field is each instruction's 11-bit contribution to the
1376 * 22-bit branch offset.
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001377 * If the target is nearby, use a single-instruction bl.
1378 * If one or more threads is suspended, don't chain.
Ben Chengba4fc8b2009-06-01 13:00:29 -07001379 */
1380void* dvmJitChain(void* tgtAddr, u4* branchAddr)
1381{
1382 int baseAddr = (u4) branchAddr + 4;
1383 int branchOffset = (int) tgtAddr - baseAddr;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001384 u4 newInst;
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001385 bool thumbTarget;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001386
Ben Cheng6999d842010-01-26 16:46:15 -08001387 /*
1388 * Only chain translations when there is no urge to ask all threads to
1389 * suspend themselves via the interpreter.
1390 */
1391 if ((gDvmJit.pProfTable != NULL) && (gDvm.sumThreadSuspendCount == 0) &&
1392 (gDvmJit.codeCacheFull == false)) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001393 assert((branchOffset >= -(1<<22)) && (branchOffset <= ((1<<22)-2)));
Ben Chengba4fc8b2009-06-01 13:00:29 -07001394
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001395 gDvmJit.translationChains++;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001396
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001397 COMPILER_TRACE_CHAINING(
1398 LOGD("Jit Runtime: chaining 0x%x to 0x%x\n",
1399 (int) branchAddr, (int) tgtAddr & -2));
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001400
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001401 /*
1402 * NOTE: normally, all translations are Thumb[2] mode, with
1403 * a single exception: the default TEMPLATE_INTERPRET
1404 * pseudo-translation. If the need ever arises to
1405 * mix Arm & Thumb[2] translations, the following code should be
1406 * generalized.
1407 */
Bill Buzbeebd047242010-05-13 13:02:53 -07001408 thumbTarget = (tgtAddr != dvmCompilerGetInterpretTemplate());
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001409
1410 newInst = assembleChainingBranch(branchOffset, thumbTarget);
Ben Cheng38329f52009-07-07 14:19:20 -07001411
Bill Buzbeebd047242010-05-13 13:02:53 -07001412 /*
1413 * The second half-word instruction of the chaining cell must
1414 * either be a nop (which represents initial state), or is the
1415 * same exact branch halfword that we are trying to install.
1416 */
1417 assert( ((*branchAddr >> 16) == getSkeleton(kThumbOrr)) ||
1418 ((*branchAddr >> 16) == (newInst >> 16)));
1419
Ben Chengb88ec3c2010-05-17 12:50:33 -07001420 UNPROTECT_CODE_CACHE(branchAddr, sizeof(*branchAddr));
1421
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001422 *branchAddr = newInst;
1423 cacheflush((long)branchAddr, (long)branchAddr + 4, 0);
Ben Cheng978738d2010-05-13 13:45:57 -07001424 UPDATE_CODE_CACHE_PATCHES();
Ben Chengb88ec3c2010-05-17 12:50:33 -07001425
1426 PROTECT_CODE_CACHE(branchAddr, sizeof(*branchAddr));
1427
Ben Cheng6999d842010-01-26 16:46:15 -08001428 gDvmJit.hasNewChain = true;
Ben Chengba4fc8b2009-06-01 13:00:29 -07001429 }
1430
Ben Chengba4fc8b2009-06-01 13:00:29 -07001431 return tgtAddr;
1432}
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001433
Ben Chengb88ec3c2010-05-17 12:50:33 -07001434#if !defined(WITH_SELF_VERIFICATION)
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001435/*
Ben Cheng6999d842010-01-26 16:46:15 -08001436 * Attempt to enqueue a work order to patch an inline cache for a predicted
1437 * chaining cell for virtual/interface calls.
1438 */
Ben Chengb88ec3c2010-05-17 12:50:33 -07001439static void inlineCachePatchEnqueue(PredictedChainingCell *cellAddr,
Ben Cheng452efba2010-04-30 15:14:00 -07001440 PredictedChainingCell *newContent)
Ben Cheng6999d842010-01-26 16:46:15 -08001441{
Ben Cheng452efba2010-04-30 15:14:00 -07001442 /*
1443 * Make sure only one thread gets here since updating the cell (ie fast
1444 * path and queueing the request (ie the queued path) have to be done
1445 * in an atomic fashion.
1446 */
Ben Cheng6999d842010-01-26 16:46:15 -08001447 dvmLockMutex(&gDvmJit.compilerICPatchLock);
1448
Ben Cheng452efba2010-04-30 15:14:00 -07001449 /* Fast path for uninitialized chaining cell */
Ben Cheng6999d842010-01-26 16:46:15 -08001450 if (cellAddr->clazz == NULL &&
1451 cellAddr->branch == PREDICTED_CHAIN_BX_PAIR_INIT) {
Ben Chengb88ec3c2010-05-17 12:50:33 -07001452
1453 UNPROTECT_CODE_CACHE(cellAddr, sizeof(*cellAddr));
1454
Ben Cheng452efba2010-04-30 15:14:00 -07001455 cellAddr->method = newContent->method;
1456 cellAddr->branch = newContent->branch;
Ben Cheng6999d842010-01-26 16:46:15 -08001457 /*
1458 * The update order matters - make sure clazz is updated last since it
1459 * will bring the uninitialized chaining cell to life.
1460 */
Andy McFadden6e10b9a2010-06-14 15:24:39 -07001461 ANDROID_MEMBAR_FULL();
Ben Cheng6999d842010-01-26 16:46:15 -08001462 cellAddr->clazz = newContent->clazz;
1463 cacheflush((intptr_t) cellAddr, (intptr_t) (cellAddr+1), 0);
Ben Cheng978738d2010-05-13 13:45:57 -07001464 UPDATE_CODE_CACHE_PATCHES();
Ben Chengb88ec3c2010-05-17 12:50:33 -07001465
1466 PROTECT_CODE_CACHE(cellAddr, sizeof(*cellAddr));
1467
Ben Cheng452efba2010-04-30 15:14:00 -07001468#if defined(WITH_JIT_TUNING)
Ben Chengb88ec3c2010-05-17 12:50:33 -07001469 gDvmJit.icPatchInit++;
Ben Cheng452efba2010-04-30 15:14:00 -07001470#endif
Ben Chengb88ec3c2010-05-17 12:50:33 -07001471 /* Check if this is a frequently missed clazz */
1472 } else if (cellAddr->stagedClazz != newContent->clazz) {
1473 /* Not proven to be frequent yet - build up the filter cache */
1474 UNPROTECT_CODE_CACHE(cellAddr, sizeof(*cellAddr));
1475
1476 cellAddr->stagedClazz = newContent->clazz;
1477
1478 UPDATE_CODE_CACHE_PATCHES();
1479 PROTECT_CODE_CACHE(cellAddr, sizeof(*cellAddr));
1480
1481#if defined(WITH_JIT_TUNING)
1482 gDvmJit.icPatchRejected++;
1483#endif
Ben Cheng452efba2010-04-30 15:14:00 -07001484 /*
Ben Chengb88ec3c2010-05-17 12:50:33 -07001485 * Different classes but same method implementation - it is safe to just
1486 * patch the class value without the need to stop the world.
Ben Cheng452efba2010-04-30 15:14:00 -07001487 */
Ben Chengb88ec3c2010-05-17 12:50:33 -07001488 } else if (cellAddr->method == newContent->method) {
1489 UNPROTECT_CODE_CACHE(cellAddr, sizeof(*cellAddr));
1490
1491 cellAddr->clazz = newContent->clazz;
1492 /* No need to flush the cache here since the branch is not patched */
1493 UPDATE_CODE_CACHE_PATCHES();
1494
1495 PROTECT_CODE_CACHE(cellAddr, sizeof(*cellAddr));
1496
1497#if defined(WITH_JIT_TUNING)
1498 gDvmJit.icPatchLockFree++;
1499#endif
1500 /*
1501 * Cannot patch the chaining cell inline - queue it until the next safe
1502 * point.
1503 */
1504 } else if (gDvmJit.compilerICPatchIndex < COMPILER_IC_PATCH_QUEUE_SIZE) {
Ben Cheng6999d842010-01-26 16:46:15 -08001505 int index = gDvmJit.compilerICPatchIndex++;
1506 gDvmJit.compilerICPatchQueue[index].cellAddr = cellAddr;
1507 gDvmJit.compilerICPatchQueue[index].cellContent = *newContent;
Ben Cheng452efba2010-04-30 15:14:00 -07001508#if defined(WITH_JIT_TUNING)
1509 gDvmJit.icPatchQueued++;
1510#endif
Ben Chengb88ec3c2010-05-17 12:50:33 -07001511 } else {
Ben Cheng452efba2010-04-30 15:14:00 -07001512 /* Queue is full - just drop this patch request */
Ben Cheng452efba2010-04-30 15:14:00 -07001513#if defined(WITH_JIT_TUNING)
1514 gDvmJit.icPatchDropped++;
1515#endif
Ben Cheng6999d842010-01-26 16:46:15 -08001516 }
1517
1518 dvmUnlockMutex(&gDvmJit.compilerICPatchLock);
Ben Cheng6999d842010-01-26 16:46:15 -08001519}
Carl Shapiroe3c01da2010-05-20 22:54:18 -07001520#endif
Ben Cheng6999d842010-01-26 16:46:15 -08001521
1522/*
Ben Cheng38329f52009-07-07 14:19:20 -07001523 * This method is called from the invoke templates for virtual and interface
1524 * methods to speculatively setup a chain to the callee. The templates are
1525 * written in assembly and have setup method, cell, and clazz at r0, r2, and
1526 * r3 respectively, so there is a unused argument in the list. Upon return one
1527 * of the following three results may happen:
1528 * 1) Chain is not setup because the callee is native. Reset the rechain
1529 * count to a big number so that it will take a long time before the next
1530 * rechain attempt to happen.
1531 * 2) Chain is not setup because the callee has not been created yet. Reset
1532 * the rechain count to a small number and retry in the near future.
1533 * 3) Ask all other threads to stop before patching this chaining cell.
1534 * This is required because another thread may have passed the class check
1535 * but hasn't reached the chaining cell yet to follow the chain. If we
1536 * patch the content before halting the other thread, there could be a
1537 * small window for race conditions to happen that it may follow the new
1538 * but wrong chain to invoke a different method.
1539 */
1540const Method *dvmJitToPatchPredictedChain(const Method *method,
Ben Chengb88ec3c2010-05-17 12:50:33 -07001541 InterpState *interpState,
Ben Cheng38329f52009-07-07 14:19:20 -07001542 PredictedChainingCell *cell,
1543 const ClassObject *clazz)
1544{
Ben Chengb88ec3c2010-05-17 12:50:33 -07001545 int newRechainCount = PREDICTED_CHAIN_COUNTER_RECHAIN;
Jeff Hao97319a82009-08-12 16:57:15 -07001546#if defined(WITH_SELF_VERIFICATION)
Ben Chengb88ec3c2010-05-17 12:50:33 -07001547 newRechainCount = PREDICTED_CHAIN_COUNTER_AVOID;
Jeff Hao97319a82009-08-12 16:57:15 -07001548 goto done;
1549#else
Ben Cheng38329f52009-07-07 14:19:20 -07001550 if (dvmIsNativeMethod(method)) {
Ben Chengb88ec3c2010-05-17 12:50:33 -07001551 UNPROTECT_CODE_CACHE(cell, sizeof(*cell));
1552
1553 /*
1554 * Put a non-zero/bogus value in the clazz field so that it won't
1555 * trigger immediate patching and will continue to fail to match with
1556 * a real clazz pointer.
1557 */
1558 cell->clazz = (void *) PREDICTED_CHAIN_FAKE_CLAZZ;
1559
Ben Cheng978738d2010-05-13 13:45:57 -07001560 UPDATE_CODE_CACHE_PATCHES();
Ben Chengb88ec3c2010-05-17 12:50:33 -07001561 PROTECT_CODE_CACHE(cell, sizeof(*cell));
Ben Cheng38329f52009-07-07 14:19:20 -07001562 goto done;
1563 }
1564 int tgtAddr = (int) dvmJitGetCodeAddr(method->insns);
1565
1566 /*
1567 * Compilation not made yet for the callee. Reset the counter to a small
1568 * value and come back to check soon.
1569 */
Bill Buzbeebd047242010-05-13 13:02:53 -07001570 if ((tgtAddr == 0) ||
1571 ((void*)tgtAddr == dvmCompilerGetInterpretTemplate())) {
Ben Cheng38329f52009-07-07 14:19:20 -07001572 COMPILER_TRACE_CHAINING(
Ben Chenga8e64a72009-10-20 13:01:36 -07001573 LOGD("Jit Runtime: predicted chain %p to method %s%s delayed",
1574 cell, method->clazz->descriptor, method->name));
Ben Cheng38329f52009-07-07 14:19:20 -07001575 goto done;
1576 }
1577
Ben Cheng6999d842010-01-26 16:46:15 -08001578 PredictedChainingCell newCell;
Ben Chenga8e64a72009-10-20 13:01:36 -07001579
Ben Chengb88ec3c2010-05-17 12:50:33 -07001580 if (cell->clazz == NULL) {
1581 newRechainCount = interpState->icRechainCount;
1582 }
Ben Cheng38329f52009-07-07 14:19:20 -07001583
1584 int baseAddr = (int) cell + 4; // PC is cur_addr + 4
1585 int branchOffset = tgtAddr - baseAddr;
1586
Ben Cheng6999d842010-01-26 16:46:15 -08001587 newCell.branch = assembleChainingBranch(branchOffset, true);
1588 newCell.clazz = clazz;
1589 newCell.method = method;
Ben Cheng38329f52009-07-07 14:19:20 -07001590
Ben Chenga8e64a72009-10-20 13:01:36 -07001591 /*
Ben Cheng6999d842010-01-26 16:46:15 -08001592 * Enter the work order to the queue and the chaining cell will be patched
1593 * the next time a safe point is entered.
Ben Cheng60c24f42010-01-04 12:29:56 -08001594 *
Ben Cheng6999d842010-01-26 16:46:15 -08001595 * If the enqueuing fails reset the rechain count to a normal value so that
1596 * it won't get indefinitely delayed.
Ben Cheng60c24f42010-01-04 12:29:56 -08001597 */
Ben Chengb88ec3c2010-05-17 12:50:33 -07001598 inlineCachePatchEnqueue(cell, &newCell);
Ben Cheng60c24f42010-01-04 12:29:56 -08001599#endif
1600done:
Ben Chengb88ec3c2010-05-17 12:50:33 -07001601 interpState->icRechainCount = newRechainCount;
Ben Cheng60c24f42010-01-04 12:29:56 -08001602 return method;
1603}
1604
1605/*
1606 * Patch the inline cache content based on the content passed from the work
1607 * order.
1608 */
Ben Cheng6999d842010-01-26 16:46:15 -08001609void dvmCompilerPatchInlineCache(void)
Ben Cheng60c24f42010-01-04 12:29:56 -08001610{
Ben Cheng6999d842010-01-26 16:46:15 -08001611 int i;
1612 PredictedChainingCell *minAddr, *maxAddr;
Ben Cheng60c24f42010-01-04 12:29:56 -08001613
Ben Cheng6999d842010-01-26 16:46:15 -08001614 /* Nothing to be done */
1615 if (gDvmJit.compilerICPatchIndex == 0) return;
Ben Cheng60c24f42010-01-04 12:29:56 -08001616
Ben Cheng6999d842010-01-26 16:46:15 -08001617 /*
1618 * Since all threads are already stopped we don't really need to acquire
1619 * the lock. But race condition can be easily introduced in the future w/o
1620 * paying attention so we still acquire the lock here.
1621 */
1622 dvmLockMutex(&gDvmJit.compilerICPatchLock);
Ben Cheng7a0bcd02010-01-22 16:45:45 -08001623
Ben Chengb88ec3c2010-05-17 12:50:33 -07001624 UNPROTECT_CODE_CACHE(gDvmJit.codeCache, gDvmJit.codeCacheByteUsed);
1625
Ben Cheng6999d842010-01-26 16:46:15 -08001626 //LOGD("Number of IC patch work orders: %d", gDvmJit.compilerICPatchIndex);
Ben Cheng60c24f42010-01-04 12:29:56 -08001627
Ben Cheng6999d842010-01-26 16:46:15 -08001628 /* Initialize the min/max address range */
1629 minAddr = (PredictedChainingCell *)
Ben Cheng7b133ef2010-02-04 16:15:59 -08001630 ((char *) gDvmJit.codeCache + gDvmJit.codeCacheSize);
Ben Cheng6999d842010-01-26 16:46:15 -08001631 maxAddr = (PredictedChainingCell *) gDvmJit.codeCache;
Ben Cheng60c24f42010-01-04 12:29:56 -08001632
Ben Cheng6999d842010-01-26 16:46:15 -08001633 for (i = 0; i < gDvmJit.compilerICPatchIndex; i++) {
1634 PredictedChainingCell *cellAddr =
1635 gDvmJit.compilerICPatchQueue[i].cellAddr;
1636 PredictedChainingCell *cellContent =
1637 &gDvmJit.compilerICPatchQueue[i].cellContent;
Ben Cheng38329f52009-07-07 14:19:20 -07001638
Ben Chengb88ec3c2010-05-17 12:50:33 -07001639 COMPILER_TRACE_CHAINING(
1640 LOGD("Jit Runtime: predicted chain %p from %s to %s (%s) "
1641 "patched",
1642 cellAddr,
1643 cellAddr->clazz->descriptor,
1644 cellContent->clazz->descriptor,
1645 cellContent->method->name));
Ben Cheng38329f52009-07-07 14:19:20 -07001646
Ben Cheng6999d842010-01-26 16:46:15 -08001647 /* Patch the chaining cell */
1648 *cellAddr = *cellContent;
1649 minAddr = (cellAddr < minAddr) ? cellAddr : minAddr;
1650 maxAddr = (cellAddr > maxAddr) ? cellAddr : maxAddr;
1651 }
1652
1653 /* Then synchronize the I/D cache */
1654 cacheflush((long) minAddr, (long) (maxAddr+1), 0);
Ben Cheng978738d2010-05-13 13:45:57 -07001655 UPDATE_CODE_CACHE_PATCHES();
Ben Cheng6999d842010-01-26 16:46:15 -08001656
Ben Chengb88ec3c2010-05-17 12:50:33 -07001657 PROTECT_CODE_CACHE(gDvmJit.codeCache, gDvmJit.codeCacheByteUsed);
1658
Ben Cheng6999d842010-01-26 16:46:15 -08001659 gDvmJit.compilerICPatchIndex = 0;
1660 dvmUnlockMutex(&gDvmJit.compilerICPatchLock);
Ben Cheng38329f52009-07-07 14:19:20 -07001661}
1662
1663/*
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001664 * Unchain a trace given the starting address of the translation
1665 * in the code cache. Refer to the diagram in dvmCompilerAssembleLIR.
1666 * Returns the address following the last cell unchained. Note that
1667 * the incoming codeAddr is a thumb code address, and therefore has
1668 * the low bit set.
1669 */
1670u4* dvmJitUnchain(void* codeAddr)
1671{
1672 u2* pChainCellOffset = (u2*)((char*)codeAddr - 3);
1673 u2 chainCellOffset = *pChainCellOffset;
1674 ChainCellCounts *pChainCellCounts =
Ben Chenge80cd942009-07-17 15:54:23 -07001675 (ChainCellCounts*)((char*)codeAddr + chainCellOffset - 3);
Ben Cheng38329f52009-07-07 14:19:20 -07001676 int cellSize;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001677 u4* pChainCells;
1678 u4* pStart;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001679 u4 newInst;
1680 int i,j;
Ben Cheng38329f52009-07-07 14:19:20 -07001681 PredictedChainingCell *predChainCell;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001682
1683 /* Get total count of chain cells */
Ben Chengcec26f62010-01-15 15:29:33 -08001684 for (i = 0, cellSize = 0; i < kChainingCellGap; i++) {
Bill Buzbee1465db52009-09-23 17:17:35 -07001685 if (i != kChainingCellInvokePredicted) {
Bill Buzbeebd047242010-05-13 13:02:53 -07001686 cellSize += pChainCellCounts->u.count[i] * (CHAIN_CELL_NORMAL_SIZE >> 2);
Ben Cheng38329f52009-07-07 14:19:20 -07001687 } else {
Bill Buzbeebd047242010-05-13 13:02:53 -07001688 cellSize += pChainCellCounts->u.count[i] *
1689 (CHAIN_CELL_PREDICTED_SIZE >> 2);
Ben Cheng38329f52009-07-07 14:19:20 -07001690 }
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001691 }
1692
Ben Chengcec26f62010-01-15 15:29:33 -08001693 if (cellSize == 0)
1694 return (u4 *) pChainCellCounts;
1695
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001696 /* Locate the beginning of the chain cell region */
Ben Chengcec26f62010-01-15 15:29:33 -08001697 pStart = pChainCells = ((u4 *) pChainCellCounts) - cellSize -
1698 pChainCellCounts->u.count[kChainingCellGap];
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001699
1700 /* The cells are sorted in order - walk through them and reset */
Ben Chengcec26f62010-01-15 15:29:33 -08001701 for (i = 0; i < kChainingCellGap; i++) {
Bill Buzbeebd047242010-05-13 13:02:53 -07001702 int elemSize = CHAIN_CELL_NORMAL_SIZE >> 2; /* In 32-bit words */
Bill Buzbee1465db52009-09-23 17:17:35 -07001703 if (i == kChainingCellInvokePredicted) {
Bill Buzbeebd047242010-05-13 13:02:53 -07001704 elemSize = CHAIN_CELL_PREDICTED_SIZE >> 2;
Ben Cheng38329f52009-07-07 14:19:20 -07001705 }
1706
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001707 for (j = 0; j < pChainCellCounts->u.count[i]; j++) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001708 switch(i) {
Bill Buzbee1465db52009-09-23 17:17:35 -07001709 case kChainingCellNormal:
Bill Buzbee1465db52009-09-23 17:17:35 -07001710 case kChainingCellHot:
1711 case kChainingCellInvokeSingleton:
Bill Buzbeebd047242010-05-13 13:02:53 -07001712 case kChainingCellBackwardBranch:
1713 /*
1714 * Replace the 1st half-word of the cell with an
1715 * unconditional branch, leaving the 2nd half-word
1716 * untouched. This avoids problems with a thread
1717 * that is suspended between the two halves when
1718 * this unchaining takes place.
1719 */
1720 newInst = *pChainCells;
1721 newInst &= 0xFFFF0000;
1722 newInst |= getSkeleton(kThumbBUncond); /* b offset is 0 */
1723 *pChainCells = newInst;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001724 break;
Bill Buzbee1465db52009-09-23 17:17:35 -07001725 case kChainingCellInvokePredicted:
Ben Cheng38329f52009-07-07 14:19:20 -07001726 predChainCell = (PredictedChainingCell *) pChainCells;
Ben Cheng7a0bcd02010-01-22 16:45:45 -08001727 /*
1728 * There could be a race on another mutator thread to use
1729 * this particular predicted cell and the check has passed
1730 * the clazz comparison. So we cannot safely wipe the
1731 * method and branch but it is safe to clear the clazz,
1732 * which serves as the key.
1733 */
Ben Cheng38329f52009-07-07 14:19:20 -07001734 predChainCell->clazz = PREDICTED_CHAIN_CLAZZ_INIT;
Ben Cheng38329f52009-07-07 14:19:20 -07001735 break;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001736 default:
Ben Chengbb0dce52009-11-03 16:19:11 -08001737 LOGE("Unexpected chaining type: %d", i);
Bill Buzbeefc519dc2010-03-06 23:30:57 -08001738 dvmAbort(); // dvmAbort OK here - can't safely recover
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001739 }
Ben Cheng38329f52009-07-07 14:19:20 -07001740 COMPILER_TRACE_CHAINING(
1741 LOGD("Jit Runtime: unchaining 0x%x", (int)pChainCells));
Ben Cheng38329f52009-07-07 14:19:20 -07001742 pChainCells += elemSize; /* Advance by a fixed number of words */
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001743 }
1744 }
1745 return pChainCells;
1746}
1747
1748/* Unchain all translation in the cache. */
1749void dvmJitUnchainAll()
1750{
1751 u4* lowAddress = NULL;
1752 u4* highAddress = NULL;
1753 unsigned int i;
1754 if (gDvmJit.pJitEntryTable != NULL) {
1755 COMPILER_TRACE_CHAINING(LOGD("Jit Runtime: unchaining all"));
1756 dvmLockMutex(&gDvmJit.tableLock);
Ben Chengb88ec3c2010-05-17 12:50:33 -07001757
1758 UNPROTECT_CODE_CACHE(gDvmJit.codeCache, gDvmJit.codeCacheByteUsed);
1759
Bill Buzbee27176222009-06-09 09:20:16 -07001760 for (i = 0; i < gDvmJit.jitTableSize; i++) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001761 if (gDvmJit.pJitEntryTable[i].dPC &&
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001762 gDvmJit.pJitEntryTable[i].codeAddress &&
1763 (gDvmJit.pJitEntryTable[i].codeAddress !=
Bill Buzbeebd047242010-05-13 13:02:53 -07001764 dvmCompilerGetInterpretTemplate())) {
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001765 u4* lastAddress;
1766 lastAddress =
1767 dvmJitUnchain(gDvmJit.pJitEntryTable[i].codeAddress);
1768 if (lowAddress == NULL ||
1769 (u4*)gDvmJit.pJitEntryTable[i].codeAddress < lowAddress)
1770 lowAddress = lastAddress;
1771 if (lastAddress > highAddress)
1772 highAddress = lastAddress;
1773 }
1774 }
1775 cacheflush((long)lowAddress, (long)highAddress, 0);
Ben Cheng978738d2010-05-13 13:45:57 -07001776 UPDATE_CODE_CACHE_PATCHES();
Ben Chengb88ec3c2010-05-17 12:50:33 -07001777
1778 PROTECT_CODE_CACHE(gDvmJit.codeCache, gDvmJit.codeCacheByteUsed);
1779
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001780 dvmUnlockMutex(&gDvmJit.tableLock);
Ben Cheng7a0bcd02010-01-22 16:45:45 -08001781 gDvmJit.translationChains = 0;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001782 }
Ben Cheng6999d842010-01-26 16:46:15 -08001783 gDvmJit.hasNewChain = false;
Bill Buzbee46cd5b62009-06-05 15:36:06 -07001784}
Bill Buzbee716f1202009-07-23 13:22:09 -07001785
1786typedef struct jitProfileAddrToLine {
1787 u4 lineNum;
1788 u4 bytecodeOffset;
1789} jitProfileAddrToLine;
1790
1791
1792/* Callback function to track the bytecode offset/line number relationiship */
1793static int addrToLineCb (void *cnxt, u4 bytecodeOffset, u4 lineNum)
1794{
1795 jitProfileAddrToLine *addrToLine = (jitProfileAddrToLine *) cnxt;
1796
1797 /* Best match so far for this offset */
1798 if (addrToLine->bytecodeOffset >= bytecodeOffset) {
1799 addrToLine->lineNum = lineNum;
1800 }
1801 return 0;
1802}
1803
Ben Chengb88ec3c2010-05-17 12:50:33 -07001804static char *getTraceBase(const JitEntry *p)
Bill Buzbee716f1202009-07-23 13:22:09 -07001805{
1806 return (char*)p->codeAddress -
1807 (6 + (p->u.info.instructionSet == DALVIK_JIT_ARM ? 0 : 1));
1808}
1809
1810/* Dumps profile info for a single trace */
Ben Cheng88a0f972010-02-24 15:00:40 -08001811static int dumpTraceProfile(JitEntry *p, bool silent, bool reset,
1812 unsigned long sum)
Bill Buzbee716f1202009-07-23 13:22:09 -07001813{
1814 ChainCellCounts* pCellCounts;
1815 char* traceBase;
1816 u4* pExecutionCount;
Ben Cheng88a0f972010-02-24 15:00:40 -08001817 u4 executionCount;
Bill Buzbee716f1202009-07-23 13:22:09 -07001818 u2* pCellOffset;
1819 JitTraceDescription *desc;
1820 const Method* method;
1821
1822 traceBase = getTraceBase(p);
1823
1824 if (p->codeAddress == NULL) {
Ben Cheng88a0f972010-02-24 15:00:40 -08001825 if (!silent)
1826 LOGD("TRACEPROFILE 0x%08x 0 NULL 0 0", (int)traceBase);
Bill Buzbee716f1202009-07-23 13:22:09 -07001827 return 0;
1828 }
Bill Buzbeebd047242010-05-13 13:02:53 -07001829 if (p->codeAddress == dvmCompilerGetInterpretTemplate()) {
Ben Cheng88a0f972010-02-24 15:00:40 -08001830 if (!silent)
1831 LOGD("TRACEPROFILE 0x%08x 0 INTERPRET_ONLY 0 0", (int)traceBase);
Bill Buzbee9a8c75a2009-11-08 14:31:20 -08001832 return 0;
1833 }
Bill Buzbee716f1202009-07-23 13:22:09 -07001834
1835 pExecutionCount = (u4*) (traceBase);
Ben Cheng88a0f972010-02-24 15:00:40 -08001836 executionCount = *pExecutionCount;
1837 if (reset) {
1838 *pExecutionCount =0;
1839 }
1840 if (silent) {
1841 return executionCount;
1842 }
Bill Buzbee716f1202009-07-23 13:22:09 -07001843 pCellOffset = (u2*) (traceBase + 4);
1844 pCellCounts = (ChainCellCounts*) ((char *)pCellOffset + *pCellOffset);
1845 desc = (JitTraceDescription*) ((char*)pCellCounts + sizeof(*pCellCounts));
1846 method = desc->method;
1847 char *methodDesc = dexProtoCopyMethodDescriptor(&method->prototype);
1848 jitProfileAddrToLine addrToLine = {0, desc->trace[0].frag.startOffset};
1849
1850 /*
1851 * We may end up decoding the debug information for the same method
1852 * multiple times, but the tradeoff is we don't need to allocate extra
1853 * space to store the addr/line mapping. Since this is a debugging feature
1854 * and done infrequently so the slower but simpler mechanism should work
1855 * just fine.
1856 */
1857 dexDecodeDebugInfo(method->clazz->pDvmDex->pDexFile,
1858 dvmGetMethodCode(method),
1859 method->clazz->descriptor,
1860 method->prototype.protoIdx,
1861 method->accessFlags,
1862 addrToLineCb, NULL, &addrToLine);
1863
Ben Cheng88a0f972010-02-24 15:00:40 -08001864 LOGD("TRACEPROFILE 0x%08x % 10d %5.2f%% [%#x(+%d), %d] %s%s;%s",
Bill Buzbee716f1202009-07-23 13:22:09 -07001865 (int)traceBase,
Ben Cheng88a0f972010-02-24 15:00:40 -08001866 executionCount,
1867 ((float ) executionCount) / sum * 100.0,
Bill Buzbee716f1202009-07-23 13:22:09 -07001868 desc->trace[0].frag.startOffset,
1869 desc->trace[0].frag.numInsts,
1870 addrToLine.lineNum,
1871 method->clazz->descriptor, method->name, methodDesc);
1872 free(methodDesc);
1873
Ben Cheng88a0f972010-02-24 15:00:40 -08001874 return executionCount;
Bill Buzbee716f1202009-07-23 13:22:09 -07001875}
1876
Ben Chengccd6c012009-10-15 14:52:45 -07001877/* Create a copy of the trace descriptor of an existing compilation */
Ben Cheng88a0f972010-02-24 15:00:40 -08001878JitTraceDescription *dvmCopyTraceDescriptor(const u2 *pc,
1879 const JitEntry *knownEntry)
Ben Chengccd6c012009-10-15 14:52:45 -07001880{
Ben Cheng88a0f972010-02-24 15:00:40 -08001881 const JitEntry *jitEntry = knownEntry ? knownEntry : dvmFindJitEntry(pc);
Ben Chengccd6c012009-10-15 14:52:45 -07001882 if (jitEntry == NULL) return NULL;
1883
1884 /* Find out the startint point */
1885 char *traceBase = getTraceBase(jitEntry);
1886
1887 /* Then find out the starting point of the chaining cell */
1888 u2 *pCellOffset = (u2*) (traceBase + 4);
1889 ChainCellCounts *pCellCounts =
1890 (ChainCellCounts*) ((char *)pCellOffset + *pCellOffset);
1891
1892 /* From there we can find out the starting point of the trace descriptor */
1893 JitTraceDescription *desc =
1894 (JitTraceDescription*) ((char*)pCellCounts + sizeof(*pCellCounts));
1895
1896 /* Now make a copy and return */
1897 int descSize = jitTraceDescriptionSize(desc);
1898 JitTraceDescription *newCopy = (JitTraceDescription *) malloc(descSize);
1899 memcpy(newCopy, desc, descSize);
1900 return newCopy;
1901}
1902
Bill Buzbee716f1202009-07-23 13:22:09 -07001903/* Handy function to retrieve the profile count */
1904static inline int getProfileCount(const JitEntry *entry)
1905{
Ben Chengb88ec3c2010-05-17 12:50:33 -07001906 if (entry->dPC == 0 || entry->codeAddress == 0 ||
1907 entry->codeAddress == dvmCompilerGetInterpretTemplate())
Bill Buzbee716f1202009-07-23 13:22:09 -07001908 return 0;
Ben Chengb88ec3c2010-05-17 12:50:33 -07001909
Bill Buzbee716f1202009-07-23 13:22:09 -07001910 u4 *pExecutionCount = (u4 *) getTraceBase(entry);
1911
1912 return *pExecutionCount;
1913}
1914
1915
1916/* qsort callback function */
1917static int sortTraceProfileCount(const void *entry1, const void *entry2)
1918{
1919 const JitEntry *jitEntry1 = entry1;
1920 const JitEntry *jitEntry2 = entry2;
1921
1922 int count1 = getProfileCount(jitEntry1);
1923 int count2 = getProfileCount(jitEntry2);
1924 return (count1 == count2) ? 0 : ((count1 > count2) ? -1 : 1);
1925}
1926
1927/* Sort the trace profile counts and dump them */
1928void dvmCompilerSortAndPrintTraceProfiles()
1929{
1930 JitEntry *sortedEntries;
1931 int numTraces = 0;
Ben Cheng88a0f972010-02-24 15:00:40 -08001932 unsigned long sum = 0;
Bill Buzbee716f1202009-07-23 13:22:09 -07001933 unsigned int i;
1934
1935 /* Make sure that the table is not changing */
1936 dvmLockMutex(&gDvmJit.tableLock);
1937
1938 /* Sort the entries by descending order */
1939 sortedEntries = malloc(sizeof(JitEntry) * gDvmJit.jitTableSize);
1940 if (sortedEntries == NULL)
1941 goto done;
1942 memcpy(sortedEntries, gDvmJit.pJitEntryTable,
1943 sizeof(JitEntry) * gDvmJit.jitTableSize);
1944 qsort(sortedEntries, gDvmJit.jitTableSize, sizeof(JitEntry),
1945 sortTraceProfileCount);
1946
Ben Cheng88a0f972010-02-24 15:00:40 -08001947 /* Analyze the sorted entries */
Bill Buzbee716f1202009-07-23 13:22:09 -07001948 for (i=0; i < gDvmJit.jitTableSize; i++) {
1949 if (sortedEntries[i].dPC != 0) {
Ben Cheng88a0f972010-02-24 15:00:40 -08001950 sum += dumpTraceProfile(&sortedEntries[i],
1951 true /* silent */,
1952 false /* reset */,
1953 0);
Bill Buzbee716f1202009-07-23 13:22:09 -07001954 numTraces++;
1955 }
1956 }
1957 if (numTraces == 0)
1958 numTraces = 1;
Ben Cheng88a0f972010-02-24 15:00:40 -08001959 if (sum == 0) {
1960 sum = 1;
1961 }
1962
1963 LOGD("JIT: Average execution count -> %d",(int)(sum / numTraces));
1964
1965 /* Dump the sorted entries. The count of each trace will be reset to 0. */
1966 for (i=0; i < gDvmJit.jitTableSize; i++) {
1967 if (sortedEntries[i].dPC != 0) {
1968 dumpTraceProfile(&sortedEntries[i],
1969 false /* silent */,
1970 true /* reset */,
1971 sum);
1972 }
1973 }
1974
1975 for (i=0; i < gDvmJit.jitTableSize && i < 10; i++) {
Ben Chengb88ec3c2010-05-17 12:50:33 -07001976 /* Stip interpreter stubs */
1977 if (sortedEntries[i].codeAddress == dvmCompilerGetInterpretTemplate()) {
1978 continue;
1979 }
Ben Cheng88a0f972010-02-24 15:00:40 -08001980 JitTraceDescription* desc =
1981 dvmCopyTraceDescriptor(NULL, &sortedEntries[i]);
1982 dvmCompilerWorkEnqueue(sortedEntries[i].dPC,
1983 kWorkOrderTraceDebug, desc);
1984 }
Bill Buzbee716f1202009-07-23 13:22:09 -07001985
1986 free(sortedEntries);
1987done:
1988 dvmUnlockMutex(&gDvmJit.tableLock);
1989 return;
1990}
jeffhao9e45c0b2010-02-03 10:24:05 -08001991
1992#if defined(WITH_SELF_VERIFICATION)
1993/*
1994 * The following are used to keep compiled loads and stores from modifying
1995 * memory during self verification mode.
1996 *
1997 * Stores do not modify memory. Instead, the address and value pair are stored
1998 * into heapSpace. Addresses within heapSpace are unique. For accesses smaller
1999 * than a word, the word containing the address is loaded first before being
2000 * updated.
2001 *
2002 * Loads check heapSpace first and return data from there if an entry exists.
2003 * Otherwise, data is loaded from memory as usual.
2004 */
2005
2006/* Used to specify sizes of memory operations */
2007enum {
2008 kSVByte,
2009 kSVSignedByte,
2010 kSVHalfword,
2011 kSVSignedHalfword,
2012 kSVWord,
2013 kSVDoubleword,
jeffhao121ea792010-02-10 10:51:02 -08002014 kSVVariable,
jeffhao9e45c0b2010-02-03 10:24:05 -08002015};
2016
2017/* Load the value of a decoded register from the stack */
2018static int selfVerificationMemRegLoad(int* sp, int reg)
2019{
2020 return *(sp + reg);
2021}
2022
2023/* Load the value of a decoded doubleword register from the stack */
2024static s8 selfVerificationMemRegLoadDouble(int* sp, int reg)
2025{
2026 return *((s8*)(sp + reg));
2027}
2028
2029/* Store the value of a decoded register out to the stack */
2030static void selfVerificationMemRegStore(int* sp, int data, int reg)
2031{
2032 *(sp + reg) = data;
2033}
2034
2035/* Store the value of a decoded doubleword register out to the stack */
2036static void selfVerificationMemRegStoreDouble(int* sp, s8 data, int reg)
2037{
2038 *((s8*)(sp + reg)) = data;
2039}
2040
2041/*
2042 * Load the specified size of data from the specified address, checking
2043 * heapSpace first if Self Verification mode wrote to it previously, and
2044 * falling back to actual memory otherwise.
2045 */
2046static int selfVerificationLoad(int addr, int size)
2047{
2048 Thread *self = dvmThreadSelf();
2049 ShadowSpace *shadowSpace = self->shadowSpace;
2050 ShadowHeap *heapSpacePtr;
2051
2052 int data;
2053 int maskedAddr = addr & 0xFFFFFFFC;
2054 int alignment = addr & 0x3;
2055
2056 for (heapSpacePtr = shadowSpace->heapSpace;
2057 heapSpacePtr != shadowSpace->heapSpaceTail; heapSpacePtr++) {
2058 if (heapSpacePtr->addr == maskedAddr) {
2059 addr = ((unsigned int) &(heapSpacePtr->data)) | alignment;
2060 break;
2061 }
2062 }
2063
2064 switch (size) {
2065 case kSVByte:
2066 data = *((u1*) addr);
2067 break;
2068 case kSVSignedByte:
2069 data = *((s1*) addr);
2070 break;
2071 case kSVHalfword:
2072 data = *((u2*) addr);
2073 break;
2074 case kSVSignedHalfword:
2075 data = *((s2*) addr);
2076 break;
2077 case kSVWord:
2078 data = *((u4*) addr);
jeffhao91080d22010-02-09 14:55:47 -08002079 break;
jeffhaoe8667642010-02-05 15:08:23 -08002080 default:
jeffhao91080d22010-02-09 14:55:47 -08002081 LOGE("*** ERROR: BAD SIZE IN selfVerificationLoad: %d", size);
jeffhaoe8667642010-02-05 15:08:23 -08002082 data = 0;
2083 dvmAbort();
jeffhao9e45c0b2010-02-03 10:24:05 -08002084 }
2085
2086 //LOGD("*** HEAP LOAD: Addr: 0x%x Data: 0x%x Size: %d", addr, data, size);
2087 return data;
2088}
2089
2090/* Like selfVerificationLoad, but specifically for doublewords */
2091static s8 selfVerificationLoadDoubleword(int addr)
2092{
2093 Thread *self = dvmThreadSelf();
2094 ShadowSpace* shadowSpace = self->shadowSpace;
2095 ShadowHeap* heapSpacePtr;
2096
2097 int addr2 = addr+4;
2098 unsigned int data = *((unsigned int*) addr);
2099 unsigned int data2 = *((unsigned int*) addr2);
2100
2101 for (heapSpacePtr = shadowSpace->heapSpace;
2102 heapSpacePtr != shadowSpace->heapSpaceTail; heapSpacePtr++) {
2103 if (heapSpacePtr->addr == addr) {
2104 data = heapSpacePtr->data;
2105 } else if (heapSpacePtr->addr == addr2) {
2106 data2 = heapSpacePtr->data;
2107 }
2108 }
2109
2110 //LOGD("*** HEAP LOAD DOUBLEWORD: Addr: 0x%x Data: 0x%x Data2: 0x%x",
2111 // addr, data, data2);
2112 return (((s8) data2) << 32) | data;
2113}
2114
2115/*
2116 * Handles a store of a specified size of data to a specified address.
2117 * This gets logged as an addr/data pair in heapSpace instead of modifying
2118 * memory. Addresses in heapSpace are unique, and accesses smaller than a
2119 * word pull the entire word from memory first before updating.
2120 */
2121static void selfVerificationStore(int addr, int data, int size)
2122{
2123 Thread *self = dvmThreadSelf();
2124 ShadowSpace *shadowSpace = self->shadowSpace;
2125 ShadowHeap *heapSpacePtr;
2126
2127 int maskedAddr = addr & 0xFFFFFFFC;
2128 int alignment = addr & 0x3;
2129
2130 //LOGD("*** HEAP STORE: Addr: 0x%x Data: 0x%x Size: %d", addr, data, size);
2131
2132 for (heapSpacePtr = shadowSpace->heapSpace;
2133 heapSpacePtr != shadowSpace->heapSpaceTail; heapSpacePtr++) {
2134 if (heapSpacePtr->addr == maskedAddr) break;
2135 }
2136
2137 if (heapSpacePtr == shadowSpace->heapSpaceTail) {
2138 heapSpacePtr->addr = maskedAddr;
2139 heapSpacePtr->data = *((unsigned int*) maskedAddr);
2140 shadowSpace->heapSpaceTail++;
2141 }
2142
2143 addr = ((unsigned int) &(heapSpacePtr->data)) | alignment;
2144 switch (size) {
2145 case kSVByte:
2146 *((u1*) addr) = data;
2147 break;
2148 case kSVSignedByte:
2149 *((s1*) addr) = data;
2150 break;
2151 case kSVHalfword:
2152 *((u2*) addr) = data;
2153 break;
2154 case kSVSignedHalfword:
2155 *((s2*) addr) = data;
2156 break;
2157 case kSVWord:
2158 *((u4*) addr) = data;
jeffhao91080d22010-02-09 14:55:47 -08002159 break;
jeffhaoe8667642010-02-05 15:08:23 -08002160 default:
jeffhao91080d22010-02-09 14:55:47 -08002161 LOGE("*** ERROR: BAD SIZE IN selfVerificationSave: %d", size);
jeffhaoe8667642010-02-05 15:08:23 -08002162 dvmAbort();
jeffhao9e45c0b2010-02-03 10:24:05 -08002163 }
2164}
2165
2166/* Like selfVerificationStore, but specifically for doublewords */
2167static void selfVerificationStoreDoubleword(int addr, s8 double_data)
2168{
2169 Thread *self = dvmThreadSelf();
2170 ShadowSpace *shadowSpace = self->shadowSpace;
2171 ShadowHeap *heapSpacePtr;
2172
2173 int addr2 = addr+4;
2174 int data = double_data;
2175 int data2 = double_data >> 32;
2176 bool store1 = false, store2 = false;
2177
2178 //LOGD("*** HEAP STORE DOUBLEWORD: Addr: 0x%x Data: 0x%x, Data2: 0x%x",
2179 // addr, data, data2);
2180
2181 for (heapSpacePtr = shadowSpace->heapSpace;
2182 heapSpacePtr != shadowSpace->heapSpaceTail; heapSpacePtr++) {
2183 if (heapSpacePtr->addr == addr) {
2184 heapSpacePtr->data = data;
2185 store1 = true;
2186 } else if (heapSpacePtr->addr == addr2) {
2187 heapSpacePtr->data = data2;
2188 store2 = true;
2189 }
2190 }
2191
2192 if (!store1) {
2193 shadowSpace->heapSpaceTail->addr = addr;
2194 shadowSpace->heapSpaceTail->data = data;
2195 shadowSpace->heapSpaceTail++;
2196 }
2197 if (!store2) {
2198 shadowSpace->heapSpaceTail->addr = addr2;
2199 shadowSpace->heapSpaceTail->data = data2;
2200 shadowSpace->heapSpaceTail++;
2201 }
2202}
2203
2204/*
2205 * Decodes the memory instruction at the address specified in the link
2206 * register. All registers (r0-r12,lr) and fp registers (d0-d15) are stored
2207 * consecutively on the stack beginning at the specified stack pointer.
2208 * Calls the proper Self Verification handler for the memory instruction and
2209 * updates the link register to point past the decoded memory instruction.
2210 */
2211void dvmSelfVerificationMemOpDecode(int lr, int* sp)
2212{
2213 enum {
2214 kMemOpLdrPcRel = 0x09, // ldr(3) [01001] rd[10..8] imm_8[7..0]
2215 kMemOpRRR = 0x0A, // Full opcode is 7 bits
2216 kMemOp2Single = 0x0A, // Used for Vstrs and Vldrs
2217 kMemOpRRR2 = 0x0B, // Full opcode is 7 bits
2218 kMemOp2Double = 0x0B, // Used for Vstrd and Vldrd
2219 kMemOpStrRRI5 = 0x0C, // str(1) [01100] imm_5[10..6] rn[5..3] rd[2..0]
2220 kMemOpLdrRRI5 = 0x0D, // ldr(1) [01101] imm_5[10..6] rn[5..3] rd[2..0]
2221 kMemOpStrbRRI5 = 0x0E, // strb(1) [01110] imm_5[10..6] rn[5..3] rd[2..0]
2222 kMemOpLdrbRRI5 = 0x0F, // ldrb(1) [01111] imm_5[10..6] rn[5..3] rd[2..0]
2223 kMemOpStrhRRI5 = 0x10, // strh(1) [10000] imm_5[10..6] rn[5..3] rd[2..0]
2224 kMemOpLdrhRRI5 = 0x11, // ldrh(1) [10001] imm_5[10..6] rn[5..3] rd[2..0]
2225 kMemOpLdrSpRel = 0x13, // ldr(4) [10011] rd[10..8] imm_8[7..0]
jeffhao121ea792010-02-10 10:51:02 -08002226 kMemOpStmia = 0x18, // stmia [11000] rn[10..8] reglist [7..0]
2227 kMemOpLdmia = 0x19, // ldmia [11001] rn[10..8] reglist [7..0]
jeffhao9e45c0b2010-02-03 10:24:05 -08002228 kMemOpStrRRR = 0x28, // str(2) [0101000] rm[8..6] rn[5..3] rd[2..0]
2229 kMemOpStrhRRR = 0x29, // strh(2) [0101001] rm[8..6] rn[5..3] rd[2..0]
2230 kMemOpStrbRRR = 0x2A, // strb(2) [0101010] rm[8..6] rn[5..3] rd[2..0]
2231 kMemOpLdrsbRRR = 0x2B, // ldrsb [0101011] rm[8..6] rn[5..3] rd[2..0]
2232 kMemOpLdrRRR = 0x2C, // ldr(2) [0101100] rm[8..6] rn[5..3] rd[2..0]
2233 kMemOpLdrhRRR = 0x2D, // ldrh(2) [0101101] rm[8..6] rn[5..3] rd[2..0]
2234 kMemOpLdrbRRR = 0x2E, // ldrb(2) [0101110] rm[8..6] rn[5..3] rd[2..0]
2235 kMemOpLdrshRRR = 0x2F, // ldrsh [0101111] rm[8..6] rn[5..3] rd[2..0]
jeffhao121ea792010-02-10 10:51:02 -08002236 kMemOp2Stmia = 0xE88, // stmia [111010001000[ rn[19..16] mask[15..0]
2237 kMemOp2Ldmia = 0xE89, // ldmia [111010001001[ rn[19..16] mask[15..0]
2238 kMemOp2Stmia2 = 0xE8A, // stmia [111010001010[ rn[19..16] mask[15..0]
2239 kMemOp2Ldmia2 = 0xE8B, // ldmia [111010001011[ rn[19..16] mask[15..0]
jeffhao9e45c0b2010-02-03 10:24:05 -08002240 kMemOp2Vstr = 0xED8, // Used for Vstrs and Vstrd
2241 kMemOp2Vldr = 0xED9, // Used for Vldrs and Vldrd
2242 kMemOp2Vstr2 = 0xEDC, // Used for Vstrs and Vstrd
2243 kMemOp2Vldr2 = 0xEDD, // Used for Vstrs and Vstrd
2244 kMemOp2StrbRRR = 0xF80, /* str rt,[rn,rm,LSL #imm] [111110000000]
2245 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2246 kMemOp2LdrbRRR = 0xF81, /* ldrb rt,[rn,rm,LSL #imm] [111110000001]
2247 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2248 kMemOp2StrhRRR = 0xF82, /* str rt,[rn,rm,LSL #imm] [111110000010]
2249 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2250 kMemOp2LdrhRRR = 0xF83, /* ldrh rt,[rn,rm,LSL #imm] [111110000011]
2251 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2252 kMemOp2StrRRR = 0xF84, /* str rt,[rn,rm,LSL #imm] [111110000100]
2253 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2254 kMemOp2LdrRRR = 0xF85, /* ldr rt,[rn,rm,LSL #imm] [111110000101]
2255 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2256 kMemOp2StrbRRI12 = 0xF88, /* strb rt,[rn,#imm12] [111110001000]
2257 rt[15..12] rn[19..16] imm12[11..0] */
2258 kMemOp2LdrbRRI12 = 0xF89, /* ldrb rt,[rn,#imm12] [111110001001]
2259 rt[15..12] rn[19..16] imm12[11..0] */
2260 kMemOp2StrhRRI12 = 0xF8A, /* strh rt,[rn,#imm12] [111110001010]
2261 rt[15..12] rn[19..16] imm12[11..0] */
2262 kMemOp2LdrhRRI12 = 0xF8B, /* ldrh rt,[rn,#imm12] [111110001011]
2263 rt[15..12] rn[19..16] imm12[11..0] */
2264 kMemOp2StrRRI12 = 0xF8C, /* str(Imm,T3) rd,[rn,#imm12] [111110001100]
2265 rn[19..16] rt[15..12] imm12[11..0] */
2266 kMemOp2LdrRRI12 = 0xF8D, /* ldr(Imm,T3) rd,[rn,#imm12] [111110001101]
2267 rn[19..16] rt[15..12] imm12[11..0] */
2268 kMemOp2LdrsbRRR = 0xF91, /* ldrsb rt,[rn,rm,LSL #imm] [111110010001]
2269 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2270 kMemOp2LdrshRRR = 0xF93, /* ldrsh rt,[rn,rm,LSL #imm] [111110010011]
2271 rn[19-16] rt[15-12] [000000] imm[5-4] rm[3-0] */
2272 kMemOp2LdrsbRRI12 = 0xF99, /* ldrsb rt,[rn,#imm12] [111110011001]
2273 rt[15..12] rn[19..16] imm12[11..0] */
2274 kMemOp2LdrshRRI12 = 0xF9B, /* ldrsh rt,[rn,#imm12] [111110011011]
2275 rt[15..12] rn[19..16] imm12[11..0] */
2276 kMemOp2 = 0xE000, // top 3 bits set indicates Thumb2
2277 };
2278
2279 int addr, offset, data;
2280 long long double_data;
2281 int size = kSVWord;
2282 bool store = false;
2283 unsigned int *lr_masked = (unsigned int *) (lr & 0xFFFFFFFE);
2284 unsigned int insn = *lr_masked;
2285
2286 int old_lr;
2287 old_lr = selfVerificationMemRegLoad(sp, 13);
2288
2289 if ((insn & kMemOp2) == kMemOp2) {
2290 insn = (insn << 16) | (insn >> 16);
2291 //LOGD("*** THUMB2 - Addr: 0x%x Insn: 0x%x", lr, insn);
2292
2293 int opcode12 = (insn >> 20) & 0xFFF;
jeffhao9e45c0b2010-02-03 10:24:05 -08002294 int opcode4 = (insn >> 8) & 0xF;
2295 int imm2 = (insn >> 4) & 0x3;
2296 int imm8 = insn & 0xFF;
2297 int imm12 = insn & 0xFFF;
2298 int rd = (insn >> 12) & 0xF;
2299 int rm = insn & 0xF;
2300 int rn = (insn >> 16) & 0xF;
2301 int rt = (insn >> 12) & 0xF;
jeffhao121ea792010-02-10 10:51:02 -08002302 bool wBack = true;
jeffhao9e45c0b2010-02-03 10:24:05 -08002303
2304 // Update the link register
2305 selfVerificationMemRegStore(sp, old_lr+4, 13);
2306
2307 // Determine whether the mem op is a store or load
2308 switch (opcode12) {
jeffhao121ea792010-02-10 10:51:02 -08002309 case kMemOp2Stmia:
2310 case kMemOp2Stmia2:
jeffhao9e45c0b2010-02-03 10:24:05 -08002311 case kMemOp2Vstr:
2312 case kMemOp2Vstr2:
2313 case kMemOp2StrbRRR:
2314 case kMemOp2StrhRRR:
2315 case kMemOp2StrRRR:
2316 case kMemOp2StrbRRI12:
2317 case kMemOp2StrhRRI12:
2318 case kMemOp2StrRRI12:
2319 store = true;
2320 }
2321
2322 // Determine the size of the mem access
2323 switch (opcode12) {
2324 case kMemOp2StrbRRR:
2325 case kMemOp2LdrbRRR:
2326 case kMemOp2StrbRRI12:
2327 case kMemOp2LdrbRRI12:
2328 size = kSVByte;
2329 break;
2330 case kMemOp2LdrsbRRR:
2331 case kMemOp2LdrsbRRI12:
2332 size = kSVSignedByte;
2333 break;
2334 case kMemOp2StrhRRR:
2335 case kMemOp2LdrhRRR:
2336 case kMemOp2StrhRRI12:
2337 case kMemOp2LdrhRRI12:
2338 size = kSVHalfword;
2339 break;
2340 case kMemOp2LdrshRRR:
2341 case kMemOp2LdrshRRI12:
2342 size = kSVSignedHalfword;
2343 break;
2344 case kMemOp2Vstr:
2345 case kMemOp2Vstr2:
2346 case kMemOp2Vldr:
2347 case kMemOp2Vldr2:
2348 if (opcode4 == kMemOp2Double) size = kSVDoubleword;
2349 break;
jeffhao121ea792010-02-10 10:51:02 -08002350 case kMemOp2Stmia:
2351 case kMemOp2Ldmia:
2352 case kMemOp2Stmia2:
2353 case kMemOp2Ldmia2:
2354 size = kSVVariable;
2355 break;
jeffhao9e45c0b2010-02-03 10:24:05 -08002356 }
2357
2358 // Load the value of the address
2359 addr = selfVerificationMemRegLoad(sp, rn);
2360
2361 // Figure out the offset
2362 switch (opcode12) {
2363 case kMemOp2Vstr:
2364 case kMemOp2Vstr2:
2365 case kMemOp2Vldr:
2366 case kMemOp2Vldr2:
2367 offset = imm8 << 2;
2368 if (opcode4 == kMemOp2Single) {
2369 rt = rd << 1;
2370 if (insn & 0x400000) rt |= 0x1;
2371 } else if (opcode4 == kMemOp2Double) {
2372 if (insn & 0x400000) rt |= 0x10;
2373 rt = rt << 1;
2374 } else {
jeffhao91080d22010-02-09 14:55:47 -08002375 LOGE("*** ERROR: UNRECOGNIZED VECTOR MEM OP: %x", opcode4);
jeffhao9e45c0b2010-02-03 10:24:05 -08002376 dvmAbort();
2377 }
2378 rt += 14;
2379 break;
2380 case kMemOp2StrbRRR:
2381 case kMemOp2LdrbRRR:
2382 case kMemOp2StrhRRR:
2383 case kMemOp2LdrhRRR:
2384 case kMemOp2StrRRR:
2385 case kMemOp2LdrRRR:
2386 case kMemOp2LdrsbRRR:
2387 case kMemOp2LdrshRRR:
2388 offset = selfVerificationMemRegLoad(sp, rm) << imm2;
2389 break;
2390 case kMemOp2StrbRRI12:
2391 case kMemOp2LdrbRRI12:
2392 case kMemOp2StrhRRI12:
2393 case kMemOp2LdrhRRI12:
2394 case kMemOp2StrRRI12:
2395 case kMemOp2LdrRRI12:
2396 case kMemOp2LdrsbRRI12:
2397 case kMemOp2LdrshRRI12:
2398 offset = imm12;
2399 break;
jeffhao121ea792010-02-10 10:51:02 -08002400 case kMemOp2Stmia:
2401 case kMemOp2Ldmia:
2402 wBack = false;
2403 case kMemOp2Stmia2:
2404 case kMemOp2Ldmia2:
2405 offset = 0;
2406 break;
jeffhao9e45c0b2010-02-03 10:24:05 -08002407 default:
jeffhao91080d22010-02-09 14:55:47 -08002408 LOGE("*** ERROR: UNRECOGNIZED THUMB2 MEM OP: %x", opcode12);
jeffhaoe8667642010-02-05 15:08:23 -08002409 offset = 0;
jeffhao9e45c0b2010-02-03 10:24:05 -08002410 dvmAbort();
2411 }
2412
2413 // Handle the decoded mem op accordingly
2414 if (store) {
jeffhao121ea792010-02-10 10:51:02 -08002415 if (size == kSVVariable) {
2416 LOGD("*** THUMB2 STMIA CURRENTLY UNUSED (AND UNTESTED)");
2417 int i;
2418 int regList = insn & 0xFFFF;
2419 for (i = 0; i < 16; i++) {
2420 if (regList & 0x1) {
2421 data = selfVerificationMemRegLoad(sp, i);
2422 selfVerificationStore(addr, data, kSVWord);
2423 addr += 4;
2424 }
2425 regList = regList >> 1;
2426 }
2427 if (wBack) selfVerificationMemRegStore(sp, addr, rn);
2428 } else if (size == kSVDoubleword) {
jeffhao9e45c0b2010-02-03 10:24:05 -08002429 double_data = selfVerificationMemRegLoadDouble(sp, rt);
2430 selfVerificationStoreDoubleword(addr+offset, double_data);
2431 } else {
2432 data = selfVerificationMemRegLoad(sp, rt);
2433 selfVerificationStore(addr+offset, data, size);
2434 }
2435 } else {
jeffhao121ea792010-02-10 10:51:02 -08002436 if (size == kSVVariable) {
2437 LOGD("*** THUMB2 LDMIA CURRENTLY UNUSED (AND UNTESTED)");
2438 int i;
2439 int regList = insn & 0xFFFF;
2440 for (i = 0; i < 16; i++) {
2441 if (regList & 0x1) {
2442 data = selfVerificationLoad(addr, kSVWord);
2443 selfVerificationMemRegStore(sp, data, i);
2444 addr += 4;
2445 }
2446 regList = regList >> 1;
2447 }
2448 if (wBack) selfVerificationMemRegStore(sp, addr, rn);
2449 } else if (size == kSVDoubleword) {
jeffhao9e45c0b2010-02-03 10:24:05 -08002450 double_data = selfVerificationLoadDoubleword(addr+offset);
2451 selfVerificationMemRegStoreDouble(sp, double_data, rt);
2452 } else {
2453 data = selfVerificationLoad(addr+offset, size);
2454 selfVerificationMemRegStore(sp, data, rt);
2455 }
2456 }
2457 } else {
2458 //LOGD("*** THUMB - Addr: 0x%x Insn: 0x%x", lr, insn);
2459
2460 // Update the link register
2461 selfVerificationMemRegStore(sp, old_lr+2, 13);
2462
2463 int opcode5 = (insn >> 11) & 0x1F;
2464 int opcode7 = (insn >> 9) & 0x7F;
2465 int imm = (insn >> 6) & 0x1F;
2466 int rd = (insn >> 8) & 0x7;
2467 int rm = (insn >> 6) & 0x7;
2468 int rn = (insn >> 3) & 0x7;
2469 int rt = insn & 0x7;
2470
2471 // Determine whether the mem op is a store or load
2472 switch (opcode5) {
2473 case kMemOpRRR:
2474 switch (opcode7) {
2475 case kMemOpStrRRR:
2476 case kMemOpStrhRRR:
2477 case kMemOpStrbRRR:
2478 store = true;
2479 }
2480 break;
2481 case kMemOpStrRRI5:
2482 case kMemOpStrbRRI5:
2483 case kMemOpStrhRRI5:
jeffhao121ea792010-02-10 10:51:02 -08002484 case kMemOpStmia:
jeffhao9e45c0b2010-02-03 10:24:05 -08002485 store = true;
2486 }
2487
2488 // Determine the size of the mem access
2489 switch (opcode5) {
2490 case kMemOpRRR:
2491 case kMemOpRRR2:
2492 switch (opcode7) {
2493 case kMemOpStrbRRR:
2494 case kMemOpLdrbRRR:
2495 size = kSVByte;
2496 break;
2497 case kMemOpLdrsbRRR:
2498 size = kSVSignedByte;
2499 break;
2500 case kMemOpStrhRRR:
2501 case kMemOpLdrhRRR:
2502 size = kSVHalfword;
2503 break;
2504 case kMemOpLdrshRRR:
2505 size = kSVSignedHalfword;
2506 break;
2507 }
2508 break;
2509 case kMemOpStrbRRI5:
2510 case kMemOpLdrbRRI5:
2511 size = kSVByte;
2512 break;
2513 case kMemOpStrhRRI5:
2514 case kMemOpLdrhRRI5:
2515 size = kSVHalfword;
2516 break;
jeffhao121ea792010-02-10 10:51:02 -08002517 case kMemOpStmia:
2518 case kMemOpLdmia:
2519 size = kSVVariable;
2520 break;
jeffhao9e45c0b2010-02-03 10:24:05 -08002521 }
2522
2523 // Load the value of the address
2524 if (opcode5 == kMemOpLdrPcRel)
2525 addr = selfVerificationMemRegLoad(sp, 4);
jeffhao121ea792010-02-10 10:51:02 -08002526 else if (opcode5 == kMemOpStmia || opcode5 == kMemOpLdmia)
2527 addr = selfVerificationMemRegLoad(sp, rd);
jeffhao9e45c0b2010-02-03 10:24:05 -08002528 else
2529 addr = selfVerificationMemRegLoad(sp, rn);
2530
2531 // Figure out the offset
2532 switch (opcode5) {
2533 case kMemOpLdrPcRel:
2534 offset = (insn & 0xFF) << 2;
2535 rt = rd;
2536 break;
2537 case kMemOpRRR:
2538 case kMemOpRRR2:
2539 offset = selfVerificationMemRegLoad(sp, rm);
2540 break;
2541 case kMemOpStrRRI5:
2542 case kMemOpLdrRRI5:
2543 offset = imm << 2;
2544 break;
2545 case kMemOpStrhRRI5:
2546 case kMemOpLdrhRRI5:
2547 offset = imm << 1;
2548 break;
2549 case kMemOpStrbRRI5:
2550 case kMemOpLdrbRRI5:
2551 offset = imm;
2552 break;
jeffhao121ea792010-02-10 10:51:02 -08002553 case kMemOpStmia:
2554 case kMemOpLdmia:
2555 offset = 0;
2556 break;
jeffhao9e45c0b2010-02-03 10:24:05 -08002557 default:
jeffhao91080d22010-02-09 14:55:47 -08002558 LOGE("*** ERROR: UNRECOGNIZED THUMB MEM OP: %x", opcode5);
jeffhaoe8667642010-02-05 15:08:23 -08002559 offset = 0;
jeffhao9e45c0b2010-02-03 10:24:05 -08002560 dvmAbort();
2561 }
2562
2563 // Handle the decoded mem op accordingly
2564 if (store) {
jeffhao121ea792010-02-10 10:51:02 -08002565 if (size == kSVVariable) {
2566 int i;
2567 int regList = insn & 0xFF;
2568 for (i = 0; i < 8; i++) {
2569 if (regList & 0x1) {
2570 data = selfVerificationMemRegLoad(sp, i);
2571 selfVerificationStore(addr, data, kSVWord);
2572 addr += 4;
2573 }
2574 regList = regList >> 1;
2575 }
2576 selfVerificationMemRegStore(sp, addr, rd);
2577 } else {
2578 data = selfVerificationMemRegLoad(sp, rt);
2579 selfVerificationStore(addr+offset, data, size);
2580 }
jeffhao9e45c0b2010-02-03 10:24:05 -08002581 } else {
jeffhao121ea792010-02-10 10:51:02 -08002582 if (size == kSVVariable) {
2583 bool wBack = true;
2584 int i;
2585 int regList = insn & 0xFF;
2586 for (i = 0; i < 8; i++) {
2587 if (regList & 0x1) {
2588 if (i == rd) wBack = false;
2589 data = selfVerificationLoad(addr, kSVWord);
2590 selfVerificationMemRegStore(sp, data, i);
2591 addr += 4;
2592 }
2593 regList = regList >> 1;
2594 }
2595 if (wBack) selfVerificationMemRegStore(sp, addr, rd);
2596 } else {
2597 data = selfVerificationLoad(addr+offset, size);
2598 selfVerificationMemRegStore(sp, data, rt);
2599 }
jeffhao9e45c0b2010-02-03 10:24:05 -08002600 }
2601 }
2602}
2603#endif