OLD | NEW |
(Empty) | |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef V8_PPC_CONSTANTS_PPC_H_ |
| 6 #define V8_PPC_CONSTANTS_PPC_H_ |
| 7 |
| 8 namespace v8 { |
| 9 namespace internal { |
| 10 |
| 11 // Number of registers |
| 12 const int kNumRegisters = 32; |
| 13 |
| 14 // FP support. |
| 15 const int kNumFPDoubleRegisters = 32; |
| 16 const int kNumFPRegisters = kNumFPDoubleRegisters; |
| 17 |
| 18 const int kNoRegister = -1; |
| 19 |
| 20 // sign-extend the least significant 16-bits of value <imm> |
| 21 #define SIGN_EXT_IMM16(imm) ((static_cast<int>(imm) << 16) >> 16) |
| 22 |
| 23 // sign-extend the least significant 26-bits of value <imm> |
| 24 #define SIGN_EXT_IMM26(imm) ((static_cast<int>(imm) << 6) >> 6) |
| 25 |
| 26 // ----------------------------------------------------------------------------- |
| 27 // Conditions. |
| 28 |
| 29 // Defines constants and accessor classes to assemble, disassemble and |
| 30 // simulate PPC instructions. |
| 31 // |
| 32 // Section references in the code refer to the "PowerPC Microprocessor |
| 33 // Family: The Programmer.s Reference Guide" from 10/95 |
| 34 // https://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF77852
5699600741775/$file/prg.pdf |
| 35 // |
| 36 |
| 37 // Constants for specific fields are defined in their respective named enums. |
| 38 // General constants are in an anonymous enum in class Instr. |
| 39 enum Condition { |
| 40 kNoCondition = -1, |
| 41 eq = 0, // Equal. |
| 42 ne = 1, // Not equal. |
| 43 ge = 2, // Greater or equal. |
| 44 lt = 3, // Less than. |
| 45 gt = 4, // Greater than. |
| 46 le = 5, // Less then or equal |
| 47 unordered = 6, // Floating-point unordered |
| 48 ordered = 7, |
| 49 overflow = 8, // Summary overflow |
| 50 nooverflow = 9, |
| 51 al = 10 // Always. |
| 52 }; |
| 53 |
| 54 |
| 55 inline Condition NegateCondition(Condition cond) { |
| 56 DCHECK(cond != al); |
| 57 return static_cast<Condition>(cond ^ ne); |
| 58 } |
| 59 |
| 60 |
| 61 // Commute a condition such that {a cond b == b cond' a}. |
| 62 inline Condition CommuteCondition(Condition cond) { |
| 63 switch (cond) { |
| 64 case lt: |
| 65 return gt; |
| 66 case gt: |
| 67 return lt; |
| 68 case ge: |
| 69 return le; |
| 70 case le: |
| 71 return ge; |
| 72 default: |
| 73 return cond; |
| 74 } |
| 75 } |
| 76 |
| 77 // ----------------------------------------------------------------------------- |
| 78 // Instructions encoding. |
| 79 |
| 80 // Instr is merely used by the Assembler to distinguish 32bit integers |
| 81 // representing instructions from usual 32 bit values. |
| 82 // Instruction objects are pointers to 32bit values, and provide methods to |
| 83 // access the various ISA fields. |
| 84 typedef int32_t Instr; |
| 85 |
| 86 // Opcodes as defined in section 4.2 table 34 (32bit PowerPC) |
| 87 enum Opcode { |
| 88 TWI = 3 << 26, // Trap Word Immediate |
| 89 MULLI = 7 << 26, // Multiply Low Immediate |
| 90 SUBFIC = 8 << 26, // Subtract from Immediate Carrying |
| 91 CMPLI = 10 << 26, // Compare Logical Immediate |
| 92 CMPI = 11 << 26, // Compare Immediate |
| 93 ADDIC = 12 << 26, // Add Immediate Carrying |
| 94 ADDICx = 13 << 26, // Add Immediate Carrying and Record |
| 95 ADDI = 14 << 26, // Add Immediate |
| 96 ADDIS = 15 << 26, // Add Immediate Shifted |
| 97 BCX = 16 << 26, // Branch Conditional |
| 98 SC = 17 << 26, // System Call |
| 99 BX = 18 << 26, // Branch |
| 100 EXT1 = 19 << 26, // Extended code set 1 |
| 101 RLWIMIX = 20 << 26, // Rotate Left Word Immediate then Mask Insert |
| 102 RLWINMX = 21 << 26, // Rotate Left Word Immediate then AND with Mask |
| 103 RLWNMX = 23 << 26, // Rotate Left Word then AND with Mask |
| 104 ORI = 24 << 26, // OR Immediate |
| 105 ORIS = 25 << 26, // OR Immediate Shifted |
| 106 XORI = 26 << 26, // XOR Immediate |
| 107 XORIS = 27 << 26, // XOR Immediate Shifted |
| 108 ANDIx = 28 << 26, // AND Immediate |
| 109 ANDISx = 29 << 26, // AND Immediate Shifted |
| 110 EXT5 = 30 << 26, // Extended code set 5 - 64bit only |
| 111 EXT2 = 31 << 26, // Extended code set 2 |
| 112 LWZ = 32 << 26, // Load Word and Zero |
| 113 LWZU = 33 << 26, // Load Word with Zero Update |
| 114 LBZ = 34 << 26, // Load Byte and Zero |
| 115 LBZU = 35 << 26, // Load Byte and Zero with Update |
| 116 STW = 36 << 26, // Store |
| 117 STWU = 37 << 26, // Store Word with Update |
| 118 STB = 38 << 26, // Store Byte |
| 119 STBU = 39 << 26, // Store Byte with Update |
| 120 LHZ = 40 << 26, // Load Half and Zero |
| 121 LHZU = 41 << 26, // Load Half and Zero with Update |
| 122 LHA = 42 << 26, // Load Half Algebraic |
| 123 LHAU = 43 << 26, // Load Half Algebraic with Update |
| 124 STH = 44 << 26, // Store Half |
| 125 STHU = 45 << 26, // Store Half with Update |
| 126 LMW = 46 << 26, // Load Multiple Word |
| 127 STMW = 47 << 26, // Store Multiple Word |
| 128 LFS = 48 << 26, // Load Floating-Point Single |
| 129 LFSU = 49 << 26, // Load Floating-Point Single with Update |
| 130 LFD = 50 << 26, // Load Floating-Point Double |
| 131 LFDU = 51 << 26, // Load Floating-Point Double with Update |
| 132 STFS = 52 << 26, // Store Floating-Point Single |
| 133 STFSU = 53 << 26, // Store Floating-Point Single with Update |
| 134 STFD = 54 << 26, // Store Floating-Point Double |
| 135 STFDU = 55 << 26, // Store Floating-Point Double with Update |
| 136 LD = 58 << 26, // Load Double Word |
| 137 EXT3 = 59 << 26, // Extended code set 3 |
| 138 STD = 62 << 26, // Store Double Word (optionally with Update) |
| 139 EXT4 = 63 << 26 // Extended code set 4 |
| 140 }; |
| 141 |
| 142 // Bits 10-1 |
| 143 enum OpcodeExt1 { |
| 144 MCRF = 0 << 1, // Move Condition Register Field |
| 145 BCLRX = 16 << 1, // Branch Conditional Link Register |
| 146 CRNOR = 33 << 1, // Condition Register NOR) |
| 147 RFI = 50 << 1, // Return from Interrupt |
| 148 CRANDC = 129 << 1, // Condition Register AND with Complement |
| 149 ISYNC = 150 << 1, // Instruction Synchronize |
| 150 CRXOR = 193 << 1, // Condition Register XOR |
| 151 CRNAND = 225 << 1, // Condition Register NAND |
| 152 CRAND = 257 << 1, // Condition Register AND |
| 153 CREQV = 289 << 1, // Condition Register Equivalent |
| 154 CRORC = 417 << 1, // Condition Register OR with Complement |
| 155 CROR = 449 << 1, // Condition Register OR |
| 156 BCCTRX = 528 << 1 // Branch Conditional to Count Register |
| 157 }; |
| 158 |
| 159 // Bits 9-1 or 10-1 |
| 160 enum OpcodeExt2 { |
| 161 CMP = 0 << 1, |
| 162 TW = 4 << 1, |
| 163 SUBFCX = 8 << 1, |
| 164 ADDCX = 10 << 1, |
| 165 MULHWUX = 11 << 1, |
| 166 MFCR = 19 << 1, |
| 167 LWARX = 20 << 1, |
| 168 LDX = 21 << 1, |
| 169 LWZX = 23 << 1, // load word zero w/ x-form |
| 170 SLWX = 24 << 1, |
| 171 CNTLZWX = 26 << 1, |
| 172 SLDX = 27 << 1, |
| 173 ANDX = 28 << 1, |
| 174 CMPL = 32 << 1, |
| 175 SUBFX = 40 << 1, |
| 176 MFVSRD = 51 << 1, // Move From VSR Doubleword |
| 177 LDUX = 53 << 1, |
| 178 DCBST = 54 << 1, |
| 179 LWZUX = 55 << 1, // load word zero w/ update x-form |
| 180 CNTLZDX = 58 << 1, |
| 181 ANDCX = 60 << 1, |
| 182 MULHWX = 75 << 1, |
| 183 DCBF = 86 << 1, |
| 184 LBZX = 87 << 1, // load byte zero w/ x-form |
| 185 NEGX = 104 << 1, |
| 186 MFVSRWZ = 115 << 1, // Move From VSR Word And Zero |
| 187 LBZUX = 119 << 1, // load byte zero w/ update x-form |
| 188 NORX = 124 << 1, |
| 189 SUBFEX = 136 << 1, |
| 190 ADDEX = 138 << 1, |
| 191 STDX = 149 << 1, |
| 192 STWX = 151 << 1, // store word w/ x-form |
| 193 MTVSRD = 179 << 1, // Move To VSR Doubleword |
| 194 STDUX = 181 << 1, |
| 195 STWUX = 183 << 1, // store word w/ update x-form |
| 196 /* |
| 197 MTCRF |
| 198 MTMSR |
| 199 STWCXx |
| 200 SUBFZEX |
| 201 */ |
| 202 ADDZEX = 202 << 1, // Add to Zero Extended |
| 203 /* |
| 204 MTSR |
| 205 */ |
| 206 MTVSRWA = 211 << 1, // Move To VSR Word Algebraic |
| 207 STBX = 215 << 1, // store byte w/ x-form |
| 208 MULLD = 233 << 1, // Multiply Low Double Word |
| 209 MULLW = 235 << 1, // Multiply Low Word |
| 210 MTVSRWZ = 243 << 1, // Move To VSR Word And Zero |
| 211 STBUX = 247 << 1, // store byte w/ update x-form |
| 212 ADDX = 266 << 1, // Add |
| 213 LHZX = 279 << 1, // load half-word zero w/ x-form |
| 214 LHZUX = 311 << 1, // load half-word zero w/ update x-form |
| 215 LHAX = 343 << 1, // load half-word algebraic w/ x-form |
| 216 LHAUX = 375 << 1, // load half-word algebraic w/ update x-form |
| 217 XORX = 316 << 1, // Exclusive OR |
| 218 MFSPR = 339 << 1, // Move from Special-Purpose-Register |
| 219 STHX = 407 << 1, // store half-word w/ x-form |
| 220 STHUX = 439 << 1, // store half-word w/ update x-form |
| 221 ORX = 444 << 1, // Or |
| 222 MTSPR = 467 << 1, // Move to Special-Purpose-Register |
| 223 DIVD = 489 << 1, // Divide Double Word |
| 224 DIVW = 491 << 1, // Divide Word |
| 225 |
| 226 // Below represent bits 10-1 (any value >= 512) |
| 227 LFSX = 535 << 1, // load float-single w/ x-form |
| 228 SRWX = 536 << 1, // Shift Right Word |
| 229 SRDX = 539 << 1, // Shift Right Double Word |
| 230 LFSUX = 567 << 1, // load float-single w/ update x-form |
| 231 SYNC = 598 << 1, // Synchronize |
| 232 LFDX = 599 << 1, // load float-double w/ x-form |
| 233 LFDUX = 631 << 1, // load float-double w/ update X-form |
| 234 STFSX = 663 << 1, // store float-single w/ x-form |
| 235 STFSUX = 695 << 1, // store float-single w/ update x-form |
| 236 STFDX = 727 << 1, // store float-double w/ x-form |
| 237 STFDUX = 759 << 1, // store float-double w/ update x-form |
| 238 SRAW = 792 << 1, // Shift Right Algebraic Word |
| 239 SRAD = 794 << 1, // Shift Right Algebraic Double Word |
| 240 SRAWIX = 824 << 1, // Shift Right Algebraic Word Immediate |
| 241 SRADIX = 413 << 2, // Shift Right Algebraic Double Word Immediate |
| 242 EXTSH = 922 << 1, // Extend Sign Halfword |
| 243 EXTSB = 954 << 1, // Extend Sign Byte |
| 244 ICBI = 982 << 1, // Instruction Cache Block Invalidate |
| 245 EXTSW = 986 << 1 // Extend Sign Word |
| 246 }; |
| 247 |
| 248 // Some use Bits 10-1 and other only 5-1 for the opcode |
| 249 enum OpcodeExt4 { |
| 250 // Bits 5-1 |
| 251 FDIV = 18 << 1, // Floating Divide |
| 252 FSUB = 20 << 1, // Floating Subtract |
| 253 FADD = 21 << 1, // Floating Add |
| 254 FSQRT = 22 << 1, // Floating Square Root |
| 255 FSEL = 23 << 1, // Floating Select |
| 256 FMUL = 25 << 1, // Floating Multiply |
| 257 FMSUB = 28 << 1, // Floating Multiply-Subtract |
| 258 FMADD = 29 << 1, // Floating Multiply-Add |
| 259 |
| 260 // Bits 10-1 |
| 261 FCMPU = 0 << 1, // Floating Compare Unordered |
| 262 FRSP = 12 << 1, // Floating-Point Rounding |
| 263 FCTIW = 14 << 1, // Floating Convert to Integer Word X-form |
| 264 FCTIWZ = 15 << 1, // Floating Convert to Integer Word with Round to Zero |
| 265 FNEG = 40 << 1, // Floating Negate |
| 266 MCRFS = 64 << 1, // Move to Condition Register from FPSCR |
| 267 FMR = 72 << 1, // Floating Move Register |
| 268 MTFSFI = 134 << 1, // Move to FPSCR Field Immediate |
| 269 FABS = 264 << 1, // Floating Absolute Value |
| 270 FRIM = 488 << 1, // Floating Round to Integer Minus |
| 271 MFFS = 583 << 1, // move from FPSCR x-form |
| 272 MTFSF = 711 << 1, // move to FPSCR fields XFL-form |
| 273 FCFID = 846 << 1, // Floating convert from integer doubleword |
| 274 FCTID = 814 << 1, // Floating convert from integer doubleword |
| 275 FCTIDZ = 815 << 1 // Floating convert from integer doubleword |
| 276 }; |
| 277 |
| 278 enum OpcodeExt5 { |
| 279 // Bits 4-2 |
| 280 RLDICL = 0 << 1, // Rotate Left Double Word Immediate then Clear Left |
| 281 RLDICR = 2 << 1, // Rotate Left Double Word Immediate then Clear Right |
| 282 RLDIC = 4 << 1, // Rotate Left Double Word Immediate then Clear |
| 283 RLDIMI = 6 << 1, // Rotate Left Double Word Immediate then Mask Insert |
| 284 // Bits 4-1 |
| 285 RLDCL = 8 << 1, // Rotate Left Double Word then Clear Left |
| 286 RLDCR = 9 << 1 // Rotate Left Double Word then Clear Right |
| 287 }; |
| 288 |
| 289 // Instruction encoding bits and masks. |
| 290 enum { |
| 291 // Instruction encoding bit |
| 292 B1 = 1 << 1, |
| 293 B4 = 1 << 4, |
| 294 B5 = 1 << 5, |
| 295 B7 = 1 << 7, |
| 296 B8 = 1 << 8, |
| 297 B9 = 1 << 9, |
| 298 B12 = 1 << 12, |
| 299 B18 = 1 << 18, |
| 300 B19 = 1 << 19, |
| 301 B20 = 1 << 20, |
| 302 B22 = 1 << 22, |
| 303 B23 = 1 << 23, |
| 304 B24 = 1 << 24, |
| 305 B25 = 1 << 25, |
| 306 B26 = 1 << 26, |
| 307 B27 = 1 << 27, |
| 308 B28 = 1 << 28, |
| 309 B6 = 1 << 6, |
| 310 B10 = 1 << 10, |
| 311 B11 = 1 << 11, |
| 312 B16 = 1 << 16, |
| 313 B17 = 1 << 17, |
| 314 B21 = 1 << 21, |
| 315 |
| 316 // Instruction bit masks |
| 317 kCondMask = 0x1F << 21, |
| 318 kOff12Mask = (1 << 12) - 1, |
| 319 kImm24Mask = (1 << 24) - 1, |
| 320 kOff16Mask = (1 << 16) - 1, |
| 321 kImm16Mask = (1 << 16) - 1, |
| 322 kImm26Mask = (1 << 26) - 1, |
| 323 kBOfieldMask = 0x1f << 21, |
| 324 kOpcodeMask = 0x3f << 26, |
| 325 kExt1OpcodeMask = 0x3ff << 1, |
| 326 kExt2OpcodeMask = 0x1f << 1, |
| 327 kExt5OpcodeMask = 0x3 << 2, |
| 328 kBOMask = 0x1f << 21, |
| 329 kBIMask = 0x1F << 16, |
| 330 kBDMask = 0x14 << 2, |
| 331 kAAMask = 0x01 << 1, |
| 332 kLKMask = 0x01, |
| 333 kRCMask = 0x01, |
| 334 kTOMask = 0x1f << 21 |
| 335 }; |
| 336 |
| 337 // the following is to differentiate different faked opcodes for |
| 338 // the BOGUS PPC instruction we invented (when bit 25 is 0) or to mark |
| 339 // different stub code (when bit 25 is 1) |
| 340 // - use primary opcode 1 for undefined instruction |
| 341 // - use bit 25 to indicate whether the opcode is for fake-arm |
| 342 // instr or stub-marker |
| 343 // - use the least significant 6-bit to indicate FAKE_OPCODE_T or |
| 344 // MARKER_T |
| 345 #define FAKE_OPCODE 1 << 26 |
| 346 #define MARKER_SUBOPCODE_BIT 25 |
| 347 #define MARKER_SUBOPCODE 1 << MARKER_SUBOPCODE_BIT |
| 348 #define FAKER_SUBOPCODE 0 << MARKER_SUBOPCODE_BIT |
| 349 |
| 350 enum FAKE_OPCODE_T { |
| 351 fBKPT = 14, |
| 352 fLastFaker // can't be more than 128 (2^^7) |
| 353 }; |
| 354 #define FAKE_OPCODE_HIGH_BIT 7 // fake opcode has to fall into bit 0~7 |
| 355 #define F_NEXT_AVAILABLE_STUB_MARKER 369 // must be less than 2^^9 (512) |
| 356 #define STUB_MARKER_HIGH_BIT 9 // stub marker has to fall into bit 0~9 |
| 357 // ----------------------------------------------------------------------------- |
| 358 // Addressing modes and instruction variants. |
| 359 |
| 360 // Overflow Exception |
| 361 enum OEBit { |
| 362 SetOE = 1 << 10, // Set overflow exception |
| 363 LeaveOE = 0 << 10 // No overflow exception |
| 364 }; |
| 365 |
| 366 // Record bit |
| 367 enum RCBit { // Bit 0 |
| 368 SetRC = 1, // LT,GT,EQ,SO |
| 369 LeaveRC = 0 // None |
| 370 }; |
| 371 |
| 372 // Link bit |
| 373 enum LKBit { // Bit 0 |
| 374 SetLK = 1, // Load effective address of next instruction |
| 375 LeaveLK = 0 // No action |
| 376 }; |
| 377 |
| 378 enum BOfield { // Bits 25-21 |
| 379 DCBNZF = 0 << 21, // Decrement CTR; branch if CTR != 0 and condition false |
| 380 DCBEZF = 2 << 21, // Decrement CTR; branch if CTR == 0 and condition false |
| 381 BF = 4 << 21, // Branch if condition false |
| 382 DCBNZT = 8 << 21, // Decrement CTR; branch if CTR != 0 and condition true |
| 383 DCBEZT = 10 << 21, // Decrement CTR; branch if CTR == 0 and condition true |
| 384 BT = 12 << 21, // Branch if condition true |
| 385 DCBNZ = 16 << 21, // Decrement CTR; branch if CTR != 0 |
| 386 DCBEZ = 18 << 21, // Decrement CTR; branch if CTR == 0 |
| 387 BA = 20 << 21 // Branch always |
| 388 }; |
| 389 |
| 390 #if V8_OS_AIX |
| 391 #undef CR_LT |
| 392 #undef CR_GT |
| 393 #undef CR_EQ |
| 394 #undef CR_SO |
| 395 #endif |
| 396 |
| 397 enum CRBit { CR_LT = 0, CR_GT = 1, CR_EQ = 2, CR_SO = 3, CR_FU = 3 }; |
| 398 |
| 399 #define CRWIDTH 4 |
| 400 |
| 401 // ----------------------------------------------------------------------------- |
| 402 // Supervisor Call (svc) specific support. |
| 403 |
| 404 // Special Software Interrupt codes when used in the presence of the PPC |
| 405 // simulator. |
| 406 // svc (formerly swi) provides a 24bit immediate value. Use bits 22:0 for |
| 407 // standard SoftwareInterrupCode. Bit 23 is reserved for the stop feature. |
| 408 enum SoftwareInterruptCodes { |
| 409 // transition to C code |
| 410 kCallRtRedirected = 0x10, |
| 411 // break point |
| 412 kBreakpoint = 0x821008, // bits23-0 of 0x7d821008 = twge r2, r2 |
| 413 // stop |
| 414 kStopCode = 1 << 23, |
| 415 // info |
| 416 kInfo = 0x9ff808 // bits23-0 of 0x7d9ff808 = twge r31, r31 |
| 417 }; |
| 418 const uint32_t kStopCodeMask = kStopCode - 1; |
| 419 const uint32_t kMaxStopCode = kStopCode - 1; |
| 420 const int32_t kDefaultStopCode = -1; |
| 421 |
| 422 // FP rounding modes. |
| 423 enum FPRoundingMode { |
| 424 RN = 0, // Round to Nearest. |
| 425 RZ = 1, // Round towards zero. |
| 426 RP = 2, // Round towards Plus Infinity. |
| 427 RM = 3, // Round towards Minus Infinity. |
| 428 |
| 429 // Aliases. |
| 430 kRoundToNearest = RN, |
| 431 kRoundToZero = RZ, |
| 432 kRoundToPlusInf = RP, |
| 433 kRoundToMinusInf = RM |
| 434 }; |
| 435 |
| 436 const uint32_t kFPRoundingModeMask = 3; |
| 437 |
| 438 enum CheckForInexactConversion { |
| 439 kCheckForInexactConversion, |
| 440 kDontCheckForInexactConversion |
| 441 }; |
| 442 |
| 443 // ----------------------------------------------------------------------------- |
| 444 // Specific instructions, constants, and masks. |
| 445 // These constants are declared in assembler-arm.cc, as they use named registers |
| 446 // and other constants. |
| 447 |
| 448 |
| 449 // add(sp, sp, 4) instruction (aka Pop()) |
| 450 extern const Instr kPopInstruction; |
| 451 |
| 452 // str(r, MemOperand(sp, 4, NegPreIndex), al) instruction (aka push(r)) |
| 453 // register r is not encoded. |
| 454 extern const Instr kPushRegPattern; |
| 455 |
| 456 // ldr(r, MemOperand(sp, 4, PostIndex), al) instruction (aka pop(r)) |
| 457 // register r is not encoded. |
| 458 extern const Instr kPopRegPattern; |
| 459 |
| 460 // use TWI to indicate redirection call for simulation mode |
| 461 const Instr rtCallRedirInstr = TWI; |
| 462 |
| 463 // ----------------------------------------------------------------------------- |
| 464 // Instruction abstraction. |
| 465 |
| 466 // The class Instruction enables access to individual fields defined in the PPC |
| 467 // architecture instruction set encoding. |
| 468 // Note that the Assembler uses typedef int32_t Instr. |
| 469 // |
| 470 // Example: Test whether the instruction at ptr does set the condition code |
| 471 // bits. |
| 472 // |
| 473 // bool InstructionSetsConditionCodes(byte* ptr) { |
| 474 // Instruction* instr = Instruction::At(ptr); |
| 475 // int type = instr->TypeValue(); |
| 476 // return ((type == 0) || (type == 1)) && instr->HasS(); |
| 477 // } |
| 478 // |
| 479 class Instruction { |
| 480 public: |
| 481 enum { kInstrSize = 4, kInstrSizeLog2 = 2, kPCReadOffset = 8 }; |
| 482 |
| 483 // Helper macro to define static accessors. |
| 484 // We use the cast to char* trick to bypass the strict anti-aliasing rules. |
| 485 #define DECLARE_STATIC_TYPED_ACCESSOR(return_type, Name) \ |
| 486 static inline return_type Name(Instr instr) { \ |
| 487 char* temp = reinterpret_cast<char*>(&instr); \ |
| 488 return reinterpret_cast<Instruction*>(temp)->Name(); \ |
| 489 } |
| 490 |
| 491 #define DECLARE_STATIC_ACCESSOR(Name) DECLARE_STATIC_TYPED_ACCESSOR(int, Name) |
| 492 |
| 493 // Get the raw instruction bits. |
| 494 inline Instr InstructionBits() const { |
| 495 return *reinterpret_cast<const Instr*>(this); |
| 496 } |
| 497 |
| 498 // Set the raw instruction bits to value. |
| 499 inline void SetInstructionBits(Instr value) { |
| 500 *reinterpret_cast<Instr*>(this) = value; |
| 501 } |
| 502 |
| 503 // Read one particular bit out of the instruction bits. |
| 504 inline int Bit(int nr) const { return (InstructionBits() >> nr) & 1; } |
| 505 |
| 506 // Read a bit field's value out of the instruction bits. |
| 507 inline int Bits(int hi, int lo) const { |
| 508 return (InstructionBits() >> lo) & ((2 << (hi - lo)) - 1); |
| 509 } |
| 510 |
| 511 // Read a bit field out of the instruction bits. |
| 512 inline int BitField(int hi, int lo) const { |
| 513 return InstructionBits() & (((2 << (hi - lo)) - 1) << lo); |
| 514 } |
| 515 |
| 516 // Static support. |
| 517 |
| 518 // Read one particular bit out of the instruction bits. |
| 519 static inline int Bit(Instr instr, int nr) { return (instr >> nr) & 1; } |
| 520 |
| 521 // Read the value of a bit field out of the instruction bits. |
| 522 static inline int Bits(Instr instr, int hi, int lo) { |
| 523 return (instr >> lo) & ((2 << (hi - lo)) - 1); |
| 524 } |
| 525 |
| 526 |
| 527 // Read a bit field out of the instruction bits. |
| 528 static inline int BitField(Instr instr, int hi, int lo) { |
| 529 return instr & (((2 << (hi - lo)) - 1) << lo); |
| 530 } |
| 531 |
| 532 inline int RSValue() const { return Bits(25, 21); } |
| 533 inline int RTValue() const { return Bits(25, 21); } |
| 534 inline int RAValue() const { return Bits(20, 16); } |
| 535 DECLARE_STATIC_ACCESSOR(RAValue); |
| 536 inline int RBValue() const { return Bits(15, 11); } |
| 537 DECLARE_STATIC_ACCESSOR(RBValue); |
| 538 inline int RCValue() const { return Bits(10, 6); } |
| 539 DECLARE_STATIC_ACCESSOR(RCValue); |
| 540 |
| 541 inline int OpcodeValue() const { return static_cast<Opcode>(Bits(31, 26)); } |
| 542 inline Opcode OpcodeField() const { |
| 543 return static_cast<Opcode>(BitField(24, 21)); |
| 544 } |
| 545 |
| 546 // Fields used in Software interrupt instructions |
| 547 inline SoftwareInterruptCodes SvcValue() const { |
| 548 return static_cast<SoftwareInterruptCodes>(Bits(23, 0)); |
| 549 } |
| 550 |
| 551 // Instructions are read of out a code stream. The only way to get a |
| 552 // reference to an instruction is to convert a pointer. There is no way |
| 553 // to allocate or create instances of class Instruction. |
| 554 // Use the At(pc) function to create references to Instruction. |
| 555 static Instruction* At(byte* pc) { |
| 556 return reinterpret_cast<Instruction*>(pc); |
| 557 } |
| 558 |
| 559 |
| 560 private: |
| 561 // We need to prevent the creation of instances of class Instruction. |
| 562 DISALLOW_IMPLICIT_CONSTRUCTORS(Instruction); |
| 563 }; |
| 564 |
| 565 |
| 566 // Helper functions for converting between register numbers and names. |
| 567 class Registers { |
| 568 public: |
| 569 // Return the name of the register. |
| 570 static const char* Name(int reg); |
| 571 |
| 572 // Lookup the register number for the name provided. |
| 573 static int Number(const char* name); |
| 574 |
| 575 struct RegisterAlias { |
| 576 int reg; |
| 577 const char* name; |
| 578 }; |
| 579 |
| 580 private: |
| 581 static const char* names_[kNumRegisters]; |
| 582 static const RegisterAlias aliases_[]; |
| 583 }; |
| 584 |
| 585 // Helper functions for converting between FP register numbers and names. |
| 586 class FPRegisters { |
| 587 public: |
| 588 // Return the name of the register. |
| 589 static const char* Name(int reg); |
| 590 |
| 591 // Lookup the register number for the name provided. |
| 592 static int Number(const char* name); |
| 593 |
| 594 private: |
| 595 static const char* names_[kNumFPRegisters]; |
| 596 }; |
| 597 } |
| 598 } // namespace v8::internal |
| 599 |
| 600 #endif // V8_PPC_CONSTANTS_PPC_H_ |
OLD | NEW |