1 /* 2 * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2019, Arm Limited. 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. Oracle designates this 9 * particular file as subject to the "Classpath" exception as provided 10 * by Oracle in the LICENSE file that accompanied this code. 11 * 12 * This code is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 * version 2 for more details (a copy is included in the LICENSE file that 16 * accompanied this code). 17 * 18 * You should have received a copy of the GNU General Public License version 19 * 2 along with this work; if not, write to the Free Software Foundation, 20 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 * 22 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23 * or visit www.oracle.com if you need additional information or have any 24 * questions. 25 */ 26 package jdk.internal.foreign.abi.aarch64; 27 28 import jdk.internal.foreign.abi.ABIDescriptor; 29 import jdk.internal.foreign.abi.Architecture; 30 import jdk.internal.foreign.abi.VMStorage; 31 32 public class AArch64Architecture implements Architecture { 33 public static final Architecture INSTANCE = new AArch64Architecture(); 34 35 private static final int INTEGER_REG_SIZE = 8; 36 private static final int VECTOR_REG_SIZE = 16; 37 private static final int STACK_SLOT_SIZE = 8; 38 39 @Override 40 public boolean isStackType(int cls) { 41 return cls == StorageClasses.STACK; 42 } 43 44 @Override 45 public int typeSize(int cls) { 46 switch (cls) { 47 case StorageClasses.INTEGER: return INTEGER_REG_SIZE; 48 case StorageClasses.VECTOR: return VECTOR_REG_SIZE; 49 case StorageClasses.STACK: return STACK_SLOT_SIZE; 50 } 51 52 throw new IllegalArgumentException("Invalid Storage Class: " + cls); 53 } 54 55 @Override 56 public int stackType() { 57 return StorageClasses.STACK; 58 } 59 60 public interface StorageClasses { 61 int INTEGER = 0; 62 int VECTOR = 1; 63 int STACK = 3; 64 } 65 66 public static final VMStorage r0 = integerRegister(0); 67 public static final VMStorage r1 = integerRegister(1); 68 public static final VMStorage r2 = integerRegister(2); 69 public static final VMStorage r3 = integerRegister(3); 70 public static final VMStorage r4 = integerRegister(4); 71 public static final VMStorage r5 = integerRegister(5); 72 public static final VMStorage r6 = integerRegister(6); 73 public static final VMStorage r7 = integerRegister(7); 74 public static final VMStorage r8 = integerRegister(8); 75 public static final VMStorage r9 = integerRegister(9); 76 public static final VMStorage r10 = integerRegister(10); 77 public static final VMStorage r11 = integerRegister(11); 78 public static final VMStorage r12 = integerRegister(12); 79 public static final VMStorage r13 = integerRegister(13); 80 public static final VMStorage r14 = integerRegister(14); 81 public static final VMStorage r15 = integerRegister(15); 82 public static final VMStorage r16 = integerRegister(16); 83 public static final VMStorage r17 = integerRegister(17); 84 public static final VMStorage r18 = integerRegister(18); 85 public static final VMStorage r19 = integerRegister(19); 86 public static final VMStorage r20 = integerRegister(20); 87 public static final VMStorage r21 = integerRegister(21); 88 public static final VMStorage r22 = integerRegister(22); 89 public static final VMStorage r23 = integerRegister(23); 90 public static final VMStorage r24 = integerRegister(24); 91 public static final VMStorage r25 = integerRegister(25); 92 public static final VMStorage r26 = integerRegister(26); 93 public static final VMStorage r27 = integerRegister(27); 94 public static final VMStorage r28 = integerRegister(28); 95 public static final VMStorage r29 = integerRegister(29); 96 public static final VMStorage r30 = integerRegister(30); 97 public static final VMStorage r31 = integerRegister(31); 98 99 public static final VMStorage v0 = vectorRegister(0); 100 public static final VMStorage v1 = vectorRegister(1); 101 public static final VMStorage v2 = vectorRegister(2); 102 public static final VMStorage v3 = vectorRegister(3); 103 public static final VMStorage v4 = vectorRegister(4); 104 public static final VMStorage v5 = vectorRegister(5); 105 public static final VMStorage v6 = vectorRegister(6); 106 public static final VMStorage v7 = vectorRegister(7); 107 public static final VMStorage v8 = vectorRegister(8); 108 public static final VMStorage v9 = vectorRegister(9); 109 public static final VMStorage v10 = vectorRegister(10); 110 public static final VMStorage v11 = vectorRegister(11); 111 public static final VMStorage v12 = vectorRegister(12); 112 public static final VMStorage v13 = vectorRegister(13); 113 public static final VMStorage v14 = vectorRegister(14); 114 public static final VMStorage v15 = vectorRegister(15); 115 public static final VMStorage v16 = vectorRegister(16); 116 public static final VMStorage v17 = vectorRegister(17); 117 public static final VMStorage v18 = vectorRegister(18); 118 public static final VMStorage v19 = vectorRegister(19); 119 public static final VMStorage v20 = vectorRegister(20); 120 public static final VMStorage v21 = vectorRegister(21); 121 public static final VMStorage v22 = vectorRegister(22); 122 public static final VMStorage v23 = vectorRegister(23); 123 public static final VMStorage v24 = vectorRegister(24); 124 public static final VMStorage v25 = vectorRegister(25); 125 public static final VMStorage v26 = vectorRegister(26); 126 public static final VMStorage v27 = vectorRegister(27); 127 public static final VMStorage v28 = vectorRegister(28); 128 public static final VMStorage v29 = vectorRegister(29); 129 public static final VMStorage v30 = vectorRegister(30); 130 public static final VMStorage v31 = vectorRegister(31); 131 132 private static VMStorage integerRegister(int index) { 133 return new VMStorage(StorageClasses.INTEGER, index, "r" + index); 134 } 135 136 private static VMStorage vectorRegister(int index) { 137 return new VMStorage(StorageClasses.VECTOR, index, "v" + index); 138 } 139 140 public static VMStorage stackStorage(int index) { 141 return new VMStorage(StorageClasses.STACK, index, "Stack@" + index); 142 } 143 144 public static ABIDescriptor abiFor(VMStorage[] inputIntRegs, 145 VMStorage[] inputVectorRegs, 146 VMStorage[] outputIntRegs, 147 VMStorage[] outputVectorRegs, 148 VMStorage[] volatileIntRegs, 149 VMStorage[] volatileVectorRegs, 150 int stackAlignment, 151 int shadowSpace) { 152 return new ABIDescriptor( 153 INSTANCE, 154 new VMStorage[][] { 155 inputIntRegs, 156 inputVectorRegs, 157 }, 158 new VMStorage[][] { 159 outputIntRegs, 160 outputVectorRegs, 161 }, 162 new VMStorage[][] { 163 volatileIntRegs, 164 volatileVectorRegs, 165 }, 166 stackAlignment, 167 shadowSpace 168 ); 169 } 170 171 }