1// Copyright 2021 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_RISCV64_FRAME_CONSTANTS_RISCV64_H_ 6#define V8_EXECUTION_RISCV64_FRAME_CONSTANTS_RISCV64_H_ 7 8#include "src/base/bits.h" 9#include "src/base/macros.h" 10#include "src/execution/frame-constants.h" 11#include "src/wasm/baseline/liftoff-assembler-defs.h" 12#include "src/wasm/wasm-linkage.h" 13 14namespace v8 { 15namespace internal { 16 17class EntryFrameConstants : public AllStatic { 18 public: 19 // This is the offset to where JSEntry pushes the current value of 20 // Isolate::c_entry_fp onto the stack. 21 static constexpr int kCallerFPOffset = -3 * kSystemPointerSize; 22}; 23 24class WasmCompileLazyFrameConstants : public TypedFrameConstants { 25 public: 26 static constexpr int kNumberOfSavedGpParamRegs = 27 arraysize(wasm::kGpParamRegisters); 28 static constexpr int kNumberOfSavedFpParamRegs = 29 arraysize(wasm::kFpParamRegisters); 30 static constexpr int kNumberOfSavedAllParamRegs = 31 kNumberOfSavedGpParamRegs + kNumberOfSavedFpParamRegs; 32 33 // FP-relative. 34 // See Generate_WasmCompileLazy in builtins-riscv64.cc. 35 // TODO(riscv): add rvv v reg save 36 static constexpr int kWasmInstanceOffset = 37 TYPED_FRAME_PUSHED_VALUE_OFFSET(kNumberOfSavedAllParamRegs); 38 static constexpr int kFixedFrameSizeFromFp = 39 TypedFrameConstants::kFixedFrameSizeFromFp + 40 kNumberOfSavedGpParamRegs * kSystemPointerSize + 41 kNumberOfSavedFpParamRegs * kDoubleSize; 42}; 43 44// Frame constructed by the {WasmDebugBreak} builtin. 45// After pushing the frame type marker, the builtin pushes all Liftoff cache 46// registers (see liftoff-assembler-defs.h). 47class WasmDebugBreakFrameConstants : public TypedFrameConstants { 48 public: 49 static constexpr RegList kPushedGpRegs = wasm::kLiftoffAssemblerGpCacheRegs; 50 51 static constexpr DoubleRegList kPushedFpRegs = 52 wasm::kLiftoffAssemblerFpCacheRegs; 53 54 static constexpr int kNumPushedGpRegisters = kPushedGpRegs.Count(); 55 static constexpr int kNumPushedFpRegisters = kPushedFpRegs.Count(); 56 57 static constexpr int kLastPushedGpRegisterOffset = 58 -kFixedFrameSizeFromFp - kNumPushedGpRegisters * kSystemPointerSize; 59 static constexpr int kLastPushedFpRegisterOffset = 60 kLastPushedGpRegisterOffset - kNumPushedFpRegisters * kDoubleSize; 61 62 // Offsets are fp-relative. 63 static int GetPushedGpRegisterOffset(int reg_code) { 64 DCHECK_NE(0, kPushedGpRegs.bits() & (1 << reg_code)); 65 uint32_t lower_regs = 66 kPushedGpRegs.bits() & ((uint32_t{1} << reg_code) - 1); 67 return kLastPushedGpRegisterOffset + 68 base::bits::CountPopulation(lower_regs) * kSystemPointerSize; 69 } 70 71 static int GetPushedFpRegisterOffset(int reg_code) { 72 DCHECK_NE(0, kPushedFpRegs.bits() & (1 << reg_code)); 73 uint32_t lower_regs = 74 kPushedFpRegs.bits() & ((uint32_t{1} << reg_code) - 1); 75 return kLastPushedFpRegisterOffset + 76 base::bits::CountPopulation(lower_regs) * kDoubleSize; 77 } 78}; 79 80} // namespace internal 81} // namespace v8 82 83#endif // V8_EXECUTION_RISCV64_FRAME_CONSTANTS_RISCV64_H_ 84