001/*
002 * Copyright (c) 2012, 2015, 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.meta.*;
027import static com.oracle.graal.lir.LIRInstruction.OperandFlag.*;
028import static jdk.internal.jvmci.sparc.SPARC.*;
029
030import com.oracle.graal.asm.sparc.*;
031import com.oracle.graal.lir.*;
032import com.oracle.graal.lir.asm.*;
033import com.oracle.graal.lir.sparc.*;
034
035@Opcode("CRUNTIME_CALL_EPILOGUE")
036final class SPARCHotSpotCRuntimeCallEpilogueOp extends SPARCLIRInstruction {
037    public static final LIRInstructionClass<SPARCHotSpotCRuntimeCallEpilogueOp> TYPE = LIRInstructionClass.create(SPARCHotSpotCRuntimeCallEpilogueOp.class);
038    public static final SizeEstimate SIZE = SizeEstimate.create(11);
039
040    private final int threadLastJavaSpOffset;
041    private final int threadLastJavaPcOffset;
042    private final int threadJavaFrameAnchorFlagsOffset;
043    private final Register thread;
044    @Use({REG, STACK}) protected Value threadTemp;
045
046    public SPARCHotSpotCRuntimeCallEpilogueOp(int threadLastJavaSpOffset, int threadLastJavaPcOffset, int threadJavaFrameAnchorFlagsOffset, Register thread, Value threadTemp) {
047        super(TYPE, SIZE);
048        this.threadLastJavaSpOffset = threadLastJavaSpOffset;
049        this.threadLastJavaPcOffset = threadLastJavaPcOffset;
050        this.threadJavaFrameAnchorFlagsOffset = threadJavaFrameAnchorFlagsOffset;
051        this.thread = thread;
052        this.threadTemp = threadTemp;
053    }
054
055    @Override
056    public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) {
057
058        // Restore the thread register when coming back from the runtime.
059        SPARCMove.move(crb, masm, thread.asValue(LIRKind.value(Kind.Long)), threadTemp, SPARCDelayedControlTransfer.DUMMY);
060
061        // Reset last Java frame, last Java PC and flags.
062        masm.stx(g0, new SPARCAddress(thread, threadLastJavaSpOffset));
063        masm.stx(g0, new SPARCAddress(thread, threadLastJavaPcOffset));
064        masm.stw(g0, new SPARCAddress(thread, threadJavaFrameAnchorFlagsOffset));
065    }
066}