blob: f9226878a916c6986b9b4b923f2b20d7025360c8 [file] [log] [blame]
Elliott Hughes60454e82012-04-25 12:56:03 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "disassembler_mips.h"
18
Ian Rogerscf7f1912014-10-22 22:06:39 -070019#include <ostream>
Ian Rogersc7dd2952014-10-21 23:31:19 -070020#include <sstream>
Elliott Hughes60454e82012-04-25 12:56:03 -070021
Elliott Hughes07ed66b2012-12-12 18:34:25 -080022#include "base/logging.h"
Elliott Hughese222ee02012-12-13 14:41:43 -080023#include "base/stringprintf.h"
Elliott Hughes60454e82012-04-25 12:56:03 -070024#include "thread.h"
25
26namespace art {
27namespace mips {
28
29struct MipsInstruction {
30 uint32_t mask;
31 uint32_t value;
32 const char* name;
33 const char* args_fmt;
34
35 bool Matches(uint32_t instruction) const {
36 return (instruction & mask) == value;
37 }
38};
39
40static const uint32_t kOpcodeShift = 26;
41
42static const uint32_t kCop1 = (17 << kOpcodeShift);
43
44static const uint32_t kITypeMask = (0x3f << kOpcodeShift);
45static const uint32_t kJTypeMask = (0x3f << kOpcodeShift);
46static const uint32_t kRTypeMask = ((0x3f << kOpcodeShift) | (0x3f));
Goran Jakovljevic403e0d52015-04-08 16:26:05 +020047static const uint32_t kSpecial0Mask = (0x3f << kOpcodeShift);
Elliott Hughes60454e82012-04-25 12:56:03 -070048static const uint32_t kSpecial2Mask = (0x3f << kOpcodeShift);
Chris Larsen2fadd7b2015-08-14 14:56:10 -070049static const uint32_t kSpecial3Mask = (0x3f << kOpcodeShift);
Elliott Hughes60454e82012-04-25 12:56:03 -070050static const uint32_t kFpMask = kRTypeMask;
51
52static const MipsInstruction gMipsInstructions[] = {
53 // "sll r0, r0, 0" is the canonical "nop", used in delay slots.
54 { 0xffffffff, 0, "nop", "" },
55
56 // R-type instructions.
57 { kRTypeMask, 0, "sll", "DTA", },
58 // 0, 1, movci
Alexey Frunze92d90602015-12-18 18:16:36 -080059 { kRTypeMask | (0x1f << 21), 2, "srl", "DTA", },
Elliott Hughes60454e82012-04-25 12:56:03 -070060 { kRTypeMask, 3, "sra", "DTA", },
Chris Larsen7d4152f2015-10-19 15:17:16 -070061 { kRTypeMask | (0x1f << 6), 4, "sllv", "DTS", },
62 { kRTypeMask | (0x1f << 6), 6, "srlv", "DTS", },
63 { kRTypeMask | (0x1f << 6), (1 << 6) | 6, "rotrv", "DTS", },
64 { kRTypeMask | (0x1f << 6), 7, "srav", "DTS", },
Elliott Hughes60454e82012-04-25 12:56:03 -070065 { kRTypeMask, 8, "jr", "S", },
Brian Carlstrom7934ac22013-07-26 10:54:15 -070066 { kRTypeMask | (0x1f << 11), 9 | (31 << 11), "jalr", "S", }, // rd = 31 is implicit.
Goran Jakovljevic403e0d52015-04-08 16:26:05 +020067 { kRTypeMask | (0x1f << 11), 9, "jr", "S", }, // rd = 0 is implicit.
Brian Carlstrom7934ac22013-07-26 10:54:15 -070068 { kRTypeMask, 9, "jalr", "DS", }, // General case.
Elliott Hughes60454e82012-04-25 12:56:03 -070069 { kRTypeMask | (0x1f << 6), 10, "movz", "DST", },
70 { kRTypeMask | (0x1f << 6), 11, "movn", "DST", },
Brian Carlstrom7934ac22013-07-26 10:54:15 -070071 { kRTypeMask, 12, "syscall", "", }, // TODO: code
72 { kRTypeMask, 13, "break", "", }, // TODO: code
73 { kRTypeMask, 15, "sync", "", }, // TODO: type
Elliott Hughes60454e82012-04-25 12:56:03 -070074 { kRTypeMask, 16, "mfhi", "D", },
75 { kRTypeMask, 17, "mthi", "S", },
76 { kRTypeMask, 18, "mflo", "D", },
77 { kRTypeMask, 19, "mtlo", "S", },
Chris Larsen7d4152f2015-10-19 15:17:16 -070078 { kRTypeMask | (0x1f << 6), 20, "dsllv", "DTS", },
79 { kRTypeMask | (0x1f << 6), 22, "dsrlv", "DTS", },
80 { kRTypeMask | (0x1f << 6), (1 << 6) | 22, "drotrv", "DTS", },
81 { kRTypeMask | (0x1f << 6), 23, "dsrav", "DTS", },
Douglas Leung027f0ff2015-02-27 19:05:03 -080082 { kRTypeMask | (0x1f << 6), 24, "mult", "ST", },
83 { kRTypeMask | (0x1f << 6), 25, "multu", "ST", },
84 { kRTypeMask | (0x1f << 6), 26, "div", "ST", },
85 { kRTypeMask | (0x1f << 6), 27, "divu", "ST", },
86 { kRTypeMask | (0x1f << 6), 24 + (2 << 6), "mul", "DST", },
87 { kRTypeMask | (0x1f << 6), 24 + (3 << 6), "muh", "DST", },
88 { kRTypeMask | (0x1f << 6), 26 + (2 << 6), "div", "DST", },
89 { kRTypeMask | (0x1f << 6), 26 + (3 << 6), "mod", "DST", },
Elliott Hughes60454e82012-04-25 12:56:03 -070090 { kRTypeMask, 32, "add", "DST", },
91 { kRTypeMask, 33, "addu", "DST", },
92 { kRTypeMask, 34, "sub", "DST", },
93 { kRTypeMask, 35, "subu", "DST", },
94 { kRTypeMask, 36, "and", "DST", },
95 { kRTypeMask, 37, "or", "DST", },
96 { kRTypeMask, 38, "xor", "DST", },
97 { kRTypeMask, 39, "nor", "DST", },
98 { kRTypeMask, 42, "slt", "DST", },
99 { kRTypeMask, 43, "sltu", "DST", },
Goran Jakovljevic403e0d52015-04-08 16:26:05 +0200100 { kRTypeMask, 45, "daddu", "DST", },
101 { kRTypeMask, 46, "dsub", "DST", },
102 { kRTypeMask, 47, "dsubu", "DST", },
103 // TODO: tge[u], tlt[u], teg, tne
Chris Larsen7d4152f2015-10-19 15:17:16 -0700104 { kRTypeMask | (0x1f << 21), 56, "dsll", "DTA", },
105 { kRTypeMask | (0x1f << 21), 58, "dsrl", "DTA", },
106 { kRTypeMask | (0x1f << 21), (1 << 21) | 58, "drotr", "DTA", },
107 { kRTypeMask | (0x1f << 21), 59, "dsra", "DTA", },
108 { kRTypeMask | (0x1f << 21), 60, "dsll32", "DTA", },
109 { kRTypeMask | (0x1f << 21), 62, "dsrl32", "DTA", },
110 { kRTypeMask | (0x1f << 21), (1 << 21) | 62, "drotr32", "DTA", },
111 { kRTypeMask | (0x1f << 21), 63, "dsra32", "DTA", },
Goran Jakovljevic403e0d52015-04-08 16:26:05 +0200112
113 // SPECIAL0
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800114 { kSpecial0Mask | 0x307ff, 1, "movf", "DSc" },
115 { kSpecial0Mask | 0x307ff, 0x10001, "movt", "DSc" },
Goran Jakovljevic403e0d52015-04-08 16:26:05 +0200116 { kSpecial0Mask | 0x7ff, (2 << 6) | 24, "mul", "DST" },
117 { kSpecial0Mask | 0x7ff, (3 << 6) | 24, "muh", "DST" },
118 { kSpecial0Mask | 0x7ff, (2 << 6) | 25, "mulu", "DST" },
119 { kSpecial0Mask | 0x7ff, (3 << 6) | 25, "muhu", "DST" },
120 { kSpecial0Mask | 0x7ff, (2 << 6) | 26, "div", "DST" },
121 { kSpecial0Mask | 0x7ff, (3 << 6) | 26, "mod", "DST" },
122 { kSpecial0Mask | 0x7ff, (2 << 6) | 27, "divu", "DST" },
123 { kSpecial0Mask | 0x7ff, (3 << 6) | 27, "modu", "DST" },
124 { kSpecial0Mask | 0x7ff, (2 << 6) | 28, "dmul", "DST" },
125 { kSpecial0Mask | 0x7ff, (3 << 6) | 28, "dmuh", "DST" },
126 { kSpecial0Mask | 0x7ff, (2 << 6) | 29, "dmulu", "DST" },
127 { kSpecial0Mask | 0x7ff, (3 << 6) | 29, "dmuhu", "DST" },
128 { kSpecial0Mask | 0x7ff, (2 << 6) | 30, "ddiv", "DST" },
129 { kSpecial0Mask | 0x7ff, (3 << 6) | 30, "dmod", "DST" },
130 { kSpecial0Mask | 0x7ff, (2 << 6) | 31, "ddivu", "DST" },
131 { kSpecial0Mask | 0x7ff, (3 << 6) | 31, "dmodu", "DST" },
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700132 { kSpecial0Mask | 0x7ff, (0 << 6) | 53, "seleqz", "DST" },
133 { kSpecial0Mask | 0x7ff, (0 << 6) | 55, "selnez", "DST" },
134 { kSpecial0Mask | (0x1f << 21) | 0x3f, (1 << 21) | 2, "rotr", "DTA", },
135 { kSpecial0Mask | (0x1f << 16) | 0x7ff, (0x01 << 6) | 0x10, "clz", "DS" },
136 { kSpecial0Mask | (0x1f << 16) | 0x7ff, (0x01 << 6) | 0x11, "clo", "DS" },
137 { kSpecial0Mask | (0x1f << 16) | 0x7ff, (0x01 << 6) | 0x12, "dclz", "DS" },
138 { kSpecial0Mask | (0x1f << 16) | 0x7ff, (0x01 << 6) | 0x13, "dclo", "DS" },
Goran Jakovljevic403e0d52015-04-08 16:26:05 +0200139 // TODO: sdbbp
Elliott Hughes60454e82012-04-25 12:56:03 -0700140
141 // SPECIAL2
142 { kSpecial2Mask | 0x7ff, (28 << kOpcodeShift) | 2, "mul", "DST" },
143 { kSpecial2Mask | 0x7ff, (28 << kOpcodeShift) | 32, "clz", "DS" },
Chris Larsene3845472015-11-18 12:27:15 -0800144 { kSpecial2Mask | 0x7ff, (28 << kOpcodeShift) | 33, "clo", "DS" },
Elliott Hughes60454e82012-04-25 12:56:03 -0700145 { kSpecial2Mask | 0xffff, (28 << kOpcodeShift) | 0, "madd", "ST" },
146 { kSpecial2Mask | 0xffff, (28 << kOpcodeShift) | 1, "maddu", "ST" },
147 { kSpecial2Mask | 0xffff, (28 << kOpcodeShift) | 2, "mul", "DST" },
148 { kSpecial2Mask | 0xffff, (28 << kOpcodeShift) | 4, "msub", "ST" },
149 { kSpecial2Mask | 0xffff, (28 << kOpcodeShift) | 5, "msubu", "ST" },
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700150 { kSpecial2Mask | 0x3f, (28 << kOpcodeShift) | 0x3f, "sdbbp", "" }, // TODO: code
Elliott Hughes60454e82012-04-25 12:56:03 -0700151
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700152 // SPECIAL3
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800153 { kSpecial3Mask | 0x3f, (31 << kOpcodeShift), "ext", "TSAZ", },
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700154 { kSpecial3Mask | 0x3f, (31 << kOpcodeShift) | 3, "dext", "TSAZ", },
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800155 { kSpecial3Mask | 0x3f, (31 << kOpcodeShift) | 4, "ins", "TSAz", },
Chris Larsene3845472015-11-18 12:27:15 -0800156 { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f,
157 (31 << kOpcodeShift) | (16 << 6) | 32,
158 "seb",
159 "DT", },
160 { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f,
161 (31 << kOpcodeShift) | (24 << 6) | 32,
162 "seh",
163 "DT", },
164 { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f,
165 (31 << kOpcodeShift) | 32,
166 "bitswap",
167 "DT", },
168 { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f,
169 (31 << kOpcodeShift) | 36,
170 "dbitswap",
171 "DT", },
172 { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f,
173 (31 << kOpcodeShift) | (2 << 6) | 36,
174 "dsbh",
175 "DT", },
176 { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f,
177 (31 << kOpcodeShift) | (5 << 6) | 36,
178 "dshd",
179 "DT", },
180 { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f,
181 (31 << kOpcodeShift) | (2 << 6) | 32,
182 "wsbh",
183 "DT", },
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700184 { kSpecial3Mask | 0x7f, (31 << kOpcodeShift) | 0x26, "sc", "Tl", },
185 { kSpecial3Mask | 0x7f, (31 << kOpcodeShift) | 0x27, "scd", "Tl", },
186 { kSpecial3Mask | 0x7f, (31 << kOpcodeShift) | 0x36, "ll", "Tl", },
187 { kSpecial3Mask | 0x7f, (31 << kOpcodeShift) | 0x37, "lld", "Tl", },
188
Elliott Hughes60454e82012-04-25 12:56:03 -0700189 // J-type instructions.
190 { kJTypeMask, 2 << kOpcodeShift, "j", "L" },
191 { kJTypeMask, 3 << kOpcodeShift, "jal", "L" },
192
193 // I-type instructions.
194 { kITypeMask, 4 << kOpcodeShift, "beq", "STB" },
195 { kITypeMask, 5 << kOpcodeShift, "bne", "STB" },
196 { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (1 << 16), "bgez", "SB" },
197 { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (0 << 16), "bltz", "SB" },
198 { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (2 << 16), "bltzl", "SB" },
199 { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (16 << 16), "bltzal", "SB" },
200 { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (18 << 16), "bltzall", "SB" },
201 { kITypeMask | (0x1f << 16), 6 << kOpcodeShift | (0 << 16), "blez", "SB" },
Alexey Frunze4dda3372015-06-01 18:31:49 -0700202 { kITypeMask, 6 << kOpcodeShift, "bgeuc", "STB" },
Elliott Hughes60454e82012-04-25 12:56:03 -0700203 { kITypeMask | (0x1f << 16), 7 << kOpcodeShift | (0 << 16), "bgtz", "SB" },
Alexey Frunze4dda3372015-06-01 18:31:49 -0700204 { kITypeMask, 7 << kOpcodeShift, "bltuc", "STB" },
Goran Jakovljevic403e0d52015-04-08 16:26:05 +0200205 { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (6 << 16), "dahi", "Si", },
206 { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (30 << 16), "dati", "Si", },
Elliott Hughes60454e82012-04-25 12:56:03 -0700207
208 { 0xffff0000, (4 << kOpcodeShift), "b", "B" },
209 { 0xffff0000, (1 << kOpcodeShift) | (17 << 16), "bal", "B" },
210
Alexey Frunze4dda3372015-06-01 18:31:49 -0700211 { kITypeMask, 8 << kOpcodeShift, "beqc", "STB" },
212
Elliott Hughes60454e82012-04-25 12:56:03 -0700213 { kITypeMask, 8 << kOpcodeShift, "addi", "TSi", },
214 { kITypeMask, 9 << kOpcodeShift, "addiu", "TSi", },
215 { kITypeMask, 10 << kOpcodeShift, "slti", "TSi", },
216 { kITypeMask, 11 << kOpcodeShift, "sltiu", "TSi", },
217 { kITypeMask, 12 << kOpcodeShift, "andi", "TSi", },
218 { kITypeMask, 13 << kOpcodeShift, "ori", "TSi", },
Goran Jakovljevic403e0d52015-04-08 16:26:05 +0200219 { kITypeMask, 14 << kOpcodeShift, "xori", "TSi", },
220 { kITypeMask | (0x1f << 21), 15 << kOpcodeShift, "lui", "TI", },
221 { kITypeMask, 15 << kOpcodeShift, "aui", "TSI", },
Alexey Frunze4dda3372015-06-01 18:31:49 -0700222
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800223 { kITypeMask | (0x3e3 << 16), (17 << kOpcodeShift) | (8 << 21), "bc1f", "cB" },
224 { kITypeMask | (0x3e3 << 16), (17 << kOpcodeShift) | (8 << 21) | (1 << 16), "bc1t", "cB" },
225 { kITypeMask | (0x1f << 21), (17 << kOpcodeShift) | (9 << 21), "bc1eqz", "tB" },
226 { kITypeMask | (0x1f << 21), (17 << kOpcodeShift) | (13 << 21), "bc1nez", "tB" },
227
Alexey Frunze4dda3372015-06-01 18:31:49 -0700228 { kITypeMask | (0x1f << 21), 22 << kOpcodeShift, "blezc", "TB" },
229
230 // TODO: de-dup
231 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (1 << 21) | (1 << 16), "bgezc", "TB" },
232 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (2 << 21) | (2 << 16), "bgezc", "TB" },
233 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (3 << 21) | (3 << 16), "bgezc", "TB" },
234 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (4 << 21) | (4 << 16), "bgezc", "TB" },
235 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (5 << 21) | (5 << 16), "bgezc", "TB" },
236 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (6 << 21) | (6 << 16), "bgezc", "TB" },
237 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (7 << 21) | (7 << 16), "bgezc", "TB" },
238 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (8 << 21) | (8 << 16), "bgezc", "TB" },
239 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (9 << 21) | (9 << 16), "bgezc", "TB" },
240 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (10 << 21) | (10 << 16), "bgezc", "TB" },
241 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (11 << 21) | (11 << 16), "bgezc", "TB" },
242 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (12 << 21) | (12 << 16), "bgezc", "TB" },
243 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (13 << 21) | (13 << 16), "bgezc", "TB" },
244 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (14 << 21) | (14 << 16), "bgezc", "TB" },
245 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (15 << 21) | (15 << 16), "bgezc", "TB" },
246 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (16 << 21) | (16 << 16), "bgezc", "TB" },
247 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (17 << 21) | (17 << 16), "bgezc", "TB" },
248 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (18 << 21) | (18 << 16), "bgezc", "TB" },
249 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (19 << 21) | (19 << 16), "bgezc", "TB" },
250 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (20 << 21) | (20 << 16), "bgezc", "TB" },
251 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (21 << 21) | (21 << 16), "bgezc", "TB" },
252 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (22 << 21) | (22 << 16), "bgezc", "TB" },
253 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (23 << 21) | (23 << 16), "bgezc", "TB" },
254 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (24 << 21) | (24 << 16), "bgezc", "TB" },
255 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (25 << 21) | (25 << 16), "bgezc", "TB" },
256 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (26 << 21) | (26 << 16), "bgezc", "TB" },
257 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (27 << 21) | (27 << 16), "bgezc", "TB" },
258 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (28 << 21) | (28 << 16), "bgezc", "TB" },
259 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (29 << 21) | (29 << 16), "bgezc", "TB" },
260 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (30 << 21) | (30 << 16), "bgezc", "TB" },
261 { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (31 << 21) | (31 << 16), "bgezc", "TB" },
262
263 { kITypeMask, 22 << kOpcodeShift, "bgec", "STB" },
264
265 { kITypeMask | (0x1f << 21), 23 << kOpcodeShift, "bgtzc", "TB" },
266
267 // TODO: de-dup
268 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (1 << 21) | (1 << 16), "bltzc", "TB" },
269 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (2 << 21) | (2 << 16), "bltzc", "TB" },
270 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (3 << 21) | (3 << 16), "bltzc", "TB" },
271 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (4 << 21) | (4 << 16), "bltzc", "TB" },
272 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (5 << 21) | (5 << 16), "bltzc", "TB" },
273 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (6 << 21) | (6 << 16), "bltzc", "TB" },
274 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (7 << 21) | (7 << 16), "bltzc", "TB" },
275 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (8 << 21) | (8 << 16), "bltzc", "TB" },
276 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (9 << 21) | (9 << 16), "bltzc", "TB" },
277 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (10 << 21) | (10 << 16), "bltzc", "TB" },
278 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (11 << 21) | (11 << 16), "bltzc", "TB" },
279 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (12 << 21) | (12 << 16), "bltzc", "TB" },
280 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (13 << 21) | (13 << 16), "bltzc", "TB" },
281 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (14 << 21) | (14 << 16), "bltzc", "TB" },
282 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (15 << 21) | (15 << 16), "bltzc", "TB" },
283 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (16 << 21) | (16 << 16), "bltzc", "TB" },
284 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (17 << 21) | (17 << 16), "bltzc", "TB" },
285 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (18 << 21) | (18 << 16), "bltzc", "TB" },
286 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (19 << 21) | (19 << 16), "bltzc", "TB" },
287 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (20 << 21) | (20 << 16), "bltzc", "TB" },
288 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (21 << 21) | (21 << 16), "bltzc", "TB" },
289 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (22 << 21) | (22 << 16), "bltzc", "TB" },
290 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (23 << 21) | (23 << 16), "bltzc", "TB" },
291 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (24 << 21) | (24 << 16), "bltzc", "TB" },
292 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (25 << 21) | (25 << 16), "bltzc", "TB" },
293 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (26 << 21) | (26 << 16), "bltzc", "TB" },
294 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (27 << 21) | (27 << 16), "bltzc", "TB" },
295 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (28 << 21) | (28 << 16), "bltzc", "TB" },
296 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (29 << 21) | (29 << 16), "bltzc", "TB" },
297 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (30 << 21) | (30 << 16), "bltzc", "TB" },
298 { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (31 << 21) | (31 << 16), "bltzc", "TB" },
299
300 { kITypeMask, 23 << kOpcodeShift, "bltc", "STB" },
301
302 { kITypeMask, 24 << kOpcodeShift, "bnec", "STB" },
303
Goran Jakovljevic403e0d52015-04-08 16:26:05 +0200304 { kITypeMask, 25 << kOpcodeShift, "daddiu", "TSi", },
305 { kITypeMask, 29 << kOpcodeShift, "daui", "TSi", },
Elliott Hughes60454e82012-04-25 12:56:03 -0700306
Brian Carlstromd74e41b2013-03-24 23:47:01 -0700307 { kITypeMask, 32u << kOpcodeShift, "lb", "TO", },
308 { kITypeMask, 33u << kOpcodeShift, "lh", "TO", },
309 { kITypeMask, 35u << kOpcodeShift, "lw", "TO", },
310 { kITypeMask, 36u << kOpcodeShift, "lbu", "TO", },
311 { kITypeMask, 37u << kOpcodeShift, "lhu", "TO", },
Goran Jakovljevic403e0d52015-04-08 16:26:05 +0200312 { kITypeMask, 39u << kOpcodeShift, "lwu", "TO", },
Brian Carlstromd74e41b2013-03-24 23:47:01 -0700313 { kITypeMask, 40u << kOpcodeShift, "sb", "TO", },
314 { kITypeMask, 41u << kOpcodeShift, "sh", "TO", },
315 { kITypeMask, 43u << kOpcodeShift, "sw", "TO", },
316 { kITypeMask, 49u << kOpcodeShift, "lwc1", "tO", },
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200317 { kJTypeMask, 50u << kOpcodeShift, "bc", "P" },
Andreas Gampe8d365912015-01-13 11:32:32 -0800318 { kITypeMask, 53u << kOpcodeShift, "ldc1", "tO", },
Alexey Frunze4dda3372015-06-01 18:31:49 -0700319 { kITypeMask | (0x1f << 21), 54u << kOpcodeShift, "jic", "Ti" },
320 { kITypeMask | (1 << 21), (54u << kOpcodeShift) | (1 << 21), "beqzc", "Sb" }, // TODO: de-dup?
321 { kITypeMask | (1 << 22), (54u << kOpcodeShift) | (1 << 22), "beqzc", "Sb" },
322 { kITypeMask | (1 << 23), (54u << kOpcodeShift) | (1 << 23), "beqzc", "Sb" },
323 { kITypeMask | (1 << 24), (54u << kOpcodeShift) | (1 << 24), "beqzc", "Sb" },
324 { kITypeMask | (1 << 25), (54u << kOpcodeShift) | (1 << 25), "beqzc", "Sb" },
Goran Jakovljevic403e0d52015-04-08 16:26:05 +0200325 { kITypeMask, 55u << kOpcodeShift, "ld", "TO", },
Brian Carlstromd74e41b2013-03-24 23:47:01 -0700326 { kITypeMask, 57u << kOpcodeShift, "swc1", "tO", },
Alexey Frunze4dda3372015-06-01 18:31:49 -0700327 { kITypeMask | (0x1f << 16), (59u << kOpcodeShift) | (30 << 16), "auipc", "Si" },
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200328 { kITypeMask | (0x3 << 19), (59u << kOpcodeShift) | (0 << 19), "addiupc", "Sp" },
Andreas Gampe8d365912015-01-13 11:32:32 -0800329 { kITypeMask, 61u << kOpcodeShift, "sdc1", "tO", },
Alexey Frunze4dda3372015-06-01 18:31:49 -0700330 { kITypeMask | (0x1f << 21), 62u << kOpcodeShift, "jialc", "Ti" },
331 { kITypeMask | (1 << 21), (62u << kOpcodeShift) | (1 << 21), "bnezc", "Sb" }, // TODO: de-dup?
332 { kITypeMask | (1 << 22), (62u << kOpcodeShift) | (1 << 22), "bnezc", "Sb" },
333 { kITypeMask | (1 << 23), (62u << kOpcodeShift) | (1 << 23), "bnezc", "Sb" },
334 { kITypeMask | (1 << 24), (62u << kOpcodeShift) | (1 << 24), "bnezc", "Sb" },
335 { kITypeMask | (1 << 25), (62u << kOpcodeShift) | (1 << 25), "bnezc", "Sb" },
Goran Jakovljevic403e0d52015-04-08 16:26:05 +0200336 { kITypeMask, 63u << kOpcodeShift, "sd", "TO", },
Elliott Hughes60454e82012-04-25 12:56:03 -0700337
338 // Floating point.
Goran Jakovljevic403e0d52015-04-08 16:26:05 +0200339 { kFpMask | (0x1f << 21), kCop1 | (0x00 << 21), "mfc1", "Td" },
340 { kFpMask | (0x1f << 21), kCop1 | (0x01 << 21), "dmfc1", "Td" },
341 { kFpMask | (0x1f << 21), kCop1 | (0x03 << 21), "mfhc1", "Td" },
342 { kFpMask | (0x1f << 21), kCop1 | (0x04 << 21), "mtc1", "Td" },
343 { kFpMask | (0x1f << 21), kCop1 | (0x05 << 21), "dmtc1", "Td" },
344 { kFpMask | (0x1f << 21), kCop1 | (0x07 << 21), "mthc1", "Td" },
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800345 { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 1, "cmp.un.s", "adt" },
346 { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 2, "cmp.eq.s", "adt" },
347 { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 3, "cmp.ueq.s", "adt" },
348 { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 4, "cmp.lt.s", "adt" },
349 { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 5, "cmp.ult.s", "adt" },
350 { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 6, "cmp.le.s", "adt" },
351 { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 7, "cmp.ule.s", "adt" },
352 { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 17, "cmp.or.s", "adt" },
353 { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 18, "cmp.une.s", "adt" },
354 { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 19, "cmp.ne.s", "adt" },
355 { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 1, "cmp.un.d", "adt" },
356 { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 2, "cmp.eq.d", "adt" },
357 { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 3, "cmp.ueq.d", "adt" },
358 { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 4, "cmp.lt.d", "adt" },
359 { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 5, "cmp.ult.d", "adt" },
360 { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 6, "cmp.le.d", "adt" },
361 { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 7, "cmp.ule.d", "adt" },
362 { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 17, "cmp.or.d", "adt" },
363 { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 18, "cmp.une.d", "adt" },
364 { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 19, "cmp.ne.d", "adt" },
Douglas Leung1cd27902015-02-13 16:55:57 -0800365 { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 0, "add", "fadt" },
366 { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 1, "sub", "fadt" },
367 { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 2, "mul", "fadt" },
368 { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 3, "div", "fadt" },
369 { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 4, "sqrt", "fad" },
370 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 5, "abs", "fad" },
371 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 6, "mov", "fad" },
372 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 7, "neg", "fad" },
373 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 8, "round.l", "fad" },
374 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 9, "trunc.l", "fad" },
375 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 10, "ceil.l", "fad" },
376 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 11, "floor.l", "fad" },
377 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 12, "round.w", "fad" },
378 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 13, "trunc.w", "fad" },
379 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 14, "ceil.w", "fad" },
380 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 15, "floor.w", "fad" },
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700381 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 26, "rint", "fad" },
382 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 27, "class", "fad" },
Douglas Leung1cd27902015-02-13 16:55:57 -0800383 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 32, "cvt.s", "fad" },
384 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 33, "cvt.d", "fad" },
385 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 36, "cvt.w", "fad" },
386 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 37, "cvt.l", "fad" },
387 { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 38, "cvt.ps", "fad" },
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800388 { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 49, "c.un", "fCdt" },
389 { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 50, "c.eq", "fCdt" },
390 { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 51, "c.ueq", "fCdt" },
391 { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 52, "c.olt", "fCdt" },
392 { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 53, "c.ult", "fCdt" },
393 { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 54, "c.ole", "fCdt" },
394 { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 55, "c.ule", "fCdt" },
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700395 { kFpMask, kCop1 | 0x10, "sel", "fadt" },
396 { kFpMask, kCop1 | 0x1e, "max", "fadt" },
397 { kFpMask, kCop1 | 0x1c, "min", "fadt" },
Elliott Hughes60454e82012-04-25 12:56:03 -0700398};
399
400static uint32_t ReadU32(const uint8_t* ptr) {
jeffhao4f8f04a2012-10-02 18:10:35 -0700401 // We only support little-endian MIPS.
402 return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24);
Elliott Hughes60454e82012-04-25 12:56:03 -0700403}
404
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700405size_t DisassemblerMips::Dump(std::ostream& os, const uint8_t* instr_ptr) {
Elliott Hughes60454e82012-04-25 12:56:03 -0700406 uint32_t instruction = ReadU32(instr_ptr);
407
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700408 uint32_t rs = (instruction >> 21) & 0x1f; // I-type, R-type.
409 uint32_t rt = (instruction >> 16) & 0x1f; // I-type, R-type.
410 uint32_t rd = (instruction >> 11) & 0x1f; // R-type.
411 uint32_t sa = (instruction >> 6) & 0x1f; // R-type.
Elliott Hughes60454e82012-04-25 12:56:03 -0700412
413 std::string opcode;
414 std::ostringstream args;
415
416 // TODO: remove this!
417 uint32_t op = (instruction >> 26) & 0x3f;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700418 uint32_t function = (instruction & 0x3f); // R-type.
Elliott Hughes60454e82012-04-25 12:56:03 -0700419 opcode = StringPrintf("op=%d fn=%d", op, function);
420
421 for (size_t i = 0; i < arraysize(gMipsInstructions); ++i) {
422 if (gMipsInstructions[i].Matches(instruction)) {
423 opcode = gMipsInstructions[i].name;
424 for (const char* args_fmt = gMipsInstructions[i].args_fmt; *args_fmt; ++args_fmt) {
425 switch (*args_fmt) {
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800426 case 'A': // sa (shift amount or [d]ins/[d]ext position).
Elliott Hughes60454e82012-04-25 12:56:03 -0700427 args << sa;
428 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700429 case 'B': // Branch offset.
Elliott Hughes60454e82012-04-25 12:56:03 -0700430 {
431 int32_t offset = static_cast<int16_t>(instruction & 0xffff);
432 offset <<= 2;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700433 offset += 4; // Delay slot.
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700434 args << FormatInstructionPointer(instr_ptr + offset)
435 << StringPrintf(" ; %+d", offset);
Elliott Hughes60454e82012-04-25 12:56:03 -0700436 }
437 break;
Alexey Frunze4dda3372015-06-01 18:31:49 -0700438 case 'b': // 21-bit branch offset.
439 {
440 int32_t offset = (instruction & 0x1fffff) - ((instruction & 0x100000) << 1);
441 offset <<= 2;
442 offset += 4; // Delay slot.
443 args << FormatInstructionPointer(instr_ptr + offset)
444 << StringPrintf(" ; %+d", offset);
445 }
446 break;
Alexey Frunzecd7b0ee2015-12-03 16:46:38 -0800447 case 'C': // Floating-point condition code flag in c.<cond>.fmt.
448 args << "cc" << (sa >> 2);
449 break;
450 case 'c': // Floating-point condition code flag in bc1f/bc1t and movf/movt.
451 args << "cc" << (rt >> 2);
452 break;
Elliott Hughes60454e82012-04-25 12:56:03 -0700453 case 'D': args << 'r' << rd; break;
454 case 'd': args << 'f' << rd; break;
Douglas Leung1cd27902015-02-13 16:55:57 -0800455 case 'a': args << 'f' << sa; break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700456 case 'f': // Floating point "fmt".
Elliott Hughes60454e82012-04-25 12:56:03 -0700457 {
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700458 size_t fmt = (instruction >> 21) & 0x7; // TODO: other fmts?
Elliott Hughes60454e82012-04-25 12:56:03 -0700459 switch (fmt) {
460 case 0: opcode += ".s"; break;
461 case 1: opcode += ".d"; break;
462 case 4: opcode += ".w"; break;
463 case 5: opcode += ".l"; break;
464 case 6: opcode += ".ps"; break;
465 default: opcode += ".?"; break;
466 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700467 continue; // No ", ".
Elliott Hughes60454e82012-04-25 12:56:03 -0700468 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700469 case 'I': // Upper 16-bit immediate.
Elliott Hughes60454e82012-04-25 12:56:03 -0700470 args << reinterpret_cast<void*>((instruction & 0xffff) << 16);
471 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700472 case 'i': // Sign-extended lower 16-bit immediate.
Elliott Hughes60454e82012-04-25 12:56:03 -0700473 args << static_cast<int16_t>(instruction & 0xffff);
474 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700475 case 'L': // Jump label.
Elliott Hughes60454e82012-04-25 12:56:03 -0700476 {
477 // TODO: is this right?
478 uint32_t instr_index = (instruction & 0x1ffffff);
479 uint32_t target = (instr_index << 2);
480 target |= (reinterpret_cast<uintptr_t>(instr_ptr + 4) & 0xf0000000);
481 args << reinterpret_cast<void*>(target);
482 }
483 break;
Chris Larsen2fadd7b2015-08-14 14:56:10 -0700484 case 'l': // 9-bit signed offset
485 {
486 int32_t offset = static_cast<int16_t>(instruction) >> 7;
487 args << StringPrintf("%+d(r%d)", offset, rs);
488 }
489 break;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700490 case 'O': // +x(rs)
Elliott Hughes60454e82012-04-25 12:56:03 -0700491 {
492 int32_t offset = static_cast<int16_t>(instruction & 0xffff);
493 args << StringPrintf("%+d(r%d)", offset, rs);
494 if (rs == 17) {
495 args << " ; ";
Goran Jakovljevic403e0d52015-04-08 16:26:05 +0200496 if (is64bit_) {
497 Thread::DumpThreadOffset<8>(args, offset);
498 } else {
499 Thread::DumpThreadOffset<4>(args, offset);
500 }
Elliott Hughes60454e82012-04-25 12:56:03 -0700501 }
502 }
503 break;
Goran Jakovljevic8c434dc2015-08-26 14:39:44 +0200504 case 'P': // 26-bit offset in bc.
505 {
506 int32_t offset = (instruction & 0x3ffffff) - ((instruction & 0x2000000) << 1);
507 offset <<= 2;
508 offset += 4;
509 args << FormatInstructionPointer(instr_ptr + offset);
510 args << StringPrintf(" ; %+d", offset);
511 }
512 break;
513 case 'p': // 19-bit offset in addiupc.
514 {
515 int32_t offset = (instruction & 0x7ffff) - ((instruction & 0x40000) << 1);
516 args << offset << " ; move r" << rs << ", ";
517 args << FormatInstructionPointer(instr_ptr + (offset << 2));
518 }
519 break;
Elliott Hughes60454e82012-04-25 12:56:03 -0700520 case 'S': args << 'r' << rs; break;
521 case 's': args << 'f' << rs; break;
522 case 'T': args << 'r' << rt; break;
523 case 't': args << 'f' << rt; break;
Alexey Frunze5c7aed32015-11-25 19:41:54 -0800524 case 'Z': args << (rd + 1); break; // sz ([d]ext size).
525 case 'z': args << (rd - sa + 1); break; // sz ([d]ins size).
Elliott Hughes60454e82012-04-25 12:56:03 -0700526 }
527 if (*(args_fmt + 1)) {
528 args << ", ";
529 }
530 }
531 break;
532 }
533 }
534
Alexey Frunze4dda3372015-06-01 18:31:49 -0700535 // Special cases for sequences of:
536 // pc-relative +/- 2GB branch:
537 // auipc reg, imm
538 // jic reg, imm
539 // pc-relative +/- 2GB branch and link:
540 // auipc reg, imm
541 // daddiu reg, reg, imm
542 // jialc reg, 0
543 if (((op == 0x36 && rs == 0 && rt != 0) || // jic
544 (op == 0x19 && rs == rt && rt != 0)) && // daddiu
545 last_ptr_ && (intptr_t)instr_ptr - (intptr_t)last_ptr_ == 4 &&
546 (last_instr_ & 0xFC1F0000) == 0xEC1E0000 && // auipc
547 ((last_instr_ >> 21) & 0x1F) == rt) {
548 uint32_t offset = (last_instr_ << 16) | (instruction & 0xFFFF);
549 offset -= (offset & 0x8000) << 1;
550 offset -= 4;
551 if (op == 0x36) {
552 args << " ; b ";
553 } else {
554 args << " ; move r" << rt << ", ";
555 }
556 args << FormatInstructionPointer(instr_ptr + (int32_t)offset);
557 args << StringPrintf(" ; %+d", (int32_t)offset);
558 }
559
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700560 os << FormatInstructionPointer(instr_ptr)
561 << StringPrintf(": %08x\t%-7s ", instruction, opcode.c_str())
562 << args.str() << '\n';
Alexey Frunze4dda3372015-06-01 18:31:49 -0700563 last_ptr_ = instr_ptr;
564 last_instr_ = instruction;
Ian Rogersb23a7722012-10-09 16:54:26 -0700565 return 4;
566}
567
Elliott Hughes60454e82012-04-25 12:56:03 -0700568void DisassemblerMips::Dump(std::ostream& os, const uint8_t* begin, const uint8_t* end) {
569 for (const uint8_t* cur = begin; cur < end; cur += 4) {
Brian Carlstrom2cbaccb2014-09-14 20:34:17 -0700570 Dump(os, cur);
Elliott Hughes60454e82012-04-25 12:56:03 -0700571 }
572}
573
574} // namespace mips
575} // namespace art