1 /*
   2  * Copyright (c) 2013, 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 jdk.vm.ci.code.ValueUtil.asRegister;
  27 import static jdk.vm.ci.sparc.SPARC.i0;
  28 import static jdk.vm.ci.sparc.SPARC.i1;
  29 import static jdk.vm.ci.sparc.SPARC.i2;
  30 import static jdk.vm.ci.sparc.SPARC.i3;
  31 import static jdk.vm.ci.sparc.SPARC.i4;
  32 import static jdk.vm.ci.sparc.SPARC.i7;
  33 import static jdk.vm.ci.sparc.SPARC.o0;
  34 import static jdk.vm.ci.sparc.SPARC.o1;
  35 import static jdk.vm.ci.sparc.SPARC.o2;
  36 import static jdk.vm.ci.sparc.SPARC.o3;
  37 import static jdk.vm.ci.sparc.SPARC.o4;
  38 import static jdk.vm.ci.sparc.SPARC.o5;
  39 import static jdk.vm.ci.sparc.SPARC.sp;
  40 
  41 import org.graalvm.compiler.asm.sparc.SPARCMacroAssembler;
  42 import org.graalvm.compiler.lir.LIRInstructionClass;
  43 import org.graalvm.compiler.lir.Opcode;
  44 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
  45 import org.graalvm.compiler.lir.sparc.SPARCLIRInstruction;
  46 
  47 import jdk.vm.ci.code.Register;
  48 import jdk.vm.ci.meta.AllocatableValue;
  49 
  50 /**
  51  * Pushes an interpreter frame to the stack.
  52  */
  53 @Opcode("PUSH_INTERPRETER_FRAME")
  54 final class SPARCHotSpotPushInterpreterFrameOp extends SPARCLIRInstruction {
  55     public static final LIRInstructionClass<SPARCHotSpotPushInterpreterFrameOp> TYPE = LIRInstructionClass.create(SPARCHotSpotPushInterpreterFrameOp.class);
  56 
  57     @Alive(REG) AllocatableValue frameSize;
  58     @Alive(REG) AllocatableValue framePc;
  59     @Alive(REG) AllocatableValue senderSp;
  60     @Alive(REG) AllocatableValue initialInfo;
  61 
  62     SPARCHotSpotPushInterpreterFrameOp(AllocatableValue frameSize, AllocatableValue framePc, AllocatableValue senderSp, AllocatableValue initialInfo) {
  63         super(TYPE);
  64         this.frameSize = frameSize;
  65         this.framePc = framePc;
  66         this.senderSp = senderSp;
  67         this.initialInfo = initialInfo;
  68     }
  69 
  70     @Override
  71     public void emitCode(CompilationResultBuilder crb, SPARCMacroAssembler masm) {
  72         final Register frameSizeRegister = asRegister(frameSize);
  73         final Register framePcRegister = asRegister(framePc);
  74         final Register senderSpRegister = asRegister(senderSp);
  75 
  76         // Save sender SP to O5_savedSP.
  77         masm.mov(senderSpRegister, o5);
  78 
  79         masm.neg(frameSizeRegister);
  80         masm.save(sp, frameSizeRegister, sp);
  81 
  82         masm.mov(i0, o0);
  83         masm.mov(i1, o1);
  84         masm.mov(i2, o2);
  85         masm.mov(i3, o3);
  86         masm.mov(i4, o4);
  87 
  88         // NOTE: Don't touch I5 as it contains valuable saved SP!
  89 
  90         // Move frame's new PC into i7
  91         masm.mov(framePcRegister, i7);
  92     }
  93 
  94     @Override
  95     public boolean leavesRegisterWindow() {
  96         return true;
  97     }
  98 }