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