1 /* 2 * Copyright 2008 The Android Open Source Project 3 * 4 * Constants used by the assembler and verified by the C compiler. 5 */ 6 7 #if defined(ASM_DEF_VERIFY) 8 /* 9 * Generate C fragments that verify values; assumes "bool failed" exists. 10 * These are all constant expressions, so on success these will compile 11 * down to nothing. 12 */ 13 # define MTERP_OFFSET(_name, _type, _field, _offset) \ 14 if (offsetof(_type, _field) != _offset) { \ 15 LOGE("Bad asm offset %s (%d), should be %d\n", \ 16 #_name, _offset, offsetof(_type, _field)); \ 17 failed = true; \ 18 } 19 # define MTERP_SIZEOF(_name, _type, _size) \ 20 if (sizeof(_type) != (_size)) { \ 21 LOGE("Bad asm sizeof %s (%d), should be %d\n", \ 22 #_name, (_size), sizeof(_type)); \ 23 failed = true; \ 24 } 25 # define MTERP_CONSTANT(_name, _value) \ 26 if ((_name) != (_value)) { \ 27 LOGE("Bad asm constant %s (%d), should be %d\n", \ 28 #_name, (_value), (_name)); \ 29 failed = true; \ 30 } 31 #else 32 /* generate constant labels for the assembly output */ 33 # define MTERP_OFFSET(name, type, field, offset) name = offset 34 # define MTERP_SIZEOF(name, type, size) name = size 35 # define MTERP_CONSTANT(name, value) name = value 36 #endif 37 38 /* 39 * Platform dependencies. Some platforms require 64-bit alignment of 64-bit 40 * data structures. Some versions of gcc will hold small enumerated types 41 * in a char instead of an int. 42 */ 43 #if defined(__ARM_EABI__) 44 # define MTERP_NO_UNALIGN_64 45 #endif 46 #if defined(HAVE_SHORT_ENUMS) 47 # define MTERP_SMALL_ENUM 1 48 #else 49 # define MTERP_SMALL_ENUM 4 50 #endif 51 52 /* 53 * This file must only contain the following kinds of statements: 54 * 55 * MTERP_OFFSET(name, StructType, fieldname, offset) 56 * 57 * Declares that the expected offset of StructType.fieldname is "offset". 58 * This will break whenever the contents of StructType are rearranged. 59 * 60 * MTERP_SIZEOF(name, Type, size) 61 * 62 * Declares that the expected size of Type is "size". 63 * 64 * MTERP_CONSTANT(name, value) 65 * 66 * Declares that the expected value of "name" is "value". Useful for 67 * enumerations and defined constants that are inaccessible to the 68 * assembly source. (Note this assumes you will use the same name in 69 * both C and assembly, which is good practice.) 70 * 71 * In all cases the "name" field is the label you will use in the assembler. 72 * 73 * The "value" field must always be an actual number, not a symbol, unless 74 * you are sure that the symbol's value will be visible to both C and 75 * assembly sources. There may be restrictions on the possible range of 76 * values (which are usually provided as immediate operands), so it's best 77 * to restrict numbers assuming a signed 8-bit field. 78 * 79 * On the assembly side, these just become "name=value" constants. On the 80 * C side, these turn into assertions that cause the VM to abort if the 81 * values are incorrect. 82 */ 83 84 /* globals (sanity check for LDR vs LDRB) */ 85 MTERP_SIZEOF(sizeofGlobal_debuggerActive, gDvm.debuggerActive, 1) 86 #if defined(WITH_PROFILER) 87 MTERP_SIZEOF(sizeofGlobal_activeProfilers, gDvm.activeProfilers, 4) 88 #endif 89 90 /* MterpGlue fields */ 91 MTERP_OFFSET(offGlue_pc, MterpGlue, pc, 0) 92 MTERP_OFFSET(offGlue_fp, MterpGlue, fp, 4) 93 MTERP_OFFSET(offGlue_retval, MterpGlue, retval, 8) 94 MTERP_OFFSET(offGlue_method, MterpGlue, method, 16) 95 MTERP_OFFSET(offGlue_methodClassDex, MterpGlue, methodClassDex, 20) 96 MTERP_OFFSET(offGlue_self, MterpGlue, self, 24) 97 MTERP_OFFSET(offGlue_bailPtr, MterpGlue, bailPtr, 28) 98 MTERP_OFFSET(offGlue_interpStackEnd, MterpGlue, interpStackEnd, 32) 99 MTERP_OFFSET(offGlue_pSelfSuspendCount, MterpGlue, pSelfSuspendCount, 36) 100 #if defined(WITH_DEBUGGER) && defined(WITH_PROFILER) 101 MTERP_OFFSET(offGlue_pDebuggerActive, MterpGlue, pDebuggerActive, 40) 102 MTERP_OFFSET(offGlue_pActiveProfilers, MterpGlue, pActiveProfilers, 44) 103 MTERP_OFFSET(offGlue_entryPoint, MterpGlue, entryPoint, 48) 104 #if defined(WITH_JIT) 105 MTERP_OFFSET(offGlue_pJitProfTable, MterpGlue, pJitProfTable, 56) 106 MTERP_OFFSET(offGlue_jitState, MterpGlue, jitState, 60) 107 MTERP_OFFSET(offGlue_jitResume, MterpGlue, jitResume, 64) 108 MTERP_OFFSET(offGlue_jitResumePC, MterpGlue, jitResumePC, 68) 109 #endif 110 #elif defined(WITH_DEBUGGER) 111 MTERP_OFFSET(offGlue_pDebuggerActive, MterpGlue, pDebuggerActive, 40) 112 MTERP_OFFSET(offGlue_entryPoint, MterpGlue, entryPoint, 44) 113 #if defined(WITH_JIT) 114 MTERP_OFFSET(offGlue_pJitProfTable, MterpGlue, pJitProfTable, 52) 115 MTERP_OFFSET(offGlue_jitState, MterpGlue, jitState, 56) 116 MTERP_OFFSET(offGlue_jitResume, MterpGlue, jitResume, 60) 117 MTERP_OFFSET(offGlue_jitResumePC, MterpGlue, jitResumePC, 64) 118 #endif 119 #elif defined(WITH_PROFILER) 120 MTERP_OFFSET(offGlue_pActiveProfilers, MterpGlue, pActiveProfilers, 40) 121 MTERP_OFFSET(offGlue_entryPoint, MterpGlue, entryPoint, 44) 122 #if defined(WITH_JIT) 123 MTERP_OFFSET(offGlue_pJitProfTable, MterpGlue, pJitProfTable, 52) 124 MTERP_OFFSET(offGlue_jitState, MterpGlue, jitState, 56) 125 MTERP_OFFSET(offGlue_jitResume, MterpGlue, jitResume, 60) 126 MTERP_OFFSET(offGlue_jitResumePC, MterpGlue, jitResumePC, 64) 127 #endif 128 #else 129 MTERP_OFFSET(offGlue_entryPoint, MterpGlue, entryPoint, 40) 130 #if defined(WITH_JIT) 131 MTERP_OFFSET(offGlue_pJitProfTable, MterpGlue, pJitProfTable, 48) 132 MTERP_OFFSET(offGlue_jitState, MterpGlue, jitState, 52) 133 MTERP_OFFSET(offGlue_jitResume, MterpGlue, jitResume, 56) 134 MTERP_OFFSET(offGlue_jitResumePC, MterpGlue, jitResumePC, 60) 135 #endif 136 #endif 137 /* make sure all JValue union members are stored at the same offset */ 138 MTERP_OFFSET(offGlue_retval_z, MterpGlue, retval.z, 8) 139 MTERP_OFFSET(offGlue_retval_i, MterpGlue, retval.i, 8) 140 MTERP_OFFSET(offGlue_retval_j, MterpGlue, retval.j, 8) 141 MTERP_OFFSET(offGlue_retval_l, MterpGlue, retval.l, 8) 142 143 /* DvmDex fields */ 144 MTERP_OFFSET(offDvmDex_pResStrings, DvmDex, pResStrings, 8) 145 MTERP_OFFSET(offDvmDex_pResClasses, DvmDex, pResClasses, 12) 146 MTERP_OFFSET(offDvmDex_pResMethods, DvmDex, pResMethods, 16) 147 MTERP_OFFSET(offDvmDex_pResFields, DvmDex, pResFields, 20) 148 MTERP_OFFSET(offDvmDex_pInterfaceCache, DvmDex, pInterfaceCache, 24) 149 150 /* StackSaveArea fields */ 151 #ifdef EASY_GDB 152 MTERP_OFFSET(offStackSaveArea_prevSave, StackSaveArea, prevSave, 0) 153 MTERP_OFFSET(offStackSaveArea_prevFrame, StackSaveArea, prevFrame, 4) 154 MTERP_OFFSET(offStackSaveArea_savedPc, StackSaveArea, savedPc, 8) 155 MTERP_OFFSET(offStackSaveArea_method, StackSaveArea, method, 12) 156 MTERP_OFFSET(offStackSaveArea_currentPc, StackSaveArea, xtra.currentPc, 16) 157 MTERP_OFFSET(offStackSaveArea_localRefCookie, \ 158 StackSaveArea, xtra.localRefCookie, 16) 159 MTERP_OFFSET(offStackSaveArea_returnAddr, StackSaveArea, returnAddr, 20) 160 MTERP_SIZEOF(sizeofStackSaveArea, StackSaveArea, 24) 161 #else 162 MTERP_OFFSET(offStackSaveArea_prevFrame, StackSaveArea, prevFrame, 0) 163 MTERP_OFFSET(offStackSaveArea_savedPc, StackSaveArea, savedPc, 4) 164 MTERP_OFFSET(offStackSaveArea_method, StackSaveArea, method, 8) 165 MTERP_OFFSET(offStackSaveArea_currentPc, StackSaveArea, xtra.currentPc, 12) 166 MTERP_OFFSET(offStackSaveArea_localRefCookie, \ 167 StackSaveArea, xtra.localRefCookie, 12) 168 MTERP_OFFSET(offStackSaveArea_returnAddr, StackSaveArea, returnAddr, 16) 169 MTERP_SIZEOF(sizeofStackSaveArea, StackSaveArea, 20) 170 #endif 171 172 /* InstField fields */ 173 #ifdef PROFILE_FIELD_ACCESS 174 MTERP_OFFSET(offInstField_byteOffset, InstField, byteOffset, 24) 175 #else 176 MTERP_OFFSET(offInstField_byteOffset, InstField, byteOffset, 16) 177 #endif 178 179 /* StaticField fields */ 180 #ifdef PROFILE_FIELD_ACCESS 181 MTERP_OFFSET(offStaticField_value, StaticField, value, 24) 182 #else 183 MTERP_OFFSET(offStaticField_value, StaticField, value, 16) 184 #endif 185 186 /* Method fields */ 187 MTERP_OFFSET(offMethod_clazz, Method, clazz, 0) 188 MTERP_OFFSET(offMethod_accessFlags, Method, accessFlags, 4) 189 MTERP_OFFSET(offMethod_methodIndex, Method, methodIndex, 8) 190 MTERP_OFFSET(offMethod_registersSize, Method, registersSize, 10) 191 MTERP_OFFSET(offMethod_outsSize, Method, outsSize, 12) 192 MTERP_OFFSET(offMethod_name, Method, name, 16) 193 MTERP_OFFSET(offMethod_insns, Method, insns, 32) 194 MTERP_OFFSET(offMethod_nativeFunc, Method, nativeFunc, 40) 195 196 /* InlineOperation fields -- code assumes "func" offset is zero, do not alter */ 197 MTERP_OFFSET(offInlineOperation_func, InlineOperation, func, 0) 198 199 /* Thread fields */ 200 MTERP_OFFSET(offThread_stackOverflowed, Thread, stackOverflowed, 40) 201 MTERP_OFFSET(offThread_curFrame, Thread, curFrame, 44) 202 MTERP_OFFSET(offThread_exception, Thread, exception, 48) 203 #ifdef USE_INDIRECT_REF 204 MTERP_OFFSET(offThread_jniLocal_topCookie, \ 205 Thread, jniLocalRefTable.segmentState.all, 76) 206 #else 207 MTERP_OFFSET(offThread_jniLocal_topCookie, \ 208 Thread, jniLocalRefTable.nextEntry, 76) 209 #endif 210 211 /* Object fields */ 212 MTERP_OFFSET(offObject_clazz, Object, clazz, 0) 213 214 /* ArrayObject fields */ 215 MTERP_OFFSET(offArrayObject_length, ArrayObject, length, 8) 216 #ifdef MTERP_NO_UNALIGN_64 217 MTERP_OFFSET(offArrayObject_contents, ArrayObject, contents, 16) 218 #else 219 MTERP_OFFSET(offArrayObject_contents, ArrayObject, contents, 12) 220 #endif 221 222 /* ClassObject fields */ 223 MTERP_OFFSET(offClassObject_descriptor, ClassObject, descriptor, 24) 224 MTERP_OFFSET(offClassObject_accessFlags, ClassObject, accessFlags, 32) 225 MTERP_OFFSET(offClassObject_pDvmDex, ClassObject, pDvmDex, 40) 226 MTERP_OFFSET(offClassObject_status, ClassObject, status, 44) 227 MTERP_OFFSET(offClassObject_super, ClassObject, super, 76) 228 MTERP_OFFSET(offClassObject_vtableCount, ClassObject, vtableCount, 116) 229 MTERP_OFFSET(offClassObject_vtable, ClassObject, vtable, 120) 230 231 /* InterpEntry enumeration */ 232 MTERP_SIZEOF(sizeofClassStatus, InterpEntry, MTERP_SMALL_ENUM) 233 MTERP_CONSTANT(kInterpEntryInstr, 0) 234 MTERP_CONSTANT(kInterpEntryReturn, 1) 235 MTERP_CONSTANT(kInterpEntryThrow, 2) 236 #if defined(WITH_JIT) 237 MTERP_CONSTANT(kInterpEntryResume, 3) 238 #endif 239 240 #if defined(WITH_JIT) 241 MTERP_CONSTANT(kJitOff, 0) 242 MTERP_CONSTANT(kJitNormal, 1) 243 MTERP_CONSTANT(kJitTSelectRequest, 2) 244 MTERP_CONSTANT(kJitTSelect, 3) 245 MTERP_CONSTANT(kJitTSelectAbort, 4) 246 MTERP_CONSTANT(kJitTSelectEnd, 5) 247 MTERP_CONSTANT(kJitSingleStep, 6) 248 MTERP_CONSTANT(kJitSingleStepEnd, 7) 249 #endif 250 251 /* ClassStatus enumeration */ 252 MTERP_SIZEOF(sizeofClassStatus, ClassStatus, MTERP_SMALL_ENUM) 253 MTERP_CONSTANT(CLASS_INITIALIZED, 7) 254 255 /* MethodType enumeration */ 256 MTERP_SIZEOF(sizeofMethodType, MethodType, MTERP_SMALL_ENUM) 257 MTERP_CONSTANT(METHOD_DIRECT, 1) 258 MTERP_CONSTANT(METHOD_STATIC, 2) 259 MTERP_CONSTANT(METHOD_VIRTUAL, 3) 260 MTERP_CONSTANT(METHOD_INTERFACE, 4) 261 262 /* ClassObject constants */ 263 MTERP_CONSTANT(ACC_PRIVATE, 0x0002) 264 MTERP_CONSTANT(ACC_STATIC, 0x0008) 265 MTERP_CONSTANT(ACC_NATIVE, 0x0100) 266 MTERP_CONSTANT(ACC_INTERFACE, 0x0200) 267 MTERP_CONSTANT(ACC_ABSTRACT, 0x0400) 268 269 /* flags for dvmMalloc */ 270 MTERP_CONSTANT(ALLOC_DONT_TRACK, 0x02) 271 272 /* opcode number */ 273 MTERP_CONSTANT(OP_MOVE_EXCEPTION, 0x0d) 274