1 // Copyright 2012 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_EXECUTION_IA32_FRAME_CONSTANTS_IA32_H_ 6 #define V8_EXECUTION_IA32_FRAME_CONSTANTS_IA32_H_ 7 8 #include "src/base/bits.h" 9 #include "src/base/macros.h" 10 #include "src/execution/frame-constants.h" 11 12 namespace v8 { 13 namespace internal { 14 15 class EntryFrameConstants : public AllStatic { 16 public: 17 // This is the offset to where JSEntry pushes the current value of 18 // Isolate::c_entry_fp onto the stack. 19 static constexpr int kCallerFPOffset = -6 * kSystemPointerSize; 20 21 // EntryFrame is used by JSEntry, JSConstructEntry and JSRunMicrotasksEntry. 22 // All of them take |root_register_value| as the first parameter. 23 static constexpr int kRootRegisterValueOffset = +2 * kSystemPointerSize; 24 25 // Rest of parameters passed to JSEntry and JSConstructEntry. 26 static constexpr int kNewTargetArgOffset = +3 * kSystemPointerSize; 27 static constexpr int kFunctionArgOffset = +4 * kSystemPointerSize; 28 static constexpr int kReceiverArgOffset = +5 * kSystemPointerSize; 29 static constexpr int kArgcOffset = +6 * kSystemPointerSize; 30 static constexpr int kArgvOffset = +7 * kSystemPointerSize; 31 32 // Rest of parameters passed to JSRunMicrotasksEntry. 33 static constexpr int kMicrotaskQueueArgOffset = +3 * kSystemPointerSize; 34 }; 35 36 class WasmCompileLazyFrameConstants : public TypedFrameConstants { 37 public: 38 static constexpr int kNumberOfSavedGpParamRegs = 4; 39 static constexpr int kNumberOfSavedFpParamRegs = 6; 40 41 // FP-relative. 42 static constexpr int kWasmInstanceOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(0); 43 static constexpr int kFixedFrameSizeFromFp = 44 TypedFrameConstants::kFixedFrameSizeFromFp + 45 kNumberOfSavedGpParamRegs * kSystemPointerSize + 46 kNumberOfSavedFpParamRegs * kSimd128Size; 47 }; 48 49 // Frame constructed by the {WasmDebugBreak} builtin. 50 // After pushing the frame type marker, the builtin pushes all Liftoff cache 51 // registers (see liftoff-assembler-defs.h). 52 class WasmDebugBreakFrameConstants : public TypedFrameConstants { 53 public: 54 // {eax, ecx, edx, esi, edi} 55 static constexpr uint32_t kPushedGpRegs = 0b11000111; 56 // {xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6} 57 static constexpr uint32_t kPushedFpRegs = 0b01111111; 58 59 static constexpr int kNumPushedGpRegisters = 60 base::bits::CountPopulation(kPushedGpRegs); 61 static constexpr int kNumPushedFpRegisters = 62 base::bits::CountPopulation(kPushedFpRegs); 63 64 static constexpr int kLastPushedGpRegisterOffset = 65 -kFixedFrameSizeFromFp - kNumPushedGpRegisters * kSystemPointerSize; 66 static constexpr int kLastPushedFpRegisterOffset = 67 kLastPushedGpRegisterOffset - kNumPushedFpRegisters * kSimd128Size; 68 69 // Offsets are fp-relative. GetPushedGpRegisterOffset(int reg_code)70 static int GetPushedGpRegisterOffset(int reg_code) { 71 DCHECK_NE(0, kPushedGpRegs & (1 << reg_code)); 72 uint32_t lower_regs = kPushedGpRegs & ((uint32_t{1} << reg_code) - 1); 73 return kLastPushedGpRegisterOffset + 74 base::bits::CountPopulation(lower_regs) * kSystemPointerSize; 75 } 76 GetPushedFpRegisterOffset(int reg_code)77 static int GetPushedFpRegisterOffset(int reg_code) { 78 DCHECK_NE(0, kPushedFpRegs & (1 << reg_code)); 79 uint32_t lower_regs = kPushedFpRegs & ((uint32_t{1} << reg_code) - 1); 80 return kLastPushedFpRegisterOffset + 81 base::bits::CountPopulation(lower_regs) * kSimd128Size; 82 } 83 }; 84 85 } // namespace internal 86 } // namespace v8 87 88 #endif // V8_EXECUTION_IA32_FRAME_CONSTANTS_IA32_H_ 89