Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 1 | /* |
| 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 Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 19 | #include <ostream> |
Ian Rogers | c7dd295 | 2014-10-21 23:31:19 -0700 | [diff] [blame] | 20 | #include <sstream> |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 21 | |
Andreas Gampe | bda1d60 | 2016-08-29 17:43:45 -0700 | [diff] [blame^] | 22 | #include "android-base/logging.h" |
| 23 | #include "android-base/stringprintf.h" |
| 24 | |
| 25 | using android::base::StringPrintf; |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | namespace mips { |
| 29 | |
| 30 | struct MipsInstruction { |
| 31 | uint32_t mask; |
| 32 | uint32_t value; |
| 33 | const char* name; |
| 34 | const char* args_fmt; |
| 35 | |
| 36 | bool Matches(uint32_t instruction) const { |
| 37 | return (instruction & mask) == value; |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | static const uint32_t kOpcodeShift = 26; |
| 42 | |
| 43 | static const uint32_t kCop1 = (17 << kOpcodeShift); |
| 44 | |
| 45 | static const uint32_t kITypeMask = (0x3f << kOpcodeShift); |
| 46 | static const uint32_t kJTypeMask = (0x3f << kOpcodeShift); |
| 47 | static const uint32_t kRTypeMask = ((0x3f << kOpcodeShift) | (0x3f)); |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 48 | static const uint32_t kSpecial0Mask = (0x3f << kOpcodeShift); |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 49 | static const uint32_t kSpecial2Mask = (0x3f << kOpcodeShift); |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 50 | static const uint32_t kSpecial3Mask = (0x3f << kOpcodeShift); |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 51 | static const uint32_t kFpMask = kRTypeMask; |
| 52 | |
| 53 | static const MipsInstruction gMipsInstructions[] = { |
| 54 | // "sll r0, r0, 0" is the canonical "nop", used in delay slots. |
| 55 | { 0xffffffff, 0, "nop", "" }, |
| 56 | |
| 57 | // R-type instructions. |
| 58 | { kRTypeMask, 0, "sll", "DTA", }, |
| 59 | // 0, 1, movci |
Alexey Frunze | 92d9060 | 2015-12-18 18:16:36 -0800 | [diff] [blame] | 60 | { kRTypeMask | (0x1f << 21), 2, "srl", "DTA", }, |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 61 | { kRTypeMask, 3, "sra", "DTA", }, |
Chris Larsen | 7d4152f | 2015-10-19 15:17:16 -0700 | [diff] [blame] | 62 | { kRTypeMask | (0x1f << 6), 4, "sllv", "DTS", }, |
| 63 | { kRTypeMask | (0x1f << 6), 6, "srlv", "DTS", }, |
| 64 | { kRTypeMask | (0x1f << 6), (1 << 6) | 6, "rotrv", "DTS", }, |
| 65 | { kRTypeMask | (0x1f << 6), 7, "srav", "DTS", }, |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 66 | { kRTypeMask, 8, "jr", "S", }, |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 67 | { kRTypeMask | (0x1f << 11), 9 | (31 << 11), "jalr", "S", }, // rd = 31 is implicit. |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 68 | { kRTypeMask | (0x1f << 11), 9, "jr", "S", }, // rd = 0 is implicit. |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 69 | { kRTypeMask, 9, "jalr", "DS", }, // General case. |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 70 | { kRTypeMask | (0x1f << 6), 10, "movz", "DST", }, |
| 71 | { kRTypeMask | (0x1f << 6), 11, "movn", "DST", }, |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 72 | { kRTypeMask, 12, "syscall", "", }, // TODO: code |
| 73 | { kRTypeMask, 13, "break", "", }, // TODO: code |
| 74 | { kRTypeMask, 15, "sync", "", }, // TODO: type |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 75 | { kRTypeMask, 16, "mfhi", "D", }, |
| 76 | { kRTypeMask, 17, "mthi", "S", }, |
| 77 | { kRTypeMask, 18, "mflo", "D", }, |
| 78 | { kRTypeMask, 19, "mtlo", "S", }, |
Chris Larsen | 7d4152f | 2015-10-19 15:17:16 -0700 | [diff] [blame] | 79 | { kRTypeMask | (0x1f << 6), 20, "dsllv", "DTS", }, |
| 80 | { kRTypeMask | (0x1f << 6), 22, "dsrlv", "DTS", }, |
| 81 | { kRTypeMask | (0x1f << 6), (1 << 6) | 22, "drotrv", "DTS", }, |
| 82 | { kRTypeMask | (0x1f << 6), 23, "dsrav", "DTS", }, |
Douglas Leung | 027f0ff | 2015-02-27 19:05:03 -0800 | [diff] [blame] | 83 | { kRTypeMask | (0x1f << 6), 24, "mult", "ST", }, |
| 84 | { kRTypeMask | (0x1f << 6), 25, "multu", "ST", }, |
| 85 | { kRTypeMask | (0x1f << 6), 26, "div", "ST", }, |
| 86 | { kRTypeMask | (0x1f << 6), 27, "divu", "ST", }, |
| 87 | { kRTypeMask | (0x1f << 6), 24 + (2 << 6), "mul", "DST", }, |
| 88 | { kRTypeMask | (0x1f << 6), 24 + (3 << 6), "muh", "DST", }, |
| 89 | { kRTypeMask | (0x1f << 6), 26 + (2 << 6), "div", "DST", }, |
| 90 | { kRTypeMask | (0x1f << 6), 26 + (3 << 6), "mod", "DST", }, |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 91 | { kRTypeMask, 32, "add", "DST", }, |
| 92 | { kRTypeMask, 33, "addu", "DST", }, |
| 93 | { kRTypeMask, 34, "sub", "DST", }, |
| 94 | { kRTypeMask, 35, "subu", "DST", }, |
| 95 | { kRTypeMask, 36, "and", "DST", }, |
| 96 | { kRTypeMask, 37, "or", "DST", }, |
| 97 | { kRTypeMask, 38, "xor", "DST", }, |
| 98 | { kRTypeMask, 39, "nor", "DST", }, |
| 99 | { kRTypeMask, 42, "slt", "DST", }, |
| 100 | { kRTypeMask, 43, "sltu", "DST", }, |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 101 | { kRTypeMask, 45, "daddu", "DST", }, |
| 102 | { kRTypeMask, 46, "dsub", "DST", }, |
| 103 | { kRTypeMask, 47, "dsubu", "DST", }, |
| 104 | // TODO: tge[u], tlt[u], teg, tne |
Chris Larsen | 7d4152f | 2015-10-19 15:17:16 -0700 | [diff] [blame] | 105 | { kRTypeMask | (0x1f << 21), 56, "dsll", "DTA", }, |
| 106 | { kRTypeMask | (0x1f << 21), 58, "dsrl", "DTA", }, |
| 107 | { kRTypeMask | (0x1f << 21), (1 << 21) | 58, "drotr", "DTA", }, |
| 108 | { kRTypeMask | (0x1f << 21), 59, "dsra", "DTA", }, |
| 109 | { kRTypeMask | (0x1f << 21), 60, "dsll32", "DTA", }, |
| 110 | { kRTypeMask | (0x1f << 21), 62, "dsrl32", "DTA", }, |
| 111 | { kRTypeMask | (0x1f << 21), (1 << 21) | 62, "drotr32", "DTA", }, |
| 112 | { kRTypeMask | (0x1f << 21), 63, "dsra32", "DTA", }, |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 113 | |
| 114 | // SPECIAL0 |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 115 | { kSpecial0Mask | 0x307ff, 1, "movf", "DSc" }, |
| 116 | { kSpecial0Mask | 0x307ff, 0x10001, "movt", "DSc" }, |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 117 | { kSpecial0Mask | 0x7ff, (2 << 6) | 24, "mul", "DST" }, |
| 118 | { kSpecial0Mask | 0x7ff, (3 << 6) | 24, "muh", "DST" }, |
| 119 | { kSpecial0Mask | 0x7ff, (2 << 6) | 25, "mulu", "DST" }, |
| 120 | { kSpecial0Mask | 0x7ff, (3 << 6) | 25, "muhu", "DST" }, |
| 121 | { kSpecial0Mask | 0x7ff, (2 << 6) | 26, "div", "DST" }, |
| 122 | { kSpecial0Mask | 0x7ff, (3 << 6) | 26, "mod", "DST" }, |
| 123 | { kSpecial0Mask | 0x7ff, (2 << 6) | 27, "divu", "DST" }, |
| 124 | { kSpecial0Mask | 0x7ff, (3 << 6) | 27, "modu", "DST" }, |
| 125 | { kSpecial0Mask | 0x7ff, (2 << 6) | 28, "dmul", "DST" }, |
| 126 | { kSpecial0Mask | 0x7ff, (3 << 6) | 28, "dmuh", "DST" }, |
| 127 | { kSpecial0Mask | 0x7ff, (2 << 6) | 29, "dmulu", "DST" }, |
| 128 | { kSpecial0Mask | 0x7ff, (3 << 6) | 29, "dmuhu", "DST" }, |
| 129 | { kSpecial0Mask | 0x7ff, (2 << 6) | 30, "ddiv", "DST" }, |
| 130 | { kSpecial0Mask | 0x7ff, (3 << 6) | 30, "dmod", "DST" }, |
| 131 | { kSpecial0Mask | 0x7ff, (2 << 6) | 31, "ddivu", "DST" }, |
| 132 | { kSpecial0Mask | 0x7ff, (3 << 6) | 31, "dmodu", "DST" }, |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 133 | { kSpecial0Mask | 0x7ff, (0 << 6) | 53, "seleqz", "DST" }, |
| 134 | { kSpecial0Mask | 0x7ff, (0 << 6) | 55, "selnez", "DST" }, |
| 135 | { kSpecial0Mask | (0x1f << 21) | 0x3f, (1 << 21) | 2, "rotr", "DTA", }, |
| 136 | { kSpecial0Mask | (0x1f << 16) | 0x7ff, (0x01 << 6) | 0x10, "clz", "DS" }, |
| 137 | { kSpecial0Mask | (0x1f << 16) | 0x7ff, (0x01 << 6) | 0x11, "clo", "DS" }, |
| 138 | { kSpecial0Mask | (0x1f << 16) | 0x7ff, (0x01 << 6) | 0x12, "dclz", "DS" }, |
| 139 | { kSpecial0Mask | (0x1f << 16) | 0x7ff, (0x01 << 6) | 0x13, "dclo", "DS" }, |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 140 | // TODO: sdbbp |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 141 | |
| 142 | // SPECIAL2 |
| 143 | { kSpecial2Mask | 0x7ff, (28 << kOpcodeShift) | 2, "mul", "DST" }, |
| 144 | { kSpecial2Mask | 0x7ff, (28 << kOpcodeShift) | 32, "clz", "DS" }, |
Chris Larsen | e384547 | 2015-11-18 12:27:15 -0800 | [diff] [blame] | 145 | { kSpecial2Mask | 0x7ff, (28 << kOpcodeShift) | 33, "clo", "DS" }, |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 146 | { kSpecial2Mask | 0xffff, (28 << kOpcodeShift) | 0, "madd", "ST" }, |
| 147 | { kSpecial2Mask | 0xffff, (28 << kOpcodeShift) | 1, "maddu", "ST" }, |
| 148 | { kSpecial2Mask | 0xffff, (28 << kOpcodeShift) | 2, "mul", "DST" }, |
| 149 | { kSpecial2Mask | 0xffff, (28 << kOpcodeShift) | 4, "msub", "ST" }, |
| 150 | { kSpecial2Mask | 0xffff, (28 << kOpcodeShift) | 5, "msubu", "ST" }, |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 151 | { kSpecial2Mask | 0x3f, (28 << kOpcodeShift) | 0x3f, "sdbbp", "" }, // TODO: code |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 152 | |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 153 | // SPECIAL3 |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 154 | { kSpecial3Mask | 0x3f, (31 << kOpcodeShift), "ext", "TSAZ", }, |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 155 | { kSpecial3Mask | 0x3f, (31 << kOpcodeShift) | 3, "dext", "TSAZ", }, |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 156 | { kSpecial3Mask | 0x3f, (31 << kOpcodeShift) | 4, "ins", "TSAz", }, |
Chris Larsen | e384547 | 2015-11-18 12:27:15 -0800 | [diff] [blame] | 157 | { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f, |
| 158 | (31 << kOpcodeShift) | (16 << 6) | 32, |
| 159 | "seb", |
| 160 | "DT", }, |
| 161 | { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f, |
| 162 | (31 << kOpcodeShift) | (24 << 6) | 32, |
| 163 | "seh", |
| 164 | "DT", }, |
| 165 | { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f, |
| 166 | (31 << kOpcodeShift) | 32, |
| 167 | "bitswap", |
| 168 | "DT", }, |
| 169 | { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f, |
| 170 | (31 << kOpcodeShift) | 36, |
| 171 | "dbitswap", |
| 172 | "DT", }, |
| 173 | { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f, |
| 174 | (31 << kOpcodeShift) | (2 << 6) | 36, |
| 175 | "dsbh", |
| 176 | "DT", }, |
| 177 | { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f, |
| 178 | (31 << kOpcodeShift) | (5 << 6) | 36, |
| 179 | "dshd", |
| 180 | "DT", }, |
| 181 | { kSpecial3Mask | (0x1f << 21) | (0x1f << 6) | 0x3f, |
| 182 | (31 << kOpcodeShift) | (2 << 6) | 32, |
| 183 | "wsbh", |
| 184 | "DT", }, |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 185 | { kSpecial3Mask | 0x7f, (31 << kOpcodeShift) | 0x26, "sc", "Tl", }, |
| 186 | { kSpecial3Mask | 0x7f, (31 << kOpcodeShift) | 0x27, "scd", "Tl", }, |
| 187 | { kSpecial3Mask | 0x7f, (31 << kOpcodeShift) | 0x36, "ll", "Tl", }, |
| 188 | { kSpecial3Mask | 0x7f, (31 << kOpcodeShift) | 0x37, "lld", "Tl", }, |
| 189 | |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 190 | // J-type instructions. |
| 191 | { kJTypeMask, 2 << kOpcodeShift, "j", "L" }, |
| 192 | { kJTypeMask, 3 << kOpcodeShift, "jal", "L" }, |
| 193 | |
| 194 | // I-type instructions. |
| 195 | { kITypeMask, 4 << kOpcodeShift, "beq", "STB" }, |
| 196 | { kITypeMask, 5 << kOpcodeShift, "bne", "STB" }, |
| 197 | { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (1 << 16), "bgez", "SB" }, |
| 198 | { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (0 << 16), "bltz", "SB" }, |
| 199 | { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (2 << 16), "bltzl", "SB" }, |
| 200 | { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (16 << 16), "bltzal", "SB" }, |
| 201 | { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (18 << 16), "bltzall", "SB" }, |
| 202 | { kITypeMask | (0x1f << 16), 6 << kOpcodeShift | (0 << 16), "blez", "SB" }, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 203 | { kITypeMask, 6 << kOpcodeShift, "bgeuc", "STB" }, |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 204 | { kITypeMask | (0x1f << 16), 7 << kOpcodeShift | (0 << 16), "bgtz", "SB" }, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 205 | { kITypeMask, 7 << kOpcodeShift, "bltuc", "STB" }, |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 206 | { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (6 << 16), "dahi", "Si", }, |
| 207 | { kITypeMask | (0x1f << 16), 1 << kOpcodeShift | (30 << 16), "dati", "Si", }, |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 208 | |
| 209 | { 0xffff0000, (4 << kOpcodeShift), "b", "B" }, |
| 210 | { 0xffff0000, (1 << kOpcodeShift) | (17 << 16), "bal", "B" }, |
| 211 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 212 | { kITypeMask, 8 << kOpcodeShift, "beqc", "STB" }, |
| 213 | |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 214 | { kITypeMask, 8 << kOpcodeShift, "addi", "TSi", }, |
| 215 | { kITypeMask, 9 << kOpcodeShift, "addiu", "TSi", }, |
| 216 | { kITypeMask, 10 << kOpcodeShift, "slti", "TSi", }, |
| 217 | { kITypeMask, 11 << kOpcodeShift, "sltiu", "TSi", }, |
| 218 | { kITypeMask, 12 << kOpcodeShift, "andi", "TSi", }, |
| 219 | { kITypeMask, 13 << kOpcodeShift, "ori", "TSi", }, |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 220 | { kITypeMask, 14 << kOpcodeShift, "xori", "TSi", }, |
| 221 | { kITypeMask | (0x1f << 21), 15 << kOpcodeShift, "lui", "TI", }, |
| 222 | { kITypeMask, 15 << kOpcodeShift, "aui", "TSI", }, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 223 | |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 224 | { kITypeMask | (0x3e3 << 16), (17 << kOpcodeShift) | (8 << 21), "bc1f", "cB" }, |
| 225 | { kITypeMask | (0x3e3 << 16), (17 << kOpcodeShift) | (8 << 21) | (1 << 16), "bc1t", "cB" }, |
| 226 | { kITypeMask | (0x1f << 21), (17 << kOpcodeShift) | (9 << 21), "bc1eqz", "tB" }, |
| 227 | { kITypeMask | (0x1f << 21), (17 << kOpcodeShift) | (13 << 21), "bc1nez", "tB" }, |
| 228 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 229 | { kITypeMask | (0x1f << 21), 22 << kOpcodeShift, "blezc", "TB" }, |
| 230 | |
| 231 | // TODO: de-dup |
| 232 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (1 << 21) | (1 << 16), "bgezc", "TB" }, |
| 233 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (2 << 21) | (2 << 16), "bgezc", "TB" }, |
| 234 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (3 << 21) | (3 << 16), "bgezc", "TB" }, |
| 235 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (4 << 21) | (4 << 16), "bgezc", "TB" }, |
| 236 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (5 << 21) | (5 << 16), "bgezc", "TB" }, |
| 237 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (6 << 21) | (6 << 16), "bgezc", "TB" }, |
| 238 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (7 << 21) | (7 << 16), "bgezc", "TB" }, |
| 239 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (8 << 21) | (8 << 16), "bgezc", "TB" }, |
| 240 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (9 << 21) | (9 << 16), "bgezc", "TB" }, |
| 241 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (10 << 21) | (10 << 16), "bgezc", "TB" }, |
| 242 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (11 << 21) | (11 << 16), "bgezc", "TB" }, |
| 243 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (12 << 21) | (12 << 16), "bgezc", "TB" }, |
| 244 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (13 << 21) | (13 << 16), "bgezc", "TB" }, |
| 245 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (14 << 21) | (14 << 16), "bgezc", "TB" }, |
| 246 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (15 << 21) | (15 << 16), "bgezc", "TB" }, |
| 247 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (16 << 21) | (16 << 16), "bgezc", "TB" }, |
| 248 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (17 << 21) | (17 << 16), "bgezc", "TB" }, |
| 249 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (18 << 21) | (18 << 16), "bgezc", "TB" }, |
| 250 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (19 << 21) | (19 << 16), "bgezc", "TB" }, |
| 251 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (20 << 21) | (20 << 16), "bgezc", "TB" }, |
| 252 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (21 << 21) | (21 << 16), "bgezc", "TB" }, |
| 253 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (22 << 21) | (22 << 16), "bgezc", "TB" }, |
| 254 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (23 << 21) | (23 << 16), "bgezc", "TB" }, |
| 255 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (24 << 21) | (24 << 16), "bgezc", "TB" }, |
| 256 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (25 << 21) | (25 << 16), "bgezc", "TB" }, |
| 257 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (26 << 21) | (26 << 16), "bgezc", "TB" }, |
| 258 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (27 << 21) | (27 << 16), "bgezc", "TB" }, |
| 259 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (28 << 21) | (28 << 16), "bgezc", "TB" }, |
| 260 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (29 << 21) | (29 << 16), "bgezc", "TB" }, |
| 261 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (30 << 21) | (30 << 16), "bgezc", "TB" }, |
| 262 | { kITypeMask | (0x3ff << 16), (22 << kOpcodeShift) | (31 << 21) | (31 << 16), "bgezc", "TB" }, |
| 263 | |
| 264 | { kITypeMask, 22 << kOpcodeShift, "bgec", "STB" }, |
| 265 | |
| 266 | { kITypeMask | (0x1f << 21), 23 << kOpcodeShift, "bgtzc", "TB" }, |
| 267 | |
| 268 | // TODO: de-dup |
| 269 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (1 << 21) | (1 << 16), "bltzc", "TB" }, |
| 270 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (2 << 21) | (2 << 16), "bltzc", "TB" }, |
| 271 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (3 << 21) | (3 << 16), "bltzc", "TB" }, |
| 272 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (4 << 21) | (4 << 16), "bltzc", "TB" }, |
| 273 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (5 << 21) | (5 << 16), "bltzc", "TB" }, |
| 274 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (6 << 21) | (6 << 16), "bltzc", "TB" }, |
| 275 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (7 << 21) | (7 << 16), "bltzc", "TB" }, |
| 276 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (8 << 21) | (8 << 16), "bltzc", "TB" }, |
| 277 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (9 << 21) | (9 << 16), "bltzc", "TB" }, |
| 278 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (10 << 21) | (10 << 16), "bltzc", "TB" }, |
| 279 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (11 << 21) | (11 << 16), "bltzc", "TB" }, |
| 280 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (12 << 21) | (12 << 16), "bltzc", "TB" }, |
| 281 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (13 << 21) | (13 << 16), "bltzc", "TB" }, |
| 282 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (14 << 21) | (14 << 16), "bltzc", "TB" }, |
| 283 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (15 << 21) | (15 << 16), "bltzc", "TB" }, |
| 284 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (16 << 21) | (16 << 16), "bltzc", "TB" }, |
| 285 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (17 << 21) | (17 << 16), "bltzc", "TB" }, |
| 286 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (18 << 21) | (18 << 16), "bltzc", "TB" }, |
| 287 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (19 << 21) | (19 << 16), "bltzc", "TB" }, |
| 288 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (20 << 21) | (20 << 16), "bltzc", "TB" }, |
| 289 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (21 << 21) | (21 << 16), "bltzc", "TB" }, |
| 290 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (22 << 21) | (22 << 16), "bltzc", "TB" }, |
| 291 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (23 << 21) | (23 << 16), "bltzc", "TB" }, |
| 292 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (24 << 21) | (24 << 16), "bltzc", "TB" }, |
| 293 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (25 << 21) | (25 << 16), "bltzc", "TB" }, |
| 294 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (26 << 21) | (26 << 16), "bltzc", "TB" }, |
| 295 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (27 << 21) | (27 << 16), "bltzc", "TB" }, |
| 296 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (28 << 21) | (28 << 16), "bltzc", "TB" }, |
| 297 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (29 << 21) | (29 << 16), "bltzc", "TB" }, |
| 298 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (30 << 21) | (30 << 16), "bltzc", "TB" }, |
| 299 | { kITypeMask | (0x3ff << 16), (23 << kOpcodeShift) | (31 << 21) | (31 << 16), "bltzc", "TB" }, |
| 300 | |
| 301 | { kITypeMask, 23 << kOpcodeShift, "bltc", "STB" }, |
| 302 | |
| 303 | { kITypeMask, 24 << kOpcodeShift, "bnec", "STB" }, |
| 304 | |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 305 | { kITypeMask, 25 << kOpcodeShift, "daddiu", "TSi", }, |
| 306 | { kITypeMask, 29 << kOpcodeShift, "daui", "TSi", }, |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 307 | |
Brian Carlstrom | d74e41b | 2013-03-24 23:47:01 -0700 | [diff] [blame] | 308 | { kITypeMask, 32u << kOpcodeShift, "lb", "TO", }, |
| 309 | { kITypeMask, 33u << kOpcodeShift, "lh", "TO", }, |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 310 | { kITypeMask, 34u << kOpcodeShift, "lwl", "TO", }, |
Brian Carlstrom | d74e41b | 2013-03-24 23:47:01 -0700 | [diff] [blame] | 311 | { kITypeMask, 35u << kOpcodeShift, "lw", "TO", }, |
| 312 | { kITypeMask, 36u << kOpcodeShift, "lbu", "TO", }, |
| 313 | { kITypeMask, 37u << kOpcodeShift, "lhu", "TO", }, |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 314 | { kITypeMask, 38u << kOpcodeShift, "lwr", "TO", }, |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 315 | { kITypeMask, 39u << kOpcodeShift, "lwu", "TO", }, |
Brian Carlstrom | d74e41b | 2013-03-24 23:47:01 -0700 | [diff] [blame] | 316 | { kITypeMask, 40u << kOpcodeShift, "sb", "TO", }, |
| 317 | { kITypeMask, 41u << kOpcodeShift, "sh", "TO", }, |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 318 | { kITypeMask, 42u << kOpcodeShift, "swl", "TO", }, |
Brian Carlstrom | d74e41b | 2013-03-24 23:47:01 -0700 | [diff] [blame] | 319 | { kITypeMask, 43u << kOpcodeShift, "sw", "TO", }, |
Chris Larsen | 3acee73 | 2015-11-18 13:31:08 -0800 | [diff] [blame] | 320 | { kITypeMask, 46u << kOpcodeShift, "swr", "TO", }, |
Alexey Frunze | 51aff3a | 2016-03-17 17:21:45 -0700 | [diff] [blame] | 321 | { kITypeMask, 48u << kOpcodeShift, "ll", "TO", }, |
Brian Carlstrom | d74e41b | 2013-03-24 23:47:01 -0700 | [diff] [blame] | 322 | { kITypeMask, 49u << kOpcodeShift, "lwc1", "tO", }, |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 323 | { kJTypeMask, 50u << kOpcodeShift, "bc", "P" }, |
Andreas Gampe | 8d36591 | 2015-01-13 11:32:32 -0800 | [diff] [blame] | 324 | { kITypeMask, 53u << kOpcodeShift, "ldc1", "tO", }, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 325 | { kITypeMask | (0x1f << 21), 54u << kOpcodeShift, "jic", "Ti" }, |
| 326 | { kITypeMask | (1 << 21), (54u << kOpcodeShift) | (1 << 21), "beqzc", "Sb" }, // TODO: de-dup? |
| 327 | { kITypeMask | (1 << 22), (54u << kOpcodeShift) | (1 << 22), "beqzc", "Sb" }, |
| 328 | { kITypeMask | (1 << 23), (54u << kOpcodeShift) | (1 << 23), "beqzc", "Sb" }, |
| 329 | { kITypeMask | (1 << 24), (54u << kOpcodeShift) | (1 << 24), "beqzc", "Sb" }, |
| 330 | { kITypeMask | (1 << 25), (54u << kOpcodeShift) | (1 << 25), "beqzc", "Sb" }, |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 331 | { kITypeMask, 55u << kOpcodeShift, "ld", "TO", }, |
Alexey Frunze | 51aff3a | 2016-03-17 17:21:45 -0700 | [diff] [blame] | 332 | { kITypeMask, 56u << kOpcodeShift, "sc", "TO", }, |
Brian Carlstrom | d74e41b | 2013-03-24 23:47:01 -0700 | [diff] [blame] | 333 | { kITypeMask, 57u << kOpcodeShift, "swc1", "tO", }, |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 334 | { kJTypeMask, 58u << kOpcodeShift, "balc", "P" }, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 335 | { kITypeMask | (0x1f << 16), (59u << kOpcodeShift) | (30 << 16), "auipc", "Si" }, |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 336 | { kITypeMask | (0x3 << 19), (59u << kOpcodeShift) | (0 << 19), "addiupc", "Sp" }, |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 337 | { kITypeMask | (0x3 << 19), (59u << kOpcodeShift) | (1 << 19), "lwpc", "So" }, |
Andreas Gampe | 8d36591 | 2015-01-13 11:32:32 -0800 | [diff] [blame] | 338 | { kITypeMask, 61u << kOpcodeShift, "sdc1", "tO", }, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 339 | { kITypeMask | (0x1f << 21), 62u << kOpcodeShift, "jialc", "Ti" }, |
| 340 | { kITypeMask | (1 << 21), (62u << kOpcodeShift) | (1 << 21), "bnezc", "Sb" }, // TODO: de-dup? |
| 341 | { kITypeMask | (1 << 22), (62u << kOpcodeShift) | (1 << 22), "bnezc", "Sb" }, |
| 342 | { kITypeMask | (1 << 23), (62u << kOpcodeShift) | (1 << 23), "bnezc", "Sb" }, |
| 343 | { kITypeMask | (1 << 24), (62u << kOpcodeShift) | (1 << 24), "bnezc", "Sb" }, |
| 344 | { kITypeMask | (1 << 25), (62u << kOpcodeShift) | (1 << 25), "bnezc", "Sb" }, |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 345 | { kITypeMask, 63u << kOpcodeShift, "sd", "TO", }, |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 346 | |
| 347 | // Floating point. |
Goran Jakovljevic | 403e0d5 | 2015-04-08 16:26:05 +0200 | [diff] [blame] | 348 | { kFpMask | (0x1f << 21), kCop1 | (0x00 << 21), "mfc1", "Td" }, |
| 349 | { kFpMask | (0x1f << 21), kCop1 | (0x01 << 21), "dmfc1", "Td" }, |
| 350 | { kFpMask | (0x1f << 21), kCop1 | (0x03 << 21), "mfhc1", "Td" }, |
| 351 | { kFpMask | (0x1f << 21), kCop1 | (0x04 << 21), "mtc1", "Td" }, |
| 352 | { kFpMask | (0x1f << 21), kCop1 | (0x05 << 21), "dmtc1", "Td" }, |
| 353 | { kFpMask | (0x1f << 21), kCop1 | (0x07 << 21), "mthc1", "Td" }, |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 354 | { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 1, "cmp.un.s", "adt" }, |
| 355 | { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 2, "cmp.eq.s", "adt" }, |
| 356 | { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 3, "cmp.ueq.s", "adt" }, |
| 357 | { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 4, "cmp.lt.s", "adt" }, |
| 358 | { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 5, "cmp.ult.s", "adt" }, |
| 359 | { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 6, "cmp.le.s", "adt" }, |
| 360 | { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 7, "cmp.ule.s", "adt" }, |
| 361 | { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 17, "cmp.or.s", "adt" }, |
| 362 | { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 18, "cmp.une.s", "adt" }, |
| 363 | { kFpMask | (0x1f << 21), kCop1 | (0x14 << 21) | 19, "cmp.ne.s", "adt" }, |
| 364 | { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 1, "cmp.un.d", "adt" }, |
| 365 | { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 2, "cmp.eq.d", "adt" }, |
| 366 | { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 3, "cmp.ueq.d", "adt" }, |
| 367 | { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 4, "cmp.lt.d", "adt" }, |
| 368 | { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 5, "cmp.ult.d", "adt" }, |
| 369 | { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 6, "cmp.le.d", "adt" }, |
| 370 | { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 7, "cmp.ule.d", "adt" }, |
| 371 | { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 17, "cmp.or.d", "adt" }, |
| 372 | { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 18, "cmp.une.d", "adt" }, |
| 373 | { kFpMask | (0x1f << 21), kCop1 | (0x15 << 21) | 19, "cmp.ne.d", "adt" }, |
Douglas Leung | 1cd2790 | 2015-02-13 16:55:57 -0800 | [diff] [blame] | 374 | { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 0, "add", "fadt" }, |
| 375 | { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 1, "sub", "fadt" }, |
| 376 | { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 2, "mul", "fadt" }, |
| 377 | { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 3, "div", "fadt" }, |
| 378 | { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 4, "sqrt", "fad" }, |
| 379 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 5, "abs", "fad" }, |
| 380 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 6, "mov", "fad" }, |
| 381 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 7, "neg", "fad" }, |
| 382 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 8, "round.l", "fad" }, |
| 383 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 9, "trunc.l", "fad" }, |
| 384 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 10, "ceil.l", "fad" }, |
| 385 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 11, "floor.l", "fad" }, |
| 386 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 12, "round.w", "fad" }, |
| 387 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 13, "trunc.w", "fad" }, |
| 388 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 14, "ceil.w", "fad" }, |
| 389 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 15, "floor.w", "fad" }, |
Alexey Frunze | a8aaf5a | 2016-06-27 14:48:20 -0700 | [diff] [blame] | 390 | { kFpMask | (0x201 << 16), kCop1 | (0x200 << 16) | 17, "movf", "fadc" }, |
| 391 | { kFpMask | (0x201 << 16), kCop1 | (0x201 << 16) | 17, "movt", "fadc" }, |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 392 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 26, "rint", "fad" }, |
| 393 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 27, "class", "fad" }, |
Douglas Leung | 1cd2790 | 2015-02-13 16:55:57 -0800 | [diff] [blame] | 394 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 32, "cvt.s", "fad" }, |
| 395 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 33, "cvt.d", "fad" }, |
| 396 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 36, "cvt.w", "fad" }, |
| 397 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 37, "cvt.l", "fad" }, |
| 398 | { kFpMask | (0x21f << 16), kCop1 | (0x200 << 16) | 38, "cvt.ps", "fad" }, |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 399 | { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 49, "c.un", "fCdt" }, |
| 400 | { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 50, "c.eq", "fCdt" }, |
| 401 | { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 51, "c.ueq", "fCdt" }, |
| 402 | { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 52, "c.olt", "fCdt" }, |
| 403 | { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 53, "c.ult", "fCdt" }, |
| 404 | { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 54, "c.ole", "fCdt" }, |
| 405 | { kFpMask | (0x10 << 21), kCop1 | (0x10 << 21) | 55, "c.ule", "fCdt" }, |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 406 | { kFpMask, kCop1 | 0x10, "sel", "fadt" }, |
| 407 | { kFpMask, kCop1 | 0x1e, "max", "fadt" }, |
| 408 | { kFpMask, kCop1 | 0x1c, "min", "fadt" }, |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 409 | }; |
| 410 | |
| 411 | static uint32_t ReadU32(const uint8_t* ptr) { |
jeffhao | 4f8f04a | 2012-10-02 18:10:35 -0700 | [diff] [blame] | 412 | // We only support little-endian MIPS. |
| 413 | return ptr[0] | (ptr[1] << 8) | (ptr[2] << 16) | (ptr[3] << 24); |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 416 | size_t DisassemblerMips::Dump(std::ostream& os, const uint8_t* instr_ptr) { |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 417 | uint32_t instruction = ReadU32(instr_ptr); |
| 418 | |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 419 | uint32_t rs = (instruction >> 21) & 0x1f; // I-type, R-type. |
| 420 | uint32_t rt = (instruction >> 16) & 0x1f; // I-type, R-type. |
| 421 | uint32_t rd = (instruction >> 11) & 0x1f; // R-type. |
| 422 | uint32_t sa = (instruction >> 6) & 0x1f; // R-type. |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 423 | |
| 424 | std::string opcode; |
| 425 | std::ostringstream args; |
| 426 | |
| 427 | // TODO: remove this! |
| 428 | uint32_t op = (instruction >> 26) & 0x3f; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 429 | uint32_t function = (instruction & 0x3f); // R-type. |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 430 | opcode = StringPrintf("op=%d fn=%d", op, function); |
| 431 | |
| 432 | for (size_t i = 0; i < arraysize(gMipsInstructions); ++i) { |
| 433 | if (gMipsInstructions[i].Matches(instruction)) { |
| 434 | opcode = gMipsInstructions[i].name; |
| 435 | for (const char* args_fmt = gMipsInstructions[i].args_fmt; *args_fmt; ++args_fmt) { |
| 436 | switch (*args_fmt) { |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 437 | case 'A': // sa (shift amount or [d]ins/[d]ext position). |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 438 | args << sa; |
| 439 | break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 440 | case 'B': // Branch offset. |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 441 | { |
| 442 | int32_t offset = static_cast<int16_t>(instruction & 0xffff); |
| 443 | offset <<= 2; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 444 | offset += 4; // Delay slot. |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 445 | args << FormatInstructionPointer(instr_ptr + offset) |
| 446 | << StringPrintf(" ; %+d", offset); |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 447 | } |
| 448 | break; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 449 | case 'b': // 21-bit branch offset. |
| 450 | { |
| 451 | int32_t offset = (instruction & 0x1fffff) - ((instruction & 0x100000) << 1); |
| 452 | offset <<= 2; |
| 453 | offset += 4; // Delay slot. |
| 454 | args << FormatInstructionPointer(instr_ptr + offset) |
| 455 | << StringPrintf(" ; %+d", offset); |
| 456 | } |
| 457 | break; |
Alexey Frunze | cd7b0ee | 2015-12-03 16:46:38 -0800 | [diff] [blame] | 458 | case 'C': // Floating-point condition code flag in c.<cond>.fmt. |
| 459 | args << "cc" << (sa >> 2); |
| 460 | break; |
| 461 | case 'c': // Floating-point condition code flag in bc1f/bc1t and movf/movt. |
| 462 | args << "cc" << (rt >> 2); |
| 463 | break; |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 464 | case 'D': args << 'r' << rd; break; |
| 465 | case 'd': args << 'f' << rd; break; |
Douglas Leung | 1cd2790 | 2015-02-13 16:55:57 -0800 | [diff] [blame] | 466 | case 'a': args << 'f' << sa; break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 467 | case 'f': // Floating point "fmt". |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 468 | { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 469 | size_t fmt = (instruction >> 21) & 0x7; // TODO: other fmts? |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 470 | switch (fmt) { |
| 471 | case 0: opcode += ".s"; break; |
| 472 | case 1: opcode += ".d"; break; |
| 473 | case 4: opcode += ".w"; break; |
| 474 | case 5: opcode += ".l"; break; |
| 475 | case 6: opcode += ".ps"; break; |
| 476 | default: opcode += ".?"; break; |
| 477 | } |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 478 | continue; // No ", ". |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 479 | } |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 480 | case 'I': // Upper 16-bit immediate. |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 481 | args << reinterpret_cast<void*>((instruction & 0xffff) << 16); |
| 482 | break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 483 | case 'i': // Sign-extended lower 16-bit immediate. |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 484 | args << static_cast<int16_t>(instruction & 0xffff); |
| 485 | break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 486 | case 'L': // Jump label. |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 487 | { |
| 488 | // TODO: is this right? |
| 489 | uint32_t instr_index = (instruction & 0x1ffffff); |
| 490 | uint32_t target = (instr_index << 2); |
| 491 | target |= (reinterpret_cast<uintptr_t>(instr_ptr + 4) & 0xf0000000); |
| 492 | args << reinterpret_cast<void*>(target); |
| 493 | } |
| 494 | break; |
Chris Larsen | 2fadd7b | 2015-08-14 14:56:10 -0700 | [diff] [blame] | 495 | case 'l': // 9-bit signed offset |
| 496 | { |
| 497 | int32_t offset = static_cast<int16_t>(instruction) >> 7; |
| 498 | args << StringPrintf("%+d(r%d)", offset, rs); |
| 499 | } |
| 500 | break; |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 501 | case 'O': // +x(rs) |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 502 | { |
| 503 | int32_t offset = static_cast<int16_t>(instruction & 0xffff); |
| 504 | args << StringPrintf("%+d(r%d)", offset, rs); |
| 505 | if (rs == 17) { |
| 506 | args << " ; "; |
Andreas Gampe | 372f3a3 | 2016-08-19 10:49:06 -0700 | [diff] [blame] | 507 | GetDisassemblerOptions()->thread_offset_name_function_(args, offset); |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | break; |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 511 | case 'o': // 19-bit offset in lwpc. |
| 512 | { |
| 513 | int32_t offset = (instruction & 0x7ffff) - ((instruction & 0x40000) << 1); |
| 514 | offset <<= 2; |
| 515 | args << FormatInstructionPointer(instr_ptr + offset); |
| 516 | args << StringPrintf(" ; %+d", offset); |
| 517 | } |
| 518 | break; |
| 519 | case 'P': // 26-bit offset in bc and balc. |
Goran Jakovljevic | 8c434dc | 2015-08-26 14:39:44 +0200 | [diff] [blame] | 520 | { |
| 521 | int32_t offset = (instruction & 0x3ffffff) - ((instruction & 0x2000000) << 1); |
| 522 | offset <<= 2; |
| 523 | offset += 4; |
| 524 | args << FormatInstructionPointer(instr_ptr + offset); |
| 525 | args << StringPrintf(" ; %+d", offset); |
| 526 | } |
| 527 | break; |
| 528 | case 'p': // 19-bit offset in addiupc. |
| 529 | { |
| 530 | int32_t offset = (instruction & 0x7ffff) - ((instruction & 0x40000) << 1); |
| 531 | args << offset << " ; move r" << rs << ", "; |
| 532 | args << FormatInstructionPointer(instr_ptr + (offset << 2)); |
| 533 | } |
| 534 | break; |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 535 | case 'S': args << 'r' << rs; break; |
| 536 | case 's': args << 'f' << rs; break; |
| 537 | case 'T': args << 'r' << rt; break; |
| 538 | case 't': args << 'f' << rt; break; |
Alexey Frunze | 5c7aed3 | 2015-11-25 19:41:54 -0800 | [diff] [blame] | 539 | case 'Z': args << (rd + 1); break; // sz ([d]ext size). |
| 540 | case 'z': args << (rd - sa + 1); break; // sz ([d]ins size). |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 541 | } |
| 542 | if (*(args_fmt + 1)) { |
| 543 | args << ", "; |
| 544 | } |
| 545 | } |
| 546 | break; |
| 547 | } |
| 548 | } |
| 549 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 550 | // TODO: Simplify this once these sequences are simplified in the compiler. |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 551 | // Special cases for sequences of: |
| 552 | // pc-relative +/- 2GB branch: |
| 553 | // auipc reg, imm |
| 554 | // jic reg, imm |
| 555 | // pc-relative +/- 2GB branch and link: |
| 556 | // auipc reg, imm |
| 557 | // daddiu reg, reg, imm |
| 558 | // jialc reg, 0 |
| 559 | if (((op == 0x36 && rs == 0 && rt != 0) || // jic |
| 560 | (op == 0x19 && rs == rt && rt != 0)) && // daddiu |
| 561 | last_ptr_ && (intptr_t)instr_ptr - (intptr_t)last_ptr_ == 4 && |
| 562 | (last_instr_ & 0xFC1F0000) == 0xEC1E0000 && // auipc |
| 563 | ((last_instr_ >> 21) & 0x1F) == rt) { |
| 564 | uint32_t offset = (last_instr_ << 16) | (instruction & 0xFFFF); |
| 565 | offset -= (offset & 0x8000) << 1; |
| 566 | offset -= 4; |
| 567 | if (op == 0x36) { |
| 568 | args << " ; b "; |
| 569 | } else { |
| 570 | args << " ; move r" << rt << ", "; |
| 571 | } |
| 572 | args << FormatInstructionPointer(instr_ptr + (int32_t)offset); |
| 573 | args << StringPrintf(" ; %+d", (int32_t)offset); |
| 574 | } |
| 575 | |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 576 | os << FormatInstructionPointer(instr_ptr) |
| 577 | << StringPrintf(": %08x\t%-7s ", instruction, opcode.c_str()) |
| 578 | << args.str() << '\n'; |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 579 | last_ptr_ = instr_ptr; |
| 580 | last_instr_ = instruction; |
Ian Rogers | b23a772 | 2012-10-09 16:54:26 -0700 | [diff] [blame] | 581 | return 4; |
| 582 | } |
| 583 | |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 584 | void DisassemblerMips::Dump(std::ostream& os, const uint8_t* begin, const uint8_t* end) { |
| 585 | for (const uint8_t* cur = begin; cur < end; cur += 4) { |
Brian Carlstrom | 2cbaccb | 2014-09-14 20:34:17 -0700 | [diff] [blame] | 586 | Dump(os, cur); |
Elliott Hughes | 60454e8 | 2012-04-25 12:56:03 -0700 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | |
| 590 | } // namespace mips |
| 591 | } // namespace art |