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_EXECUTION_MIPS_FRAME_CONSTANTS_MIPS_H_
6#define V8_EXECUTION_MIPS_FRAME_CONSTANTS_MIPS_H_
7
8#include "src/base/bits.h"
9#include "src/base/macros.h"
10#include "src/codegen/register.h"
11#include "src/execution/frame-constants.h"
12
13namespace v8 {
14namespace internal {
15
16class EntryFrameConstants : public AllStatic {
17 public:
18  // This is the offset to where JSEntry pushes the current value of
19  // Isolate::c_entry_fp onto the stack.
20  static constexpr int kCallerFPOffset = -3 * kSystemPointerSize;
21
22  // Stack offsets for arguments passed to JSEntry.
23  static constexpr int kArgcOffset = +0 * kSystemPointerSize;
24  static constexpr int kArgvOffset = +1 * kSystemPointerSize;
25};
26
27class WasmCompileLazyFrameConstants : public TypedFrameConstants {
28 public:
29  static constexpr int kNumberOfSavedGpParamRegs = 3;
30  static constexpr int kNumberOfSavedFpParamRegs = 7;
31  static constexpr int kNumberOfSavedAllParamRegs = 10;
32
33  // FP-relative.
34  // See Generate_WasmCompileLazy in builtins-mips.cc.
35  static constexpr int kWasmInstanceOffset =
36      TYPED_FRAME_PUSHED_VALUE_OFFSET(kNumberOfSavedAllParamRegs);
37  static constexpr int kFixedFrameSizeFromFp =
38      TypedFrameConstants::kFixedFrameSizeFromFp +
39      kNumberOfSavedGpParamRegs * kPointerSize +
40      kNumberOfSavedFpParamRegs * kDoubleSize;
41};
42
43// Frame constructed by the {WasmDebugBreak} builtin.
44// After pushing the frame type marker, the builtin pushes all Liftoff cache
45// registers (see liftoff-assembler-defs.h).
46class WasmDebugBreakFrameConstants : public TypedFrameConstants {
47 public:
48  // {v0, v1, a0, a1, a2, a3, t0, t1, t2, t3, t4, t5, t6, s7}
49  static constexpr RegList kPushedGpRegs = {v0, v1, a0, a1, a2, a3, t0,
50                                            t1, t2, t3, t4, t5, t6, s7};
51  // {f0, f2, f4, f6, f8, f10, f12, f14, f16, f18, f20, f22, f24}
52  static constexpr DoubleRegList kPushedFpRegs = {
53      f0, f2, f4, f6, f8, f10, f12, f14, f16, f18, f20, f22, f24};
54
55  static constexpr int kNumPushedGpRegisters = kPushedGpRegs.Count();
56  static constexpr int kNumPushedFpRegisters = kPushedFpRegs.Count();
57
58  static constexpr int kLastPushedGpRegisterOffset =
59      -kFixedFrameSizeFromFp - kNumPushedGpRegisters * kSystemPointerSize;
60  static constexpr int kLastPushedFpRegisterOffset =
61      kLastPushedGpRegisterOffset - kNumPushedFpRegisters * kDoubleSize;
62
63  // Offsets are fp-relative.
64  static int GetPushedGpRegisterOffset(int reg_code) {
65    DCHECK_NE(0, kPushedGpRegs.bits() & (1 << reg_code));
66    uint32_t lower_regs =
67        kPushedGpRegs.bits() & ((uint32_t{1} << reg_code) - 1);
68    return kLastPushedGpRegisterOffset +
69           base::bits::CountPopulation(lower_regs) * kSystemPointerSize;
70  }
71
72  static int GetPushedFpRegisterOffset(int reg_code) {
73    DCHECK_NE(0, kPushedFpRegs.bits() & (1 << reg_code));
74    uint32_t lower_regs =
75        kPushedFpRegs.bits() & ((uint32_t{1} << reg_code) - 1);
76    return kLastPushedFpRegisterOffset +
77           base::bits::CountPopulation(lower_regs) * kDoubleSize;
78  }
79};
80
81}  // namespace internal
82}  // namespace v8
83
84#endif  // V8_EXECUTION_MIPS_FRAME_CONSTANTS_MIPS_H_
85