1 /*
   2  * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2018, Red Hat Inc. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  */
  24 
  25 
  26 package org.graalvm.compiler.hotspot.aarch64;
  27 
  28 import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
  29 import static jdk.vm.ci.code.ValueUtil.asRegister;
  30 
  31 import jdk.vm.ci.aarch64.AArch64Kind;
  32 import jdk.vm.ci.code.Register;
  33 import jdk.vm.ci.meta.AllocatableValue;
  34 
  35 import org.graalvm.compiler.asm.aarch64.AArch64Address;
  36 import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
  37 import org.graalvm.compiler.debug.GraalError;
  38 import org.graalvm.compiler.lir.LIRInstructionClass;
  39 import org.graalvm.compiler.lir.aarch64.AArch64LIRInstruction;
  40 import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
  41 
  42 public final class AArch64HotSpotLoadConfigValueOp extends AArch64LIRInstruction {
  43 
  44     public static final LIRInstructionClass<AArch64HotSpotLoadConfigValueOp> TYPE = LIRInstructionClass.create(AArch64HotSpotLoadConfigValueOp.class);
  45 
  46     @Def({OperandFlag.REG}) protected AllocatableValue result;
  47     private final int markId;
  48 
  49     public AArch64HotSpotLoadConfigValueOp(int markId, AllocatableValue result) {
  50         super(TYPE);
  51         this.result = result;
  52         this.markId = markId;
  53     }
  54 
  55     @Override
  56     public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
  57         if (GeneratePIC.getValue(crb.getOptions())) {
  58             AArch64Kind kind = (AArch64Kind) result.getPlatformKind();
  59             Register reg = asRegister(result);
  60             masm.adrp(reg);
  61             masm.add(64, reg, reg, 1);
  62             switch (kind) {
  63                 case BYTE:
  64                     masm.ldrs(8, 32, reg, AArch64Address.createBaseRegisterOnlyAddress(reg));
  65                     break;
  66                 case WORD:
  67                     masm.ldrs(16, 32, reg, AArch64Address.createBaseRegisterOnlyAddress(reg));
  68                     break;
  69                 case DWORD:
  70                     masm.ldr(32, reg, AArch64Address.createBaseRegisterOnlyAddress(reg));
  71                     break;
  72                 case QWORD:
  73                     masm.ldr(64, reg, AArch64Address.createBaseRegisterOnlyAddress(reg));
  74                     break;
  75                 default:
  76                     throw GraalError.unimplemented();
  77             }
  78             masm.nop();
  79         } else {
  80             throw GraalError.unimplemented();
  81         }
  82         crb.recordMark(markId);
  83     }
  84 
  85 }