1/* 2 * Copyright (c) 2016, 2017, 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 24package jdk.tools.jaotc.amd64; 25 26import static jdk.vm.ci.amd64.AMD64.rax; 27import static jdk.vm.ci.amd64.AMD64.rbx; 28import static jdk.vm.ci.amd64.AMD64.rip; 29 30import jdk.tools.jaotc.StubInformation; 31import jdk.tools.jaotc.ELFMacroAssembler; 32import org.graalvm.compiler.asm.amd64.AMD64Address; 33import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler; 34 35import jdk.vm.ci.code.TargetDescription; 36 37public final class AMD64ELFMacroAssembler extends AMD64MacroAssembler implements ELFMacroAssembler { 38 39 private int currentEndOfInstruction; 40 41 public AMD64ELFMacroAssembler(TargetDescription target) { 42 super(target); 43 } 44 45 @Override 46 public int currentEndOfInstruction() { 47 return currentEndOfInstruction; 48 } 49 50 @Override 51 public byte[] getPLTJumpCode() { 52 // The main dispatch instruction 53 // jmpq *0x00000000(%rip) 54 jmp(new AMD64Address(rip, 0)); 55 currentEndOfInstruction = position(); 56 57 // Align to 8 bytes 58 align(8); 59 60 return close(true); 61 } 62 63 @Override 64 public byte[] getPLTStaticEntryCode(StubInformation stub) { 65 // The main dispatch instruction 66 // jmpq *0x00000000(%rip) 67 jmp(new AMD64Address(rip, 0)); 68 stub.setDispatchJumpOffset(position()); 69 70 // C2I stub used to call interpreter. 71 // mov 0x00000000(%rip),%rbx Loading Method* 72 movq(rbx, new AMD64Address(rip, 0)); 73 stub.setMovOffset(position()); 74 75 // jmpq *0x00000000(%rip) [c2i addr] 76 jmp(new AMD64Address(rip, 0)); 77 stub.setC2IJumpOffset(position()); 78 79 // Call to VM runtime to resolve the call. 80 // jmpq *0x00000000(%rip) 81 stub.setResolveJumpStart(position()); 82 jmp(new AMD64Address(rip, 0)); 83 stub.setResolveJumpOffset(position()); 84 currentEndOfInstruction = position(); 85 86 // Align to 8 bytes 87 align(8); 88 stub.setSize(position()); 89 90 return close(true); 91 } 92 93 @Override 94 public byte[] getPLTVirtualEntryCode(StubInformation stub) { 95 // Klass loading instruction 96 // mov 0x00000000(%rip),%rax 97 movq(rax, new AMD64Address(rip, 0)); 98 stub.setMovOffset(position()); 99 100 // The main dispatch instruction 101 // jmpq *0x00000000(%rip) 102 jmp(new AMD64Address(rip, 0)); 103 stub.setDispatchJumpOffset(position()); 104 105 // Call to VM runtime to resolve the call. 106 // jmpq *0x00000000(%rip) 107 stub.setResolveJumpStart(position()); 108 jmp(new AMD64Address(rip, 0)); 109 stub.setResolveJumpOffset(position()); 110 currentEndOfInstruction = position(); 111 112 // Align to 8 bytes 113 align(8); 114 stub.setSize(position()); 115 116 return close(true); 117 } 118 119} 120