001/*
002 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.hotspot.sparc;
024
025import jdk.internal.jvmci.code.*;
026import jdk.internal.jvmci.hotspot.*;
027import jdk.internal.jvmci.meta.*;
028import static com.oracle.graal.hotspot.HotSpotBackend.*;
029import static com.oracle.graal.hotspot.HotSpotBackend.Options.*;
030import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.*;
031import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.RegisterEffect.*;
032import static com.oracle.graal.hotspot.HotSpotForeignCallLinkage.Transition.*;
033import static com.oracle.graal.hotspot.HotSpotHostBackend.*;
034import static jdk.internal.jvmci.meta.LocationIdentity.*;
035import static jdk.internal.jvmci.meta.Value.*;
036import static jdk.internal.jvmci.sparc.SPARC.*;
037
038import com.oracle.graal.hotspot.*;
039import com.oracle.graal.hotspot.meta.*;
040
041public class SPARCHotSpotForeignCallsProvider extends HotSpotHostForeignCallsProvider {
042
043    private final Value[] nativeABICallerSaveRegisters;
044
045    public SPARCHotSpotForeignCallsProvider(HotSpotGraalRuntimeProvider runtime, MetaAccessProvider metaAccess, CodeCacheProvider codeCache, Value[] nativeABICallerSaveRegisters) {
046        super(runtime, metaAccess, codeCache);
047        this.nativeABICallerSaveRegisters = nativeABICallerSaveRegisters;
048    }
049
050    @Override
051    public void initialize(HotSpotProviders providers, HotSpotVMConfig config) {
052        TargetDescription target = providers.getCodeCache().getTarget();
053        Kind word = target.wordKind;
054
055        // The calling convention for the exception handler stub is (only?) defined in
056        // TemplateInterpreterGenerator::generate_throw_exception()
057        // in templateInterpreter_sparc.cpp around line 1925
058        RegisterValue outgoingException = o0.asValue(target.getLIRKind(Kind.Object));
059        RegisterValue outgoingExceptionPc = o1.asValue(target.getLIRKind(word));
060        RegisterValue incomingException = i0.asValue(target.getLIRKind(Kind.Object));
061        RegisterValue incomingExceptionPc = i1.asValue(LIRKind.value(word));
062        CallingConvention outgoingExceptionCc = new CallingConvention(0, ILLEGAL, outgoingException, outgoingExceptionPc);
063        CallingConvention incomingExceptionCc = new CallingConvention(0, ILLEGAL, incomingException, incomingExceptionPc);
064        register(new HotSpotForeignCallLinkageImpl(EXCEPTION_HANDLER, 0L, PRESERVES_REGISTERS, LEAF_NOFP, outgoingExceptionCc, incomingExceptionCc, NOT_REEXECUTABLE, any()));
065        register(new HotSpotForeignCallLinkageImpl(EXCEPTION_HANDLER_IN_CALLER, JUMP_ADDRESS, PRESERVES_REGISTERS, LEAF_NOFP, outgoingExceptionCc, incomingExceptionCc, NOT_REEXECUTABLE, any()));
066
067        if (PreferGraalStubs.getValue()) {
068            link(new SPARCDeoptimizationStub(providers, target, registerStubCall(DEOPTIMIZATION_HANDLER, REEXECUTABLE, LEAF, NO_LOCATIONS)));
069            link(new SPARCUncommonTrapStub(providers, target, registerStubCall(UNCOMMON_TRAP_HANDLER, REEXECUTABLE, LEAF, NO_LOCATIONS)));
070        }
071
072        super.initialize(providers, config);
073    }
074
075    @Override
076    public Value[] getNativeABICallerSaveRegisters() {
077        return nativeABICallerSaveRegisters;
078    }
079}