1 /*
   2  * Copyright (c) 2012, 2015, 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 package org.graalvm.compiler.hotspot.sparc;
  24 
  25 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
  26 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK;
  27 import static jdk.vm.ci.sparc.SPARC.g0;
  28 import static jdk.vm.ci.sparc.SPARCKind.XWORD;
  29 
  30 import org.graalvm.compiler.asm.sparc.SPARCAddress;
  31 import org.graalvm.compiler.asm.sparc.SPARCMacroAssembler;
  32 import org.graalvm.compiler.core.common.LIRKind;
  33 import org.graalvm.compiler.lir.LIRInstructionClass;
  34 import org.graalvm.compiler.lir.Opcode;
  35 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
  36 import org.graalvm.compiler.lir.sparc.SPARCDelayedControlTransfer;
  37 import org.graalvm.compiler.lir.sparc.SPARCLIRInstruction;
  38 import org.graalvm.compiler.lir.sparc.SPARCMove;
  39 
  40 import jdk.vm.ci.code.Register;
  41 import jdk.vm.ci.meta.Value;
  42 
  43 @Opcode("CRUNTIME_CALL_EPILOGUE")
  44 final class SPARCHotSpotCRuntimeCallEpilogueOp extends SPARCLIRInstruction {
  45     public static final LIRInstructionClass<SPARCHotSpotCRuntimeCallEpilogueOp> TYPE = LIRInstructionClass.create(SPARCHotSpotCRuntimeCallEpilogueOp.class);
  46     public static final SizeEstimate SIZE = SizeEstimate.create(11);
  47 
  48     private final int threadLastJavaSpOffset;
  49     private final int threadLastJavaPcOffset;
  50     private final int threadJavaFrameAnchorFlagsOffset;
  51     private final Register thread;
  52     @Use({REG, STACK}) protected Value threadTemp;
  53 
  54     SPARCHotSpotCRuntimeCallEpilogueOp(int threadLastJavaSpOffset, int threadLastJavaPcOffset, int threadJavaFrameAnchorFlagsOffset, Register thread, Value threadTemp) {
  55         super(TYPE, SIZE);
  56         this.threadLastJavaSpOffset = threadLastJavaSpOffset;
  57         this.threadLastJavaPcOffset = threadLastJavaPcOffset;
  58         this.threadJavaFrameAnchorFlagsOffset = threadJavaFrameAnchorFlagsOffset;
  59         this.thread = thread;
  60         this.threadTemp = threadTemp;
  61     }
  62 
  63     @Override
  64     public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) {
  65 
  66         // Restore the thread register when coming back from the runtime.
  67         SPARCMove.move(crb, masm, thread.asValue(LIRKind.value(XWORD)), threadTemp, SPARCDelayedControlTransfer.DUMMY);
  68 
  69         // Reset last Java frame, last Java PC and flags.
  70         masm.stx(g0, new SPARCAddress(thread, threadLastJavaSpOffset));
  71         masm.stx(g0, new SPARCAddress(thread, threadLastJavaPcOffset));
  72         masm.stw(g0, new SPARCAddress(thread, threadJavaFrameAnchorFlagsOffset));
  73     }
  74 }