1 /* 2 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 package org.graalvm.compiler.hotspot.aarch64; 26 27 import static jdk.vm.ci.aarch64.AArch64.r0; 28 import static jdk.vm.ci.aarch64.AArch64.r3; 29 import static jdk.vm.ci.hotspot.HotSpotCallingConventionType.NativeCall; 30 import static jdk.vm.ci.meta.Value.ILLEGAL; 31 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.JUMP_ADDRESS; 32 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.RegisterEffect.PRESERVES_REGISTERS; 33 import static org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage.Transition.LEAF; 34 import static org.graalvm.compiler.hotspot.replacements.CRC32CSubstitutions.UPDATE_BYTES_CRC32C; 35 import static org.graalvm.compiler.hotspot.replacements.CRC32Substitutions.UPDATE_BYTES_CRC32; 36 import static jdk.internal.vm.compiler.word.LocationIdentity.any; 37 38 import org.graalvm.compiler.core.common.LIRKind; 39 import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; 40 import org.graalvm.compiler.hotspot.HotSpotBackend; 41 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkageImpl; 42 import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider; 43 import org.graalvm.compiler.hotspot.meta.HotSpotHostForeignCallsProvider; 44 import org.graalvm.compiler.hotspot.meta.HotSpotProviders; 45 import org.graalvm.compiler.options.OptionValues; 46 import org.graalvm.compiler.word.WordTypes; 47 48 import jdk.vm.ci.code.CallingConvention; 49 import jdk.vm.ci.code.CodeCacheProvider; 50 import jdk.vm.ci.code.RegisterValue; 51 import jdk.vm.ci.code.TargetDescription; 52 import jdk.vm.ci.hotspot.HotSpotJVMCIRuntime; 53 import jdk.vm.ci.meta.MetaAccessProvider; 54 import jdk.vm.ci.meta.PlatformKind; 55 import jdk.vm.ci.meta.Value; 56 57 public class AArch64HotSpotForeignCallsProvider extends HotSpotHostForeignCallsProvider { 58 59 private final Value[] nativeABICallerSaveRegisters; 60 AArch64HotSpotForeignCallsProvider(HotSpotJVMCIRuntime jvmciRuntime, HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, CodeCacheProvider codeCache, WordTypes wordTypes, Value[] nativeABICallerSaveRegisters)61 public AArch64HotSpotForeignCallsProvider(HotSpotJVMCIRuntime jvmciRuntime, HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, CodeCacheProvider codeCache, 62 WordTypes wordTypes, Value[] nativeABICallerSaveRegisters) { 63 super(jvmciRuntime, runtime, metaAccess, codeCache, wordTypes); 64 this.nativeABICallerSaveRegisters = nativeABICallerSaveRegisters; 65 } 66 67 @Override initialize(HotSpotProviders providers, OptionValues options)68 public void initialize(HotSpotProviders providers, OptionValues options) { 69 GraalHotSpotVMConfig config = runtime.getVMConfig(); 70 TargetDescription target = providers.getCodeCache().getTarget(); 71 PlatformKind word = target.arch.getWordKind(); 72 73 // The calling convention for the exception handler stub is (only?) defined in 74 // TemplateInterpreterGenerator::generate_throw_exception() 75 RegisterValue exception = r0.asValue(LIRKind.reference(word)); 76 RegisterValue exceptionPc = r3.asValue(LIRKind.value(word)); 77 CallingConvention exceptionCc = new CallingConvention(0, ILLEGAL, exception, exceptionPc); 78 register(new HotSpotForeignCallLinkageImpl(HotSpotBackend.EXCEPTION_HANDLER, 0L, PRESERVES_REGISTERS, LEAF, exceptionCc, null, NOT_REEXECUTABLE, any())); 79 register(new HotSpotForeignCallLinkageImpl(HotSpotBackend.EXCEPTION_HANDLER_IN_CALLER, JUMP_ADDRESS, PRESERVES_REGISTERS, LEAF, exceptionCc, null, NOT_REEXECUTABLE, any())); 80 81 // These stubs do callee saving 82 if (config.useCRC32Intrinsics) { 83 registerForeignCall(UPDATE_BYTES_CRC32, config.updateBytesCRC32Stub, NativeCall, PRESERVES_REGISTERS, LEAF, NOT_REEXECUTABLE, any()); 84 } 85 if (config.useCRC32CIntrinsics) { 86 registerForeignCall(UPDATE_BYTES_CRC32C, config.updateBytesCRC32C, NativeCall, PRESERVES_REGISTERS, LEAF, NOT_REEXECUTABLE, any()); 87 } 88 89 super.initialize(providers, options); 90 } 91 92 @Override getNativeABICallerSaveRegisters()93 public Value[] getNativeABICallerSaveRegisters() { 94 return nativeABICallerSaveRegisters; 95 } 96 97 } 98