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