Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_ARM_CONSTANTS_ARM_H_ |
| 29 | #define V8_ARM_CONSTANTS_ARM_H_ |
| 30 | |
| 31 | // The simulator emulates the EABI so we define the USE_ARM_EABI macro if we |
| 32 | // are not running on real ARM hardware. One reason for this is that the |
| 33 | // old ABI uses fp registers in the calling convention and the simulator does |
| 34 | // not simulate fp registers or coroutine instructions. |
| 35 | #if defined(__ARM_EABI__) || !defined(__arm__) |
| 36 | # define USE_ARM_EABI 1 |
| 37 | #endif |
| 38 | |
| 39 | // This means that interwork-compatible jump instructions are generated. We |
| 40 | // want to generate them on the simulator too so it makes snapshots that can |
| 41 | // be used on real hardware. |
| 42 | #if defined(__THUMB_INTERWORK__) || !defined(__arm__) |
| 43 | # define USE_THUMB_INTERWORK 1 |
| 44 | #endif |
| 45 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 46 | #if defined(__ARM_ARCH_7A__) || \ |
| 47 | defined(__ARM_ARCH_7R__) || \ |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 48 | defined(__ARM_ARCH_7__) |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 49 | # define CAN_USE_ARMV7_INSTRUCTIONS 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 50 | #endif |
| 51 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 52 | #if defined(__ARM_ARCH_6__) || \ |
| 53 | defined(__ARM_ARCH_6J__) || \ |
| 54 | defined(__ARM_ARCH_6K__) || \ |
| 55 | defined(__ARM_ARCH_6Z__) || \ |
| 56 | defined(__ARM_ARCH_6ZK__) || \ |
| 57 | defined(__ARM_ARCH_6T2__) || \ |
| 58 | defined(CAN_USE_ARMV7_INSTRUCTIONS) |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 59 | # define CAN_USE_ARMV6_INSTRUCTIONS 1 |
| 60 | #endif |
| 61 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 62 | #if defined(__ARM_ARCH_5T__) || \ |
| 63 | defined(__ARM_ARCH_5TE__) || \ |
| 64 | defined(CAN_USE_ARMV6_INSTRUCTIONS) |
| 65 | # define CAN_USE_ARMV5_INSTRUCTIONS 1 |
| 66 | # define CAN_USE_THUMB_INSTRUCTIONS 1 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 67 | #endif |
| 68 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 69 | // Simulator should support ARM5 instructions and unaligned access by default. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 70 | #if !defined(__arm__) |
| 71 | # define CAN_USE_ARMV5_INSTRUCTIONS 1 |
| 72 | # define CAN_USE_THUMB_INSTRUCTIONS 1 |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 73 | |
| 74 | # ifndef CAN_USE_UNALIGNED_ACCESSES |
| 75 | # define CAN_USE_UNALIGNED_ACCESSES 1 |
| 76 | # endif |
| 77 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 78 | #endif |
| 79 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 80 | #if CAN_USE_UNALIGNED_ACCESSES |
| 81 | #define V8_TARGET_CAN_READ_UNALIGNED 1 |
| 82 | #endif |
| 83 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 84 | // Using blx may yield better code, so use it when required or when available |
| 85 | #if defined(USE_THUMB_INTERWORK) || defined(CAN_USE_ARMV5_INSTRUCTIONS) |
| 86 | #define USE_BLX 1 |
| 87 | #endif |
| 88 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 89 | namespace v8 { |
| 90 | namespace internal { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 91 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 92 | // Constant pool marker. |
| 93 | static const int kConstantPoolMarkerMask = 0xffe00000; |
| 94 | static const int kConstantPoolMarker = 0x0c000000; |
| 95 | static const int kConstantPoolLengthMask = 0x001ffff; |
| 96 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 97 | // Number of registers in normal ARM mode. |
| 98 | static const int kNumRegisters = 16; |
| 99 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 100 | // VFP support. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 101 | static const int kNumVFPSingleRegisters = 32; |
| 102 | static const int kNumVFPDoubleRegisters = 16; |
| 103 | static const int kNumVFPRegisters = |
| 104 | kNumVFPSingleRegisters + kNumVFPDoubleRegisters; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 105 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 106 | // PC is register 15. |
| 107 | static const int kPCRegister = 15; |
| 108 | static const int kNoRegister = -1; |
| 109 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 110 | // ----------------------------------------------------------------------------- |
| 111 | // Conditions. |
| 112 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 113 | // Defines constants and accessor classes to assemble, disassemble and |
| 114 | // simulate ARM instructions. |
| 115 | // |
| 116 | // Section references in the code refer to the "ARM Architecture Reference |
| 117 | // Manual" from July 2005 (available at http://www.arm.com/miscPDFs/14128.pdf) |
| 118 | // |
| 119 | // Constants for specific fields are defined in their respective named enums. |
| 120 | // General constants are in an anonymous enum in class Instr. |
| 121 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 122 | // Values for the condition field as defined in section A3.2 |
| 123 | enum Condition { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 124 | kNoCondition = -1, |
| 125 | |
| 126 | eq = 0 << 28, // Z set Equal. |
| 127 | ne = 1 << 28, // Z clear Not equal. |
| 128 | cs = 2 << 28, // C set Unsigned higher or same. |
| 129 | cc = 3 << 28, // C clear Unsigned lower. |
| 130 | mi = 4 << 28, // N set Negative. |
| 131 | pl = 5 << 28, // N clear Positive or zero. |
| 132 | vs = 6 << 28, // V set Overflow. |
| 133 | vc = 7 << 28, // V clear No overflow. |
| 134 | hi = 8 << 28, // C set, Z clear Unsigned higher. |
| 135 | ls = 9 << 28, // C clear or Z set Unsigned lower or same. |
| 136 | ge = 10 << 28, // N == V Greater or equal. |
| 137 | lt = 11 << 28, // N != V Less than. |
| 138 | gt = 12 << 28, // Z clear, N == V Greater than. |
| 139 | le = 13 << 28, // Z set or N != V Less then or equal |
| 140 | al = 14 << 28, // Always. |
| 141 | |
| 142 | kSpecialCondition = 15 << 28, // Special condition (refer to section A3.2.1). |
| 143 | kNumberOfConditions = 16, |
| 144 | |
| 145 | // Aliases. |
| 146 | hs = cs, // C set Unsigned higher or same. |
| 147 | lo = cc // C clear Unsigned lower. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 151 | inline Condition NegateCondition(Condition cond) { |
| 152 | ASSERT(cond != al); |
| 153 | return static_cast<Condition>(cond ^ ne); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | // Corresponds to transposing the operands of a comparison. |
| 158 | inline Condition ReverseCondition(Condition cond) { |
| 159 | switch (cond) { |
| 160 | case lo: |
| 161 | return hi; |
| 162 | case hi: |
| 163 | return lo; |
| 164 | case hs: |
| 165 | return ls; |
| 166 | case ls: |
| 167 | return hs; |
| 168 | case lt: |
| 169 | return gt; |
| 170 | case gt: |
| 171 | return lt; |
| 172 | case ge: |
| 173 | return le; |
| 174 | case le: |
| 175 | return ge; |
| 176 | default: |
| 177 | return cond; |
| 178 | }; |
| 179 | } |
| 180 | |
| 181 | |
| 182 | // ----------------------------------------------------------------------------- |
| 183 | // Instructions encoding. |
| 184 | |
| 185 | // Instr is merely used by the Assembler to distinguish 32bit integers |
| 186 | // representing instructions from usual 32 bit values. |
| 187 | // Instruction objects are pointers to 32bit values, and provide methods to |
| 188 | // access the various ISA fields. |
| 189 | typedef int32_t Instr; |
| 190 | |
| 191 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 192 | // Opcodes for Data-processing instructions (instructions with a type 0 and 1) |
| 193 | // as defined in section A3.4 |
| 194 | enum Opcode { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 195 | AND = 0 << 21, // Logical AND. |
| 196 | EOR = 1 << 21, // Logical Exclusive OR. |
| 197 | SUB = 2 << 21, // Subtract. |
| 198 | RSB = 3 << 21, // Reverse Subtract. |
| 199 | ADD = 4 << 21, // Add. |
| 200 | ADC = 5 << 21, // Add with Carry. |
| 201 | SBC = 6 << 21, // Subtract with Carry. |
| 202 | RSC = 7 << 21, // Reverse Subtract with Carry. |
| 203 | TST = 8 << 21, // Test. |
| 204 | TEQ = 9 << 21, // Test Equivalence. |
| 205 | CMP = 10 << 21, // Compare. |
| 206 | CMN = 11 << 21, // Compare Negated. |
| 207 | ORR = 12 << 21, // Logical (inclusive) OR. |
| 208 | MOV = 13 << 21, // Move. |
| 209 | BIC = 14 << 21, // Bit Clear. |
| 210 | MVN = 15 << 21 // Move Not. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 214 | // The bits for bit 7-4 for some type 0 miscellaneous instructions. |
| 215 | enum MiscInstructionsBits74 { |
| 216 | // With bits 22-21 01. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 217 | BX = 1 << 4, |
| 218 | BXJ = 2 << 4, |
| 219 | BLX = 3 << 4, |
| 220 | BKPT = 7 << 4, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 221 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 222 | // With bits 22-21 11. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 223 | CLZ = 1 << 4 |
| 224 | }; |
| 225 | |
| 226 | |
| 227 | // Instruction encoding bits and masks. |
| 228 | enum { |
| 229 | H = 1 << 5, // Halfword (or byte). |
| 230 | S6 = 1 << 6, // Signed (or unsigned). |
| 231 | L = 1 << 20, // Load (or store). |
| 232 | S = 1 << 20, // Set condition code (or leave unchanged). |
| 233 | W = 1 << 21, // Writeback base register (or leave unchanged). |
| 234 | A = 1 << 21, // Accumulate in multiply instruction (or not). |
| 235 | B = 1 << 22, // Unsigned byte (or word). |
| 236 | N = 1 << 22, // Long (or short). |
| 237 | U = 1 << 23, // Positive (or negative) offset/index. |
| 238 | P = 1 << 24, // Offset/pre-indexed addressing (or post-indexed addressing). |
| 239 | I = 1 << 25, // Immediate shifter operand (or not). |
| 240 | |
| 241 | B4 = 1 << 4, |
| 242 | B5 = 1 << 5, |
| 243 | B6 = 1 << 6, |
| 244 | B7 = 1 << 7, |
| 245 | B8 = 1 << 8, |
| 246 | B9 = 1 << 9, |
| 247 | B12 = 1 << 12, |
| 248 | B16 = 1 << 16, |
| 249 | B18 = 1 << 18, |
| 250 | B19 = 1 << 19, |
| 251 | B20 = 1 << 20, |
| 252 | B21 = 1 << 21, |
| 253 | B22 = 1 << 22, |
| 254 | B23 = 1 << 23, |
| 255 | B24 = 1 << 24, |
| 256 | B25 = 1 << 25, |
| 257 | B26 = 1 << 26, |
| 258 | B27 = 1 << 27, |
| 259 | B28 = 1 << 28, |
| 260 | |
| 261 | // Instruction bit masks. |
| 262 | kCondMask = 15 << 28, |
| 263 | kALUMask = 0x6f << 21, |
| 264 | kRdMask = 15 << 12, // In str instruction. |
| 265 | kCoprocessorMask = 15 << 8, |
| 266 | kOpCodeMask = 15 << 21, // In data-processing instructions. |
| 267 | kImm24Mask = (1 << 24) - 1, |
| 268 | kOff12Mask = (1 << 12) - 1 |
| 269 | }; |
| 270 | |
| 271 | |
| 272 | // ----------------------------------------------------------------------------- |
| 273 | // Addressing modes and instruction variants. |
| 274 | |
| 275 | // Condition code updating mode. |
| 276 | enum SBit { |
| 277 | SetCC = 1 << 20, // Set condition code. |
| 278 | LeaveCC = 0 << 20 // Leave condition code unchanged. |
| 279 | }; |
| 280 | |
| 281 | |
| 282 | // Status register selection. |
| 283 | enum SRegister { |
| 284 | CPSR = 0 << 22, |
| 285 | SPSR = 1 << 22 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 286 | }; |
| 287 | |
| 288 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 289 | // Shifter types for Data-processing operands as defined in section A5.1.2. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 290 | enum ShiftOp { |
| 291 | LSL = 0 << 5, // Logical shift left. |
| 292 | LSR = 1 << 5, // Logical shift right. |
| 293 | ASR = 2 << 5, // Arithmetic shift right. |
| 294 | ROR = 3 << 5, // Rotate right. |
| 295 | |
| 296 | // RRX is encoded as ROR with shift_imm == 0. |
| 297 | // Use a special code to make the distinction. The RRX ShiftOp is only used |
| 298 | // as an argument, and will never actually be encoded. The Assembler will |
| 299 | // detect it and emit the correct ROR shift operand with shift_imm == 0. |
| 300 | RRX = -1, |
| 301 | kNumberOfShifts = 4 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 305 | // Status register fields. |
| 306 | enum SRegisterField { |
| 307 | CPSR_c = CPSR | 1 << 16, |
| 308 | CPSR_x = CPSR | 1 << 17, |
| 309 | CPSR_s = CPSR | 1 << 18, |
| 310 | CPSR_f = CPSR | 1 << 19, |
| 311 | SPSR_c = SPSR | 1 << 16, |
| 312 | SPSR_x = SPSR | 1 << 17, |
| 313 | SPSR_s = SPSR | 1 << 18, |
| 314 | SPSR_f = SPSR | 1 << 19 |
| 315 | }; |
| 316 | |
| 317 | // Status register field mask (or'ed SRegisterField enum values). |
| 318 | typedef uint32_t SRegisterFieldMask; |
| 319 | |
| 320 | |
| 321 | // Memory operand addressing mode. |
| 322 | enum AddrMode { |
| 323 | // Bit encoding P U W. |
| 324 | Offset = (8|4|0) << 21, // Offset (without writeback to base). |
| 325 | PreIndex = (8|4|1) << 21, // Pre-indexed addressing with writeback. |
| 326 | PostIndex = (0|4|0) << 21, // Post-indexed addressing with writeback. |
| 327 | NegOffset = (8|0|0) << 21, // Negative offset (without writeback to base). |
| 328 | NegPreIndex = (8|0|1) << 21, // Negative pre-indexed with writeback. |
| 329 | NegPostIndex = (0|0|0) << 21 // Negative post-indexed with writeback. |
| 330 | }; |
| 331 | |
| 332 | |
| 333 | // Load/store multiple addressing mode. |
| 334 | enum BlockAddrMode { |
| 335 | // Bit encoding P U W . |
| 336 | da = (0|0|0) << 21, // Decrement after. |
| 337 | ia = (0|4|0) << 21, // Increment after. |
| 338 | db = (8|0|0) << 21, // Decrement before. |
| 339 | ib = (8|4|0) << 21, // Increment before. |
| 340 | da_w = (0|0|1) << 21, // Decrement after with writeback to base. |
| 341 | ia_w = (0|4|1) << 21, // Increment after with writeback to base. |
| 342 | db_w = (8|0|1) << 21, // Decrement before with writeback to base. |
| 343 | ib_w = (8|4|1) << 21, // Increment before with writeback to base. |
| 344 | |
| 345 | // Alias modes for comparison when writeback does not matter. |
| 346 | da_x = (0|0|0) << 21, // Decrement after. |
| 347 | ia_x = (0|4|0) << 21, // Increment after. |
| 348 | db_x = (8|0|0) << 21, // Decrement before. |
| 349 | ib_x = (8|4|0) << 21 // Increment before. |
| 350 | }; |
| 351 | |
| 352 | |
| 353 | // Coprocessor load/store operand size. |
| 354 | enum LFlag { |
| 355 | Long = 1 << 22, // Long load/store coprocessor. |
| 356 | Short = 0 << 22 // Short load/store coprocessor. |
| 357 | }; |
| 358 | |
| 359 | |
| 360 | // ----------------------------------------------------------------------------- |
| 361 | // Supervisor Call (svc) specific support. |
| 362 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 363 | // Special Software Interrupt codes when used in the presence of the ARM |
| 364 | // simulator. |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 365 | // svc (formerly swi) provides a 24bit immediate value. Use bits 22:0 for |
| 366 | // standard SoftwareInterrupCode. Bit 23 is reserved for the stop feature. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 367 | enum SoftwareInterruptCodes { |
| 368 | // transition to C code |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 369 | kCallRtRedirected= 0x10, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 370 | // break point |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 371 | kBreakpoint= 0x20, |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 372 | // stop |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 373 | kStopCode = 1 << 23 |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 374 | }; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 375 | static const uint32_t kStopCodeMask = kStopCode - 1; |
| 376 | static const uint32_t kMaxStopCode = kStopCode - 1; |
| 377 | static const int32_t kDefaultStopCode = -1; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 378 | |
| 379 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 380 | // Type of VFP register. Determines register encoding. |
| 381 | enum VFPRegPrecision { |
| 382 | kSinglePrecision = 0, |
| 383 | kDoublePrecision = 1 |
| 384 | }; |
| 385 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 386 | |
| 387 | // VFP FPSCR constants. |
| 388 | enum VFPConversionMode { |
| 389 | kFPSCRRounding = 0, |
| 390 | kDefaultRoundToZero = 1 |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 391 | }; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 392 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 393 | // This mask does not include the "inexact" or "input denormal" cumulative |
| 394 | // exceptions flags, because we usually don't want to check for it. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 395 | static const uint32_t kVFPExceptionMask = 0xf; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame^] | 396 | static const uint32_t kVFPInvalidOpExceptionBit = 1 << 0; |
| 397 | static const uint32_t kVFPOverflowExceptionBit = 1 << 2; |
| 398 | static const uint32_t kVFPUnderflowExceptionBit = 1 << 3; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 399 | static const uint32_t kVFPInexactExceptionBit = 1 << 4; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 400 | static const uint32_t kVFPFlushToZeroMask = 1 << 24; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 401 | |
| 402 | static const uint32_t kVFPNConditionFlagBit = 1 << 31; |
| 403 | static const uint32_t kVFPZConditionFlagBit = 1 << 30; |
| 404 | static const uint32_t kVFPCConditionFlagBit = 1 << 29; |
| 405 | static const uint32_t kVFPVConditionFlagBit = 1 << 28; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 406 | |
| 407 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 408 | // VFP rounding modes. See ARM DDI 0406B Page A2-29. |
| 409 | enum VFPRoundingMode { |
| 410 | RN = 0 << 22, // Round to Nearest. |
| 411 | RP = 1 << 22, // Round towards Plus Infinity. |
| 412 | RM = 2 << 22, // Round towards Minus Infinity. |
| 413 | RZ = 3 << 22, // Round towards zero. |
| 414 | |
| 415 | // Aliases. |
| 416 | kRoundToNearest = RN, |
| 417 | kRoundToPlusInf = RP, |
| 418 | kRoundToMinusInf = RM, |
| 419 | kRoundToZero = RZ |
| 420 | }; |
| 421 | |
| 422 | static const uint32_t kVFPRoundingModeMask = 3 << 22; |
| 423 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 424 | enum CheckForInexactConversion { |
| 425 | kCheckForInexactConversion, |
| 426 | kDontCheckForInexactConversion |
| 427 | }; |
| 428 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 429 | // ----------------------------------------------------------------------------- |
| 430 | // Hints. |
| 431 | |
| 432 | // Branch hints are not used on the ARM. They are defined so that they can |
| 433 | // appear in shared function signatures, but will be ignored in ARM |
| 434 | // implementations. |
| 435 | enum Hint { no_hint }; |
| 436 | |
| 437 | // Hints are not used on the arm. Negating is trivial. |
| 438 | inline Hint NegateHint(Hint ignored) { return no_hint; } |
| 439 | |
| 440 | |
| 441 | // ----------------------------------------------------------------------------- |
| 442 | // Specific instructions, constants, and masks. |
| 443 | // These constants are declared in assembler-arm.cc, as they use named registers |
| 444 | // and other constants. |
| 445 | |
| 446 | |
| 447 | // add(sp, sp, 4) instruction (aka Pop()) |
| 448 | extern const Instr kPopInstruction; |
| 449 | |
| 450 | // str(r, MemOperand(sp, 4, NegPreIndex), al) instruction (aka push(r)) |
| 451 | // register r is not encoded. |
| 452 | extern const Instr kPushRegPattern; |
| 453 | |
| 454 | // ldr(r, MemOperand(sp, 4, PostIndex), al) instruction (aka pop(r)) |
| 455 | // register r is not encoded. |
| 456 | extern const Instr kPopRegPattern; |
| 457 | |
| 458 | // mov lr, pc |
| 459 | extern const Instr kMovLrPc; |
| 460 | // ldr rd, [pc, #offset] |
| 461 | extern const Instr kLdrPCMask; |
| 462 | extern const Instr kLdrPCPattern; |
| 463 | // blxcc rm |
| 464 | extern const Instr kBlxRegMask; |
| 465 | |
| 466 | extern const Instr kBlxRegPattern; |
| 467 | |
| 468 | extern const Instr kMovMvnMask; |
| 469 | extern const Instr kMovMvnPattern; |
| 470 | extern const Instr kMovMvnFlip; |
| 471 | extern const Instr kMovLeaveCCMask; |
| 472 | extern const Instr kMovLeaveCCPattern; |
| 473 | extern const Instr kMovwMask; |
| 474 | extern const Instr kMovwPattern; |
| 475 | extern const Instr kMovwLeaveCCFlip; |
| 476 | extern const Instr kCmpCmnMask; |
| 477 | extern const Instr kCmpCmnPattern; |
| 478 | extern const Instr kCmpCmnFlip; |
| 479 | extern const Instr kAddSubFlip; |
| 480 | extern const Instr kAndBicFlip; |
| 481 | |
| 482 | // A mask for the Rd register for push, pop, ldr, str instructions. |
| 483 | extern const Instr kLdrRegFpOffsetPattern; |
| 484 | |
| 485 | extern const Instr kStrRegFpOffsetPattern; |
| 486 | |
| 487 | extern const Instr kLdrRegFpNegOffsetPattern; |
| 488 | |
| 489 | extern const Instr kStrRegFpNegOffsetPattern; |
| 490 | |
| 491 | extern const Instr kLdrStrInstrTypeMask; |
| 492 | extern const Instr kLdrStrInstrArgumentMask; |
| 493 | extern const Instr kLdrStrOffsetMask; |
| 494 | |
| 495 | |
| 496 | // ----------------------------------------------------------------------------- |
| 497 | // Instruction abstraction. |
| 498 | |
| 499 | // The class Instruction enables access to individual fields defined in the ARM |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 500 | // architecture instruction set encoding as described in figure A3-1. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 501 | // Note that the Assembler uses typedef int32_t Instr. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 502 | // |
| 503 | // Example: Test whether the instruction at ptr does set the condition code |
| 504 | // bits. |
| 505 | // |
| 506 | // bool InstructionSetsConditionCodes(byte* ptr) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 507 | // Instruction* instr = Instruction::At(ptr); |
| 508 | // int type = instr->TypeValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 509 | // return ((type == 0) || (type == 1)) && instr->HasS(); |
| 510 | // } |
| 511 | // |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 512 | class Instruction { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 513 | public: |
| 514 | enum { |
| 515 | kInstrSize = 4, |
| 516 | kInstrSizeLog2 = 2, |
| 517 | kPCReadOffset = 8 |
| 518 | }; |
| 519 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 520 | // Helper macro to define static accessors. |
| 521 | // We use the cast to char* trick to bypass the strict anti-aliasing rules. |
| 522 | #define DECLARE_STATIC_TYPED_ACCESSOR(return_type, Name) \ |
| 523 | static inline return_type Name(Instr instr) { \ |
| 524 | char* temp = reinterpret_cast<char*>(&instr); \ |
| 525 | return reinterpret_cast<Instruction*>(temp)->Name(); \ |
| 526 | } |
| 527 | |
| 528 | #define DECLARE_STATIC_ACCESSOR(Name) DECLARE_STATIC_TYPED_ACCESSOR(int, Name) |
| 529 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 530 | // Get the raw instruction bits. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 531 | inline Instr InstructionBits() const { |
| 532 | return *reinterpret_cast<const Instr*>(this); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | // Set the raw instruction bits to value. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 536 | inline void SetInstructionBits(Instr value) { |
| 537 | *reinterpret_cast<Instr*>(this) = value; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | // Read one particular bit out of the instruction bits. |
| 541 | inline int Bit(int nr) const { |
| 542 | return (InstructionBits() >> nr) & 1; |
| 543 | } |
| 544 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 545 | // Read a bit field's value out of the instruction bits. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 546 | inline int Bits(int hi, int lo) const { |
| 547 | return (InstructionBits() >> lo) & ((2 << (hi - lo)) - 1); |
| 548 | } |
| 549 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 550 | // Read a bit field out of the instruction bits. |
| 551 | inline int BitField(int hi, int lo) const { |
| 552 | return InstructionBits() & (((2 << (hi - lo)) - 1) << lo); |
| 553 | } |
| 554 | |
| 555 | // Static support. |
| 556 | |
| 557 | // Read one particular bit out of the instruction bits. |
| 558 | static inline int Bit(Instr instr, int nr) { |
| 559 | return (instr >> nr) & 1; |
| 560 | } |
| 561 | |
| 562 | // Read the value of a bit field out of the instruction bits. |
| 563 | static inline int Bits(Instr instr, int hi, int lo) { |
| 564 | return (instr >> lo) & ((2 << (hi - lo)) - 1); |
| 565 | } |
| 566 | |
| 567 | |
| 568 | // Read a bit field out of the instruction bits. |
| 569 | static inline int BitField(Instr instr, int hi, int lo) { |
| 570 | return instr & (((2 << (hi - lo)) - 1) << lo); |
| 571 | } |
| 572 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 573 | |
| 574 | // Accessors for the different named fields used in the ARM encoding. |
| 575 | // The naming of these accessor corresponds to figure A3-1. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 576 | // |
| 577 | // Two kind of accessors are declared: |
| 578 | // - <Name>Field() will return the raw field, ie the field's bits at their |
| 579 | // original place in the instruction encoding. |
| 580 | // eg. if instr is the 'addgt r0, r1, r2' instruction, encoded as 0xC0810002 |
| 581 | // ConditionField(instr) will return 0xC0000000. |
| 582 | // - <Name>Value() will return the field value, shifted back to bit 0. |
| 583 | // eg. if instr is the 'addgt r0, r1, r2' instruction, encoded as 0xC0810002 |
| 584 | // ConditionField(instr) will return 0xC. |
| 585 | |
| 586 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 587 | // Generally applicable fields |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 588 | inline Condition ConditionValue() const { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 589 | return static_cast<Condition>(Bits(31, 28)); |
| 590 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 591 | inline Condition ConditionField() const { |
| 592 | return static_cast<Condition>(BitField(31, 28)); |
| 593 | } |
| 594 | DECLARE_STATIC_TYPED_ACCESSOR(Condition, ConditionValue); |
| 595 | DECLARE_STATIC_TYPED_ACCESSOR(Condition, ConditionField); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 596 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 597 | inline int TypeValue() const { return Bits(27, 25); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 598 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 599 | inline int RnValue() const { return Bits(19, 16); } |
| 600 | DECLARE_STATIC_ACCESSOR(RnValue); |
| 601 | inline int RdValue() const { return Bits(15, 12); } |
| 602 | DECLARE_STATIC_ACCESSOR(RdValue); |
| 603 | |
| 604 | inline int CoprocessorValue() const { return Bits(11, 8); } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 605 | // Support for VFP. |
| 606 | // Vn(19-16) | Vd(15-12) | Vm(3-0) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 607 | inline int VnValue() const { return Bits(19, 16); } |
| 608 | inline int VmValue() const { return Bits(3, 0); } |
| 609 | inline int VdValue() const { return Bits(15, 12); } |
| 610 | inline int NValue() const { return Bit(7); } |
| 611 | inline int MValue() const { return Bit(5); } |
| 612 | inline int DValue() const { return Bit(22); } |
| 613 | inline int RtValue() const { return Bits(15, 12); } |
| 614 | inline int PValue() const { return Bit(24); } |
| 615 | inline int UValue() const { return Bit(23); } |
| 616 | inline int Opc1Value() const { return (Bit(23) << 2) | Bits(21, 20); } |
| 617 | inline int Opc2Value() const { return Bits(19, 16); } |
| 618 | inline int Opc3Value() const { return Bits(7, 6); } |
| 619 | inline int SzValue() const { return Bit(8); } |
| 620 | inline int VLValue() const { return Bit(20); } |
| 621 | inline int VCValue() const { return Bit(8); } |
| 622 | inline int VAValue() const { return Bits(23, 21); } |
| 623 | inline int VBValue() const { return Bits(6, 5); } |
| 624 | inline int VFPNRegValue(VFPRegPrecision pre) { |
| 625 | return VFPGlueRegValue(pre, 16, 7); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 626 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 627 | inline int VFPMRegValue(VFPRegPrecision pre) { |
| 628 | return VFPGlueRegValue(pre, 0, 5); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 629 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 630 | inline int VFPDRegValue(VFPRegPrecision pre) { |
| 631 | return VFPGlueRegValue(pre, 12, 22); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 632 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 633 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 634 | // Fields used in Data processing instructions |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 635 | inline int OpcodeValue() const { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 636 | return static_cast<Opcode>(Bits(24, 21)); |
| 637 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 638 | inline Opcode OpcodeField() const { |
| 639 | return static_cast<Opcode>(BitField(24, 21)); |
| 640 | } |
| 641 | inline int SValue() const { return Bit(20); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 642 | // with register |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 643 | inline int RmValue() const { return Bits(3, 0); } |
| 644 | DECLARE_STATIC_ACCESSOR(RmValue); |
| 645 | inline int ShiftValue() const { return static_cast<ShiftOp>(Bits(6, 5)); } |
| 646 | inline ShiftOp ShiftField() const { |
| 647 | return static_cast<ShiftOp>(BitField(6, 5)); |
| 648 | } |
| 649 | inline int RegShiftValue() const { return Bit(4); } |
| 650 | inline int RsValue() const { return Bits(11, 8); } |
| 651 | inline int ShiftAmountValue() const { return Bits(11, 7); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 652 | // with immediate |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 653 | inline int RotateValue() const { return Bits(11, 8); } |
| 654 | inline int Immed8Value() const { return Bits(7, 0); } |
| 655 | inline int Immed4Value() const { return Bits(19, 16); } |
| 656 | inline int ImmedMovwMovtValue() const { |
| 657 | return Immed4Value() << 12 | Offset12Value(); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 658 | |
| 659 | // Fields used in Load/Store instructions |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 660 | inline int PUValue() const { return Bits(24, 23); } |
| 661 | inline int PUField() const { return BitField(24, 23); } |
| 662 | inline int BValue() const { return Bit(22); } |
| 663 | inline int WValue() const { return Bit(21); } |
| 664 | inline int LValue() const { return Bit(20); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 665 | // with register uses same fields as Data processing instructions above |
| 666 | // with immediate |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 667 | inline int Offset12Value() const { return Bits(11, 0); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 668 | // multiple |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 669 | inline int RlistValue() const { return Bits(15, 0); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 670 | // extra loads and stores |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 671 | inline int SignValue() const { return Bit(6); } |
| 672 | inline int HValue() const { return Bit(5); } |
| 673 | inline int ImmedHValue() const { return Bits(11, 8); } |
| 674 | inline int ImmedLValue() const { return Bits(3, 0); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 675 | |
| 676 | // Fields used in Branch instructions |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 677 | inline int LinkValue() const { return Bit(24); } |
| 678 | inline int SImmed24Value() const { return ((InstructionBits() << 8) >> 8); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 679 | |
| 680 | // Fields used in Software interrupt instructions |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 681 | inline SoftwareInterruptCodes SvcValue() const { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 682 | return static_cast<SoftwareInterruptCodes>(Bits(23, 0)); |
| 683 | } |
| 684 | |
| 685 | // Test for special encodings of type 0 instructions (extra loads and stores, |
| 686 | // as well as multiplications). |
| 687 | inline bool IsSpecialType0() const { return (Bit(7) == 1) && (Bit(4) == 1); } |
| 688 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 689 | // Test for miscellaneous instructions encodings of type 0 instructions. |
| 690 | inline bool IsMiscType0() const { return (Bit(24) == 1) |
| 691 | && (Bit(23) == 0) |
| 692 | && (Bit(20) == 0) |
| 693 | && ((Bit(7) == 0)); } |
| 694 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 695 | // Test for a stop instruction. |
| 696 | inline bool IsStop() const { |
| 697 | return (TypeValue() == 7) && (Bit(24) == 1) && (SvcValue() >= kStopCode); |
| 698 | } |
| 699 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 700 | // Special accessors that test for existence of a value. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 701 | inline bool HasS() const { return SValue() == 1; } |
| 702 | inline bool HasB() const { return BValue() == 1; } |
| 703 | inline bool HasW() const { return WValue() == 1; } |
| 704 | inline bool HasL() const { return LValue() == 1; } |
| 705 | inline bool HasU() const { return UValue() == 1; } |
| 706 | inline bool HasSign() const { return SignValue() == 1; } |
| 707 | inline bool HasH() const { return HValue() == 1; } |
| 708 | inline bool HasLink() const { return LinkValue() == 1; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 709 | |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 710 | // Decoding the double immediate in the vmov instruction. |
| 711 | double DoubleImmedVmov() const; |
| 712 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 713 | // Instructions are read of out a code stream. The only way to get a |
| 714 | // reference to an instruction is to convert a pointer. There is no way |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 715 | // to allocate or create instances of class Instruction. |
| 716 | // Use the At(pc) function to create references to Instruction. |
| 717 | static Instruction* At(byte* pc) { |
| 718 | return reinterpret_cast<Instruction*>(pc); |
| 719 | } |
| 720 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 721 | |
| 722 | private: |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 723 | // Join split register codes, depending on single or double precision. |
| 724 | // four_bit is the position of the least-significant bit of the four |
| 725 | // bit specifier. one_bit is the position of the additional single bit |
| 726 | // specifier. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 727 | inline int VFPGlueRegValue(VFPRegPrecision pre, int four_bit, int one_bit) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 728 | if (pre == kSinglePrecision) { |
| 729 | return (Bits(four_bit + 3, four_bit) << 1) | Bit(one_bit); |
| 730 | } |
| 731 | return (Bit(one_bit) << 4) | Bits(four_bit + 3, four_bit); |
| 732 | } |
| 733 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 734 | // We need to prevent the creation of instances of class Instruction. |
| 735 | DISALLOW_IMPLICIT_CONSTRUCTORS(Instruction); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 736 | }; |
| 737 | |
| 738 | |
| 739 | // Helper functions for converting between register numbers and names. |
| 740 | class Registers { |
| 741 | public: |
| 742 | // Return the name of the register. |
| 743 | static const char* Name(int reg); |
| 744 | |
| 745 | // Lookup the register number for the name provided. |
| 746 | static int Number(const char* name); |
| 747 | |
| 748 | struct RegisterAlias { |
| 749 | int reg; |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 750 | const char* name; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 751 | }; |
| 752 | |
| 753 | private: |
| 754 | static const char* names_[kNumRegisters]; |
| 755 | static const RegisterAlias aliases_[]; |
| 756 | }; |
| 757 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 758 | // Helper functions for converting between VFP register numbers and names. |
| 759 | class VFPRegisters { |
| 760 | public: |
| 761 | // Return the name of the register. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 762 | static const char* Name(int reg, bool is_double); |
| 763 | |
| 764 | // Lookup the register number for the name provided. |
| 765 | // Set flag pointed by is_double to true if register |
| 766 | // is double-precision. |
| 767 | static int Number(const char* name, bool* is_double); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 768 | |
| 769 | private: |
| 770 | static const char* names_[kNumVFPRegisters]; |
| 771 | }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 772 | |
| 773 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 774 | } } // namespace v8::internal |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 775 | |
| 776 | #endif // V8_ARM_CONSTANTS_ARM_H_ |