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_MEMBER(_type, _field) != _offset) { \ 15 LOGE("Bad asm offset %s (%d), should be %d", \ 16 #_name, _offset, OFFSETOF_MEMBER(_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", \ 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", \ 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 /* DvmDex fields */ 85 MTERP_OFFSET(offDvmDex_pResStrings, DvmDex, pResStrings, 8) 86 MTERP_OFFSET(offDvmDex_pResClasses, DvmDex, pResClasses, 12) 87 MTERP_OFFSET(offDvmDex_pResMethods, DvmDex, pResMethods, 16) 88 MTERP_OFFSET(offDvmDex_pResFields, DvmDex, pResFields, 20) 89 MTERP_OFFSET(offDvmDex_pInterfaceCache, DvmDex, pInterfaceCache, 24) 90 91 /* StackSaveArea fields */ 92 #ifdef EASY_GDB 93 MTERP_OFFSET(offStackSaveArea_prevSave, StackSaveArea, prevSave, 0) 94 MTERP_OFFSET(offStackSaveArea_prevFrame, StackSaveArea, prevFrame, 4) 95 MTERP_OFFSET(offStackSaveArea_savedPc, StackSaveArea, savedPc, 8) 96 MTERP_OFFSET(offStackSaveArea_method, StackSaveArea, method, 12) 97 MTERP_OFFSET(offStackSaveArea_currentPc, StackSaveArea, xtra.currentPc, 16) 98 MTERP_OFFSET(offStackSaveArea_localRefCookie, \ 99 StackSaveArea, xtra.localRefCookie, 16) 100 MTERP_OFFSET(offStackSaveArea_returnAddr, StackSaveArea, returnAddr, 20) 101 MTERP_SIZEOF(sizeofStackSaveArea, StackSaveArea, 24) 102 #else 103 MTERP_OFFSET(offStackSaveArea_prevFrame, StackSaveArea, prevFrame, 0) 104 MTERP_OFFSET(offStackSaveArea_savedPc, StackSaveArea, savedPc, 4) 105 MTERP_OFFSET(offStackSaveArea_method, StackSaveArea, method, 8) 106 MTERP_OFFSET(offStackSaveArea_currentPc, StackSaveArea, xtra.currentPc, 12) 107 MTERP_OFFSET(offStackSaveArea_localRefCookie, \ 108 StackSaveArea, xtra.localRefCookie, 12) 109 MTERP_OFFSET(offStackSaveArea_returnAddr, StackSaveArea, returnAddr, 16) 110 MTERP_SIZEOF(sizeofStackSaveArea, StackSaveArea, 20) 111 #endif 112 113 /* ShadowSpace fields */ 114 #if defined(WITH_JIT) && defined(WITH_SELF_VERIFICATION) 115 MTERP_OFFSET(offShadowSpace_startPC, ShadowSpace, startPC, 0) 116 MTERP_OFFSET(offShadowSpace_fp, ShadowSpace, fp, 4) 117 MTERP_OFFSET(offShadowSpace_method, ShadowSpace, method, 8) 118 MTERP_OFFSET(offShadowSpace_methodClassDex, ShadowSpace, methodClassDex, 12) 119 MTERP_OFFSET(offShadowSpace_retval, ShadowSpace, retval, 16) 120 MTERP_OFFSET(offShadowSpace_interpStackEnd, ShadowSpace, interpStackEnd, 24) 121 MTERP_OFFSET(offShadowSpace_jitExitState,ShadowSpace, jitExitState, 28) 122 MTERP_OFFSET(offShadowSpace_svState, ShadowSpace, selfVerificationState, 32) 123 MTERP_OFFSET(offShadowSpace_shadowFP, ShadowSpace, shadowFP, 40) 124 #endif 125 126 /* InstField fields */ 127 MTERP_OFFSET(offInstField_byteOffset, InstField, byteOffset, 16) 128 129 /* Field fields */ 130 MTERP_OFFSET(offField_clazz, Field, clazz, 0) 131 132 /* StaticField fields */ 133 MTERP_OFFSET(offStaticField_value, StaticField, value, 16) 134 135 /* Method fields */ 136 MTERP_OFFSET(offMethod_clazz, Method, clazz, 0) 137 MTERP_OFFSET(offMethod_accessFlags, Method, accessFlags, 4) 138 MTERP_OFFSET(offMethod_methodIndex, Method, methodIndex, 8) 139 MTERP_OFFSET(offMethod_registersSize, Method, registersSize, 10) 140 MTERP_OFFSET(offMethod_outsSize, Method, outsSize, 12) 141 MTERP_OFFSET(offMethod_name, Method, name, 16) 142 MTERP_OFFSET(offMethod_insns, Method, insns, 32) 143 MTERP_OFFSET(offMethod_nativeFunc, Method, nativeFunc, 40) 144 145 /* InlineOperation fields -- code assumes "func" offset is zero, do not alter */ 146 MTERP_OFFSET(offInlineOperation_func, InlineOperation, func, 0) 147 148 /* Thread fields */ 149 MTERP_OFFSET(offThread_pc, Thread, interpSave.pc, 0) 150 MTERP_OFFSET(offThread_curFrame, Thread, interpSave.curFrame, 4) 151 MTERP_OFFSET(offThread_method, Thread, interpSave.method, 8) 152 MTERP_OFFSET(offThread_methodClassDex, Thread, interpSave.methodClassDex, 12) 153 /* make sure all JValue union members are stored at the same offset */ 154 MTERP_OFFSET(offThread_retval, Thread, interpSave.retval, 16) 155 MTERP_OFFSET(offThread_retval_z, Thread, interpSave.retval.z, 16) 156 MTERP_OFFSET(offThread_retval_i, Thread, interpSave.retval.i, 16) 157 MTERP_OFFSET(offThread_retval_j, Thread, interpSave.retval.j, 16) 158 MTERP_OFFSET(offThread_retval_l, Thread, interpSave.retval.l, 16) 159 MTERP_OFFSET(offThread_bailPtr, Thread, interpSave.bailPtr, 24) 160 MTERP_OFFSET(offThread_threadId, Thread, threadId, 36) 161 162 //40 163 MTERP_OFFSET(offThread_subMode, \ 164 Thread, interpBreak.ctl.subMode, 40) 165 MTERP_OFFSET(offThread_breakFlags, \ 166 Thread, interpBreak.ctl.breakFlags, 42) 167 MTERP_OFFSET(offThread_curHandlerTable, \ 168 Thread, interpBreak.ctl.curHandlerTable, 44) 169 MTERP_OFFSET(offThread_suspendCount, Thread, suspendCount, 48); 170 MTERP_OFFSET(offThread_dbgSuspendCount, Thread, dbgSuspendCount, 52); 171 MTERP_OFFSET(offThread_cardTable, Thread, cardTable, 56) 172 MTERP_OFFSET(offThread_interpStackEnd, Thread, interpStackEnd, 60) 173 MTERP_OFFSET(offThread_exception, Thread, exception, 68) 174 MTERP_OFFSET(offThread_debugIsMethodEntry, Thread, debugIsMethodEntry, 72) 175 MTERP_OFFSET(offThread_interpStackSize, Thread, interpStackSize, 76) 176 MTERP_OFFSET(offThread_stackOverflowed, Thread, stackOverflowed, 80) 177 MTERP_OFFSET(offThread_mainHandlerTable, Thread, mainHandlerTable, 88) 178 MTERP_OFFSET(offThread_singleStepCount, Thread, singleStepCount, 96) 179 180 #ifdef WITH_JIT 181 MTERP_OFFSET(offThread_jitToInterpEntries,Thread, jitToInterpEntries, 100) 182 MTERP_OFFSET(offThread_inJitCodeCache, Thread, inJitCodeCache, 124) 183 MTERP_OFFSET(offThread_pJitProfTable, Thread, pJitProfTable, 128) 184 MTERP_OFFSET(offThread_jitThreshold, Thread, jitThreshold, 132) 185 MTERP_OFFSET(offThread_jitResumeNPC, Thread, jitResumeNPC, 136) 186 MTERP_OFFSET(offThread_jitResumeNSP, Thread, jitResumeNSP, 140) 187 MTERP_OFFSET(offThread_jitResumeDPC, Thread, jitResumeDPC, 144) 188 MTERP_OFFSET(offThread_jitState, Thread, jitState, 148) 189 MTERP_OFFSET(offThread_icRechainCount, Thread, icRechainCount, 152) 190 MTERP_OFFSET(offThread_pProfileCountdown, Thread, pProfileCountdown, 156) 191 MTERP_OFFSET(offThread_callsiteClass, Thread, callsiteClass, 160) 192 MTERP_OFFSET(offThread_methodToCall, Thread, methodToCall, 164) 193 MTERP_OFFSET(offThread_jniLocal_topCookie, \ 194 Thread, jniLocalRefTable.segmentState.all, 168) 195 #if defined(WITH_SELF_VERIFICATION) 196 MTERP_OFFSET(offThread_shadowSpace, Thread, shadowSpace, 192) 197 #endif 198 #else 199 MTERP_OFFSET(offThread_jniLocal_topCookie, \ 200 Thread, jniLocalRefTable.segmentState.all, 100) 201 #endif 202 203 /* Object fields */ 204 MTERP_OFFSET(offObject_clazz, Object, clazz, 0) 205 MTERP_OFFSET(offObject_lock, Object, lock, 4) 206 207 /* Lock shape */ 208 MTERP_CONSTANT(LW_LOCK_OWNER_SHIFT, 3) 209 MTERP_CONSTANT(LW_HASH_STATE_SHIFT, 1) 210 211 /* ArrayObject fields */ 212 MTERP_OFFSET(offArrayObject_length, ArrayObject, length, 8) 213 #ifdef MTERP_NO_UNALIGN_64 214 MTERP_OFFSET(offArrayObject_contents, ArrayObject, contents, 16) 215 #else 216 MTERP_OFFSET(offArrayObject_contents, ArrayObject, contents, 12) 217 #endif 218 219 /* String fields */ 220 MTERP_CONSTANT(STRING_FIELDOFF_VALUE, 8) 221 MTERP_CONSTANT(STRING_FIELDOFF_HASHCODE, 12) 222 MTERP_CONSTANT(STRING_FIELDOFF_OFFSET, 16) 223 MTERP_CONSTANT(STRING_FIELDOFF_COUNT, 20) 224 225 #if defined(WITH_JIT) 226 /* 227 * Reasons for the non-chaining interpreter entry points 228 * Enums defined in vm/Globals.h 229 */ 230 MTERP_CONSTANT(kInlineCacheMiss, 0) 231 MTERP_CONSTANT(kCallsiteInterpreted, 1) 232 MTERP_CONSTANT(kSwitchOverflow, 2) 233 MTERP_CONSTANT(kHeavyweightMonitor, 3) 234 235 /* Size of callee save area */ 236 MTERP_CONSTANT(JIT_CALLEE_SAVE_DOUBLE_COUNT, 8) 237 #endif 238 239 /* ClassObject fields */ 240 MTERP_OFFSET(offClassObject_descriptor, ClassObject, descriptor, 24) 241 MTERP_OFFSET(offClassObject_accessFlags, ClassObject, accessFlags, 32) 242 MTERP_OFFSET(offClassObject_pDvmDex, ClassObject, pDvmDex, 40) 243 MTERP_OFFSET(offClassObject_status, ClassObject, status, 44) 244 MTERP_OFFSET(offClassObject_super, ClassObject, super, 72) 245 MTERP_OFFSET(offClassObject_vtableCount, ClassObject, vtableCount, 112) 246 MTERP_OFFSET(offClassObject_vtable, ClassObject, vtable, 116) 247 248 #if defined(WITH_JIT) 249 MTERP_CONSTANT(kJitNot, 0) 250 MTERP_CONSTANT(kJitTSelectRequest, 1) 251 MTERP_CONSTANT(kJitTSelectRequestHot, 2) 252 MTERP_CONSTANT(kJitSelfVerification, 3) 253 MTERP_CONSTANT(kJitTSelect, 4) 254 MTERP_CONSTANT(kJitTSelectEnd, 5) 255 MTERP_CONSTANT(kJitDone, 6) 256 257 #if defined(WITH_SELF_VERIFICATION) 258 MTERP_CONSTANT(kSVSIdle, 0) 259 MTERP_CONSTANT(kSVSStart, 1) 260 MTERP_CONSTANT(kSVSPunt, 2) 261 MTERP_CONSTANT(kSVSSingleStep, 3) 262 MTERP_CONSTANT(kSVSNoProfile, 4) 263 MTERP_CONSTANT(kSVSTraceSelect, 5) 264 MTERP_CONSTANT(kSVSNormal, 6) 265 MTERP_CONSTANT(kSVSNoChain, 7) 266 MTERP_CONSTANT(kSVSBackwardBranch, 8) 267 MTERP_CONSTANT(kSVSDebugInterp, 9) 268 #endif 269 #endif 270 271 /* ClassStatus enumeration */ 272 MTERP_SIZEOF(sizeofClassStatus, ClassStatus, MTERP_SMALL_ENUM) 273 MTERP_CONSTANT(CLASS_INITIALIZED, 7) 274 275 /* MethodType enumeration */ 276 MTERP_SIZEOF(sizeofMethodType, MethodType, MTERP_SMALL_ENUM) 277 MTERP_CONSTANT(METHOD_DIRECT, 1) 278 MTERP_CONSTANT(METHOD_STATIC, 2) 279 MTERP_CONSTANT(METHOD_VIRTUAL, 3) 280 MTERP_CONSTANT(METHOD_INTERFACE, 4) 281 282 /* ClassObject constants */ 283 MTERP_CONSTANT(ACC_PRIVATE, 0x0002) 284 MTERP_CONSTANT(ACC_STATIC, 0x0008) 285 MTERP_CONSTANT(ACC_NATIVE, 0x0100) 286 MTERP_CONSTANT(ACC_INTERFACE, 0x0200) 287 MTERP_CONSTANT(ACC_ABSTRACT, 0x0400) 288 MTERP_CONSTANT(CLASS_ISFINALIZABLE, 1<<31) 289 290 /* flags for dvmMalloc */ 291 MTERP_CONSTANT(ALLOC_DONT_TRACK, 0x01) 292 293 /* for GC */ 294 MTERP_CONSTANT(GC_CARD_SHIFT, 7) 295 296 /* opcode number */ 297 MTERP_CONSTANT(OP_MOVE_EXCEPTION, 0x0d) 298 MTERP_CONSTANT(OP_INVOKE_DIRECT_RANGE, 0x76) 299 MTERP_CONSTANT(OP_INVOKE_DIRECT_JUMBO, 0x124) 300 301 /* flags for interpBreak */ 302 MTERP_CONSTANT(kSubModeNormal, 0x0000) 303 MTERP_CONSTANT(kSubModeMethodTrace, 0x0001) 304 MTERP_CONSTANT(kSubModeEmulatorTrace, 0x0002) 305 MTERP_CONSTANT(kSubModeInstCounting, 0x0004) 306 MTERP_CONSTANT(kSubModeDebuggerActive, 0x0008) 307 MTERP_CONSTANT(kSubModeSuspendPending, 0x0010) 308 MTERP_CONSTANT(kSubModeCallbackPending, 0x0020) 309 MTERP_CONSTANT(kSubModeCountedStep, 0x0040) 310 MTERP_CONSTANT(kSubModeJitTraceBuild, 0x4000) 311 MTERP_CONSTANT(kSubModeJitSV, 0x8000) 312 MTERP_CONSTANT(kSubModeDebugProfile, 0x000f) 313 314 MTERP_CONSTANT(kInterpNoBreak, 0x00) 315 MTERP_CONSTANT(kInterpSingleStep, 0x01) 316 MTERP_CONSTANT(kInterpSafePoint, 0x02) 317 318 MTERP_CONSTANT(DBG_METHOD_ENTRY, 0x04) 319 MTERP_CONSTANT(DBG_METHOD_EXIT, 0x08) 320