• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_X64_FRAME_CONSTANTS_X64_H_
6 #define V8_EXECUTION_X64_FRAME_CONSTANTS_X64_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 #ifdef V8_TARGET_OS_WIN
18   static constexpr int kCalleeSaveXMMRegisters = 10;
19   static constexpr int kXMMRegisterSize = 16;
20   static constexpr int kXMMRegistersBlockSize =
21       kXMMRegisterSize * kCalleeSaveXMMRegisters;
22 
23   // This is the offset to where JSEntry pushes the current value of
24   // Isolate::c_entry_fp onto the stack.
25   // On x64, there are 7 pushq() and 3 Push() calls between setting up rbp and
26   // pushing the c_entry_fp, plus we manually allocate kXMMRegistersBlockSize
27   // bytes on the stack.
28   static constexpr int kCallerFPOffset = -3 * kSystemPointerSize +
29                                          -7 * kSystemPointerSize -
30                                          kXMMRegistersBlockSize;
31 
32   // Stack offsets for arguments passed to JSEntry.
33   static constexpr int kArgcOffset = 6 * kSystemPointerSize;
34   static constexpr int kArgvOffset = 7 * kSystemPointerSize;
35 #else
36   // This is the offset to where JSEntry pushes the current value of
37   // Isolate::c_entry_fp onto the stack.
38   // On x64, there are 5 pushq() and 3 Push() calls between setting up rbp and
39   // pushing the c_entry_fp.
40   static constexpr int kCallerFPOffset =
41       -3 * kSystemPointerSize + -5 * kSystemPointerSize;
42 #endif
43 };
44 
45 class WasmCompileLazyFrameConstants : public TypedFrameConstants {
46  public:
47   static constexpr int kNumberOfSavedGpParamRegs = 6;
48   static constexpr int kNumberOfSavedFpParamRegs = 6;
49 
50   // FP-relative.
51   static constexpr int kWasmInstanceOffset = TYPED_FRAME_PUSHED_VALUE_OFFSET(0);
52   static constexpr int kFixedFrameSizeFromFp =
53       TypedFrameConstants::kFixedFrameSizeFromFp +
54       kNumberOfSavedGpParamRegs * kSystemPointerSize +
55       kNumberOfSavedFpParamRegs * kSimd128Size;
56 };
57 
58 // Frame constructed by the {WasmDebugBreak} builtin.
59 // After pushing the frame type marker, the builtin pushes all Liftoff cache
60 // registers (see liftoff-assembler-defs.h).
61 class WasmDebugBreakFrameConstants : public TypedFrameConstants {
62  public:
63   // {rax, rcx, rdx, rbx, rsi, rdi, r9}
64   static constexpr uint32_t kPushedGpRegs = 0b1011001111;
65   // {xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7}
66   static constexpr uint32_t kPushedFpRegs = 0b11111111;
67 
68   static constexpr int kNumPushedGpRegisters =
69       base::bits::CountPopulation(kPushedGpRegs);
70   static constexpr int kNumPushedFpRegisters =
71       base::bits::CountPopulation(kPushedFpRegs);
72 
73   static constexpr int kLastPushedGpRegisterOffset =
74       -kFixedFrameSizeFromFp - kNumPushedGpRegisters * kSystemPointerSize;
75   static constexpr int kLastPushedFpRegisterOffset =
76       kLastPushedGpRegisterOffset - kNumPushedFpRegisters * kSimd128Size;
77 
78   // Offsets are fp-relative.
GetPushedGpRegisterOffset(int reg_code)79   static int GetPushedGpRegisterOffset(int reg_code) {
80     DCHECK_NE(0, kPushedGpRegs & (1 << reg_code));
81     uint32_t lower_regs = kPushedGpRegs & ((uint32_t{1} << reg_code) - 1);
82     return kLastPushedGpRegisterOffset +
83            base::bits::CountPopulation(lower_regs) * kSystemPointerSize;
84   }
85 
GetPushedFpRegisterOffset(int reg_code)86   static int GetPushedFpRegisterOffset(int reg_code) {
87     DCHECK_NE(0, kPushedFpRegs & (1 << reg_code));
88     uint32_t lower_regs = kPushedFpRegs & ((uint32_t{1} << reg_code) - 1);
89     return kLastPushedFpRegisterOffset +
90            base::bits::CountPopulation(lower_regs) * kSimd128Size;
91   }
92 };
93 
94 }  // namespace internal
95 }  // namespace v8
96 
97 #endif  // V8_EXECUTION_X64_FRAME_CONSTANTS_X64_H_
98