github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/jit-rules-arm.h (about) 1 /* 2 * jit-rules-arm.h - Rules that define the characteristics of the ARM. 3 * 4 * Copyright (C) 2004 Southern Storm Software, Pty Ltd. 5 * Copyright (C) 2008 Michele Tartara <mikyt@users.sourceforge.net> 6 * 7 * This file is part of the libjit library. 8 * 9 * The libjit library is free software: you can redistribute it and/or 10 * modify it under the terms of the GNU Lesser General Public License 11 * as published by the Free Software Foundation, either version 2.1 of 12 * the License, or (at your option) any later version. 13 * 14 * The libjit library is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 * Lesser General Public License for more details. 18 * 19 * You should have received a copy of the GNU Lesser General Public 20 * License along with the libjit library. If not, see 21 * <http://www.gnu.org/licenses/>. 22 */ 23 24 #ifndef _JIT_RULES_ARM_H 25 #define _JIT_RULES_ARM_H 26 27 #include "jit-apply-rules.h" 28 29 #ifdef __cplusplus 30 extern "C" { 31 #endif 32 33 /* 34 * Determine the kind of floating point unit that is being used (if any) 35 */ 36 #if defined(__VFP_FP__) 37 /* Vector floating point unit (used by EABI systems) */ 38 # define JIT_ARM_HAS_VFP 1 39 #elif defined(__FPA_FP__) 40 /* Old floating point unit (used by OABI systems) */ 41 # define JIT_ARM_HAS_FPA 1 42 #endif 43 44 /* 45 * Determine if this ARM core uses floating point registers available 46 */ 47 #if defined(JIT_ARM_HAS_FPA) || defined(JIT_ARM_HAS_VFP) 48 # define JIT_ARM_HAS_FLOAT_REGS 1 49 #endif 50 51 /* 52 * Information about all of the registers, in allocation order. 53 * We use r0-r5 for general-purpose values and r6-r8 for globals. 54 * 55 * The floating-point registers are only present on some ARM cores. 56 * 57 * The definitions of the used flags are in jit-rules.h 58 */ 59 #define JIT_REG_INFO \ 60 {"r0", 0, 1, JIT_REG_WORD | JIT_REG_LONG | JIT_REG_CALL_USED}, \ 61 {"r1", 1, -1, JIT_REG_WORD | JIT_REG_CALL_USED}, \ 62 {"r2", 2, 3, JIT_REG_WORD | JIT_REG_LONG | JIT_REG_CALL_USED}, \ 63 {"r3", 3, -1, JIT_REG_WORD | JIT_REG_CALL_USED}, \ 64 {"r4", 4, -1, JIT_REG_WORD}, \ 65 {"r5", 5, -1, JIT_REG_WORD}, \ 66 {"r6", 6, -1, JIT_REG_WORD | JIT_REG_GLOBAL}, \ 67 {"r7", 7, -1, JIT_REG_WORD | JIT_REG_GLOBAL}, \ 68 {"r8", 8, -1, JIT_REG_WORD | JIT_REG_GLOBAL}, \ 69 {"r9", 9, -1, JIT_REG_FIXED}, /* pic reg */ \ 70 {"r10", 10, -1, JIT_REG_FIXED}, /* stack limit */ \ 71 {"fp", 11, -1, JIT_REG_FIXED | JIT_REG_FRAME}, \ 72 {"r12", 12, -1, JIT_REG_FIXED | JIT_REG_CALL_USED}, /* work reg */ \ 73 {"sp", 13, -1, JIT_REG_FIXED | JIT_REG_STACK_PTR}, \ 74 {"lr", 14, -1, JIT_REG_FIXED}, \ 75 {"pc", 15, -1, JIT_REG_FIXED}, \ 76 JIT_REG_INFO_FLOAT_REGS 77 78 /* 79 * Definitions in case of no floating point registers 80 */ 81 #ifndef JIT_ARM_HAS_FLOAT_REGS 82 83 #define JIT_REG_INFO_FLOAT_REGS 84 85 /* JIT_NUM_REGS is the total number of registers (general purpose) */ 86 #define JIT_NUM_REGS 16 87 88 #endif /* JIT_ARM_HAS_FLOAT_REGS */ 89 90 /* 91 * Definitions in case of FPA 92 */ 93 #ifdef JIT_ARM_HAS_FPA 94 95 #define JIT_REG_ARM_FLOAT \ 96 (JIT_REG_FLOAT32 | JIT_REG_FLOAT64 | JIT_REG_NFLOAT | JIT_REG_CALL_USED) 97 98 #define JIT_REG_INFO_FLOAT_REGS \ 99 {"f0", 0, -1, JIT_REG_ARM_FLOAT}, \ 100 {"f1", 1, -1, JIT_REG_ARM_FLOAT}, \ 101 {"f2", 2, -1, JIT_REG_ARM_FLOAT}, \ 102 {"f3", 3, -1, JIT_REG_ARM_FLOAT}, 103 104 /* JIT_NUM_REGS is the total number of registers (general purpose+floating point) */ 105 #define JIT_NUM_REGS 20 106 107 #endif /* JIT_ARM_HAS_FPA */ 108 109 /* 110 * Definitions in case of VFP 111 */ 112 #ifdef JIT_ARM_HAS_VFP 113 114 #define JIT_REG_ARM_FLOAT32 (JIT_REG_FLOAT32) 115 #define JIT_REG_ARM_FLOAT64 (JIT_REG_FLOAT64 | JIT_REG_NFLOAT) 116 117 #define JIT_REG_INFO_FLOAT_REGS \ 118 {"s0", 0, -1, JIT_REG_ARM_FLOAT32}, \ 119 {"s1", 1, -1, JIT_REG_ARM_FLOAT32}, \ 120 {"s2", 2, -1, JIT_REG_ARM_FLOAT32}, \ 121 {"s3", 3, -1, JIT_REG_ARM_FLOAT32}, \ 122 {"s4", 4, -1, JIT_REG_ARM_FLOAT32}, \ 123 {"s5", 5, -1, JIT_REG_ARM_FLOAT32}, \ 124 {"s6", 6, -1, JIT_REG_ARM_FLOAT32}, \ 125 {"s7", 7, -1, JIT_REG_ARM_FLOAT32}, \ 126 {"s8", 8, -1, JIT_REG_ARM_FLOAT32}, \ 127 {"s9", 9, -1, JIT_REG_ARM_FLOAT32}, \ 128 {"s10", 10, -1, JIT_REG_ARM_FLOAT32}, \ 129 {"s11", 11, -1, JIT_REG_ARM_FLOAT32}, \ 130 {"s12", 12, -1, JIT_REG_ARM_FLOAT32}, \ 131 {"s13", 13, -1, JIT_REG_ARM_FLOAT32}, \ 132 {"s14", 14, -1, JIT_REG_ARM_FLOAT32}, \ 133 {"s15", 15, -1, JIT_REG_ARM_FLOAT32}, \ 134 {"d8", 8, -1, JIT_REG_ARM_FLOAT64}, \ 135 {"d9", 9, -1, JIT_REG_ARM_FLOAT64}, \ 136 {"d10", 10, -1, JIT_REG_ARM_FLOAT64}, \ 137 {"d11", 11, -1, JIT_REG_ARM_FLOAT64}, \ 138 {"d12", 12, -1, JIT_REG_ARM_FLOAT64}, \ 139 {"d13", 13, -1, JIT_REG_ARM_FLOAT64}, \ 140 {"d14", 14, -1, JIT_REG_ARM_FLOAT64}, \ 141 {"d15", 15, -1, JIT_REG_ARM_FLOAT64}, 142 143 /* JIT_NUM_REGS is the total number of registers (general purpose+floating point) */ 144 #define JIT_NUM_REGS 40 145 146 #endif 147 148 /* The number of global registers */ 149 #define JIT_NUM_GLOBAL_REGS 3 150 151 //Floating point registers are NOT handled like a stack 152 #undef JIT_REG_STACK 153 154 /* 155 * Define to 1 if we should always load values into registers 156 * before operating on them. i.e. the CPU does not have reg-mem 157 * and mem-reg addressing modes. 158 */ 159 #define JIT_ALWAYS_REG_REG 1 160 161 /* 162 * The maximum number of bytes to allocate for the prolog. 163 * This may be shortened once we know the true prolog size. 164 */ 165 #define JIT_PROLOG_SIZE 48 166 167 /* 168 * Preferred alignment for the start of functions. 169 */ 170 #define JIT_FUNCTION_ALIGNMENT 8 171 172 /* 173 * Define this to 1 if the platform allows reads and writes on 174 * any byte boundary. Define to 0 if only properly-aligned 175 * memory accesses are allowed. 176 */ 177 #define JIT_ALIGN_OVERRIDES 0 178 179 /* 180 * Extra state information that is added to the "jit_gencode" structure. 181 */ 182 #define JIT_ARM_MAX_CONSTANTS 32 183 184 #define jit_extra_gen_state \ 185 int constants[JIT_ARM_MAX_CONSTANTS]; \ 186 int *fixup_constants[JIT_ARM_MAX_CONSTANTS]; \ 187 int num_constants; \ 188 int align_constants; \ 189 unsigned int *first_constant_use 190 191 #define jit_extra_gen_init(gen) \ 192 do { \ 193 (gen)->num_constants = 0; \ 194 (gen)->align_constants = 0; \ 195 (gen)->first_constant_use = 0; \ 196 } while (0) 197 198 #define jit_extra_gen_cleanup(gen) do { ; } while (0) 199 200 /* 201 * Parameter passing rules. We start by assuming that lr, sp, fp, 202 * r8, r7, r6, r5, and r4 need to be saved in the local frame. 203 */ 204 #define JIT_CDECL_WORD_REG_PARAMS {0, 1, 2, 3, -1} 205 #define JIT_MAX_WORD_REG_PARAMS 4 206 #define JIT_INITIAL_STACK_OFFSET (sizeof(void *)) 207 #define JIT_INITIAL_FRAME_SIZE (8 * sizeof(void *)) 208 #define JIT_USE_PARAM_AREA 1 209 210 #ifdef __cplusplus 211 }; 212 #endif 213 214 #endif /* _JIT_RULES_ARM_H */