99d31b432f
This CL allows us to distinguish between the host- and target OS. The host OS is defined by V8_OS_ macros (e.g. V8_OS_WIN). The target OS is defined by V8_TARGET_OS_ macros (e.g. V8_TARGET_OS_WIN). V8_TARGET_OS_ macros are defined by gn, based on the `target_os` gn variable. If a V8_TARGET_OS_ is set, we also define V8_HAVE_TARGET_OS (this determines fall-back behavior in V8; if it is not defined, we set V8_TARGET_OS_ to equal the equivalent V8_OS_ define). Besides adding the defines, this CL also adds logic to consider the target OS in codegen. Specifically, x64 builds now look at the V8_TARGET_OS_WIN define instead of V8_OS_WIN or _WIN64. This effectively makes cross-compilation to x64 Windows in mksnapshot possible. In future work, we could add similar support for cross-compiling to other platforms such as ia32 Windows. Bug: v8:9736,chromium:803591 Change-Id: I689f3de8c206b743c4bef703f5ade0bba32ce995 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1809374 Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Michael Achenbach <machenbach@chromium.org> Commit-Queue: Jakob Gruber <jgruber@chromium.org> Cr-Commit-Position: refs/heads/master@{#63892}
241 lines
10 KiB
C++
241 lines
10 KiB
C++
// Copyright 2015 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "src/codegen/assembler-inl.h"
|
|
#include "src/codegen/macro-assembler.h"
|
|
|
|
#include "src/compiler/linkage.h"
|
|
|
|
#include "src/zone/zone.h"
|
|
|
|
namespace v8 {
|
|
namespace internal {
|
|
namespace compiler {
|
|
|
|
namespace {
|
|
|
|
// Platform-specific configuration for C calling convention.
|
|
#if V8_TARGET_ARCH_IA32
|
|
// ===========================================================================
|
|
// == ia32 ===================================================================
|
|
// ===========================================================================
|
|
#define CALLEE_SAVE_REGISTERS esi.bit() | edi.bit() | ebx.bit()
|
|
|
|
#elif V8_TARGET_ARCH_X64
|
|
// ===========================================================================
|
|
// == x64 ====================================================================
|
|
// ===========================================================================
|
|
|
|
#ifdef V8_TARGET_OS_WIN
|
|
// == x64 windows ============================================================
|
|
#define STACK_SHADOW_WORDS 4
|
|
#define PARAM_REGISTERS rcx, rdx, r8, r9
|
|
#define CALLEE_SAVE_REGISTERS \
|
|
rbx.bit() | rdi.bit() | rsi.bit() | r12.bit() | r13.bit() | r14.bit() | \
|
|
r15.bit()
|
|
#define CALLEE_SAVE_FP_REGISTERS \
|
|
(1 << xmm6.code()) | (1 << xmm7.code()) | (1 << xmm8.code()) | \
|
|
(1 << xmm9.code()) | (1 << xmm10.code()) | (1 << xmm11.code()) | \
|
|
(1 << xmm12.code()) | (1 << xmm13.code()) | (1 << xmm14.code()) | \
|
|
(1 << xmm15.code())
|
|
#else // V8_TARGET_OS_WIN
|
|
// == x64 other ==============================================================
|
|
#define PARAM_REGISTERS rdi, rsi, rdx, rcx, r8, r9
|
|
#define CALLEE_SAVE_REGISTERS \
|
|
rbx.bit() | r12.bit() | r13.bit() | r14.bit() | r15.bit()
|
|
#endif // V8_TARGET_OS_WIN
|
|
|
|
#elif V8_TARGET_ARCH_ARM
|
|
// ===========================================================================
|
|
// == arm ====================================================================
|
|
// ===========================================================================
|
|
#define PARAM_REGISTERS r0, r1, r2, r3
|
|
#define CALLEE_SAVE_REGISTERS \
|
|
r4.bit() | r5.bit() | r6.bit() | r7.bit() | r8.bit() | r9.bit() | r10.bit()
|
|
#define CALLEE_SAVE_FP_REGISTERS \
|
|
(1 << d8.code()) | (1 << d9.code()) | (1 << d10.code()) | \
|
|
(1 << d11.code()) | (1 << d12.code()) | (1 << d13.code()) | \
|
|
(1 << d14.code()) | (1 << d15.code())
|
|
|
|
|
|
#elif V8_TARGET_ARCH_ARM64
|
|
// ===========================================================================
|
|
// == arm64 ====================================================================
|
|
// ===========================================================================
|
|
#define PARAM_REGISTERS x0, x1, x2, x3, x4, x5, x6, x7
|
|
#define CALLEE_SAVE_REGISTERS \
|
|
(1 << x19.code()) | (1 << x20.code()) | (1 << x21.code()) | \
|
|
(1 << x22.code()) | (1 << x23.code()) | (1 << x24.code()) | \
|
|
(1 << x25.code()) | (1 << x26.code()) | (1 << x27.code()) | \
|
|
(1 << x28.code()) | (1 << x29.code()) | (1 << x30.code())
|
|
|
|
|
|
#define CALLEE_SAVE_FP_REGISTERS \
|
|
(1 << d8.code()) | (1 << d9.code()) | (1 << d10.code()) | \
|
|
(1 << d11.code()) | (1 << d12.code()) | (1 << d13.code()) | \
|
|
(1 << d14.code()) | (1 << d15.code())
|
|
|
|
#elif V8_TARGET_ARCH_MIPS
|
|
// ===========================================================================
|
|
// == mips ===================================================================
|
|
// ===========================================================================
|
|
#define STACK_SHADOW_WORDS 4
|
|
#define PARAM_REGISTERS a0, a1, a2, a3
|
|
#define CALLEE_SAVE_REGISTERS \
|
|
s0.bit() | s1.bit() | s2.bit() | s3.bit() | s4.bit() | s5.bit() | s6.bit() | \
|
|
s7.bit()
|
|
#define CALLEE_SAVE_FP_REGISTERS \
|
|
f20.bit() | f22.bit() | f24.bit() | f26.bit() | f28.bit() | f30.bit()
|
|
|
|
#elif V8_TARGET_ARCH_MIPS64
|
|
// ===========================================================================
|
|
// == mips64 =================================================================
|
|
// ===========================================================================
|
|
#define PARAM_REGISTERS a0, a1, a2, a3, a4, a5, a6, a7
|
|
#define CALLEE_SAVE_REGISTERS \
|
|
s0.bit() | s1.bit() | s2.bit() | s3.bit() | s4.bit() | s5.bit() | s6.bit() | \
|
|
s7.bit()
|
|
#define CALLEE_SAVE_FP_REGISTERS \
|
|
f20.bit() | f22.bit() | f24.bit() | f26.bit() | f28.bit() | f30.bit()
|
|
|
|
#elif V8_TARGET_ARCH_PPC64
|
|
// ===========================================================================
|
|
// == ppc & ppc64 ============================================================
|
|
// ===========================================================================
|
|
#ifdef V8_TARGET_LITTLE_ENDIAN // ppc64le linux
|
|
#define STACK_SHADOW_WORDS 12
|
|
#else // AIX
|
|
#define STACK_SHADOW_WORDS 14
|
|
#endif
|
|
#define PARAM_REGISTERS r3, r4, r5, r6, r7, r8, r9, r10
|
|
#define CALLEE_SAVE_REGISTERS \
|
|
r14.bit() | r15.bit() | r16.bit() | r17.bit() | r18.bit() | r19.bit() | \
|
|
r20.bit() | r21.bit() | r22.bit() | r23.bit() | r24.bit() | r25.bit() | \
|
|
r26.bit() | r27.bit() | r28.bit() | r29.bit() | r30.bit()
|
|
#define CALLEE_SAVE_FP_REGISTERS \
|
|
d14.bit() | d15.bit() | d16.bit() | d17.bit() | d18.bit() | d19.bit() | \
|
|
d20.bit() | d21.bit() | d22.bit() | d23.bit() | d24.bit() | d25.bit() | \
|
|
d26.bit() | d27.bit() | d28.bit() | d29.bit() | d30.bit() | d31.bit()
|
|
|
|
#elif V8_TARGET_ARCH_S390X
|
|
// ===========================================================================
|
|
// == s390x ==================================================================
|
|
// ===========================================================================
|
|
#define STACK_SHADOW_WORDS 20
|
|
#define PARAM_REGISTERS r2, r3, r4, r5, r6
|
|
#define CALLEE_SAVE_REGISTERS \
|
|
r6.bit() | r7.bit() | r8.bit() | r9.bit() | r10.bit() | ip.bit() | r13.bit()
|
|
#define CALLEE_SAVE_FP_REGISTERS \
|
|
d8.bit() | d9.bit() | d10.bit() | d11.bit() | d12.bit() | d13.bit() | \
|
|
d14.bit() | d15.bit()
|
|
|
|
#else
|
|
// ===========================================================================
|
|
// == unknown ================================================================
|
|
// ===========================================================================
|
|
#define UNSUPPORTED_C_LINKAGE 1
|
|
#endif
|
|
} // namespace
|
|
|
|
|
|
// General code uses the above configuration data.
|
|
CallDescriptor* Linkage::GetSimplifiedCDescriptor(Zone* zone,
|
|
const MachineSignature* msig,
|
|
CallDescriptor::Flags flags) {
|
|
DCHECK_LE(msig->parameter_count(), static_cast<size_t>(kMaxCParameters));
|
|
|
|
LocationSignature::Builder locations(zone, msig->return_count(),
|
|
msig->parameter_count());
|
|
// Check the types of the signature.
|
|
// Currently no floating point parameters or returns are allowed because
|
|
// on ia32, the FP top of stack is involved.
|
|
for (size_t i = 0; i < msig->return_count(); i++) {
|
|
MachineRepresentation rep = msig->GetReturn(i).representation();
|
|
CHECK_NE(MachineRepresentation::kFloat32, rep);
|
|
CHECK_NE(MachineRepresentation::kFloat64, rep);
|
|
}
|
|
for (size_t i = 0; i < msig->parameter_count(); i++) {
|
|
MachineRepresentation rep = msig->GetParam(i).representation();
|
|
CHECK_NE(MachineRepresentation::kFloat32, rep);
|
|
CHECK_NE(MachineRepresentation::kFloat64, rep);
|
|
}
|
|
|
|
#ifdef UNSUPPORTED_C_LINKAGE
|
|
// This method should not be called on unknown architectures.
|
|
FATAL("requested C call descriptor on unsupported architecture");
|
|
return nullptr;
|
|
#endif
|
|
|
|
// Add return location(s).
|
|
CHECK_GE(2, locations.return_count_);
|
|
|
|
if (locations.return_count_ > 0) {
|
|
locations.AddReturn(LinkageLocation::ForRegister(kReturnRegister0.code(),
|
|
msig->GetReturn(0)));
|
|
}
|
|
if (locations.return_count_ > 1) {
|
|
locations.AddReturn(LinkageLocation::ForRegister(kReturnRegister1.code(),
|
|
msig->GetReturn(1)));
|
|
}
|
|
|
|
const int parameter_count = static_cast<int>(msig->parameter_count());
|
|
|
|
#ifdef PARAM_REGISTERS
|
|
const v8::internal::Register kParamRegisters[] = {PARAM_REGISTERS};
|
|
const int kParamRegisterCount = static_cast<int>(arraysize(kParamRegisters));
|
|
#else
|
|
const v8::internal::Register* kParamRegisters = nullptr;
|
|
const int kParamRegisterCount = 0;
|
|
#endif
|
|
|
|
#ifdef STACK_SHADOW_WORDS
|
|
int stack_offset = STACK_SHADOW_WORDS;
|
|
#else
|
|
int stack_offset = 0;
|
|
#endif
|
|
// Add register and/or stack parameter(s).
|
|
for (int i = 0; i < parameter_count; i++) {
|
|
if (i < kParamRegisterCount) {
|
|
locations.AddParam(LinkageLocation::ForRegister(kParamRegisters[i].code(),
|
|
msig->GetParam(i)));
|
|
} else {
|
|
locations.AddParam(LinkageLocation::ForCallerFrameSlot(
|
|
-1 - stack_offset, msig->GetParam(i)));
|
|
stack_offset++;
|
|
}
|
|
}
|
|
|
|
#ifdef CALLEE_SAVE_REGISTERS
|
|
const RegList kCalleeSaveRegisters = CALLEE_SAVE_REGISTERS;
|
|
#else
|
|
const RegList kCalleeSaveRegisters = 0;
|
|
#endif
|
|
|
|
#ifdef CALLEE_SAVE_FP_REGISTERS
|
|
const RegList kCalleeSaveFPRegisters = CALLEE_SAVE_FP_REGISTERS;
|
|
#else
|
|
const RegList kCalleeSaveFPRegisters = 0;
|
|
#endif
|
|
|
|
// The target for C calls is always an address (i.e. machine pointer).
|
|
MachineType target_type = MachineType::Pointer();
|
|
LinkageLocation target_loc = LinkageLocation::ForAnyRegister(target_type);
|
|
flags |= CallDescriptor::kNoAllocate;
|
|
|
|
return new (zone) CallDescriptor( // --
|
|
CallDescriptor::kCallAddress, // kind
|
|
target_type, // target MachineType
|
|
target_loc, // target location
|
|
locations.Build(), // location_sig
|
|
0, // stack_parameter_count
|
|
Operator::kNoThrow, // properties
|
|
kCalleeSaveRegisters, // callee-saved registers
|
|
kCalleeSaveFPRegisters, // callee-saved fp regs
|
|
flags, "c-call");
|
|
}
|
|
|
|
} // namespace compiler
|
|
} // namespace internal
|
|
} // namespace v8
|