asm-constants.h revision 6999d84e2c55dc4a46a6c311b55bd5811336d9c4
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) */ 85MTERP_SIZEOF(sizeofGlobal_debuggerActive, gDvm.debuggerActive, 1) 86#if defined(WITH_PROFILER) 87MTERP_SIZEOF(sizeofGlobal_activeProfilers, gDvm.activeProfilers, 4) 88#endif 89 90/* MterpGlue fields */ 91MTERP_OFFSET(offGlue_pc, MterpGlue, pc, 0) 92MTERP_OFFSET(offGlue_fp, MterpGlue, fp, 4) 93MTERP_OFFSET(offGlue_retval, MterpGlue, retval, 8) 94MTERP_OFFSET(offGlue_method, MterpGlue, method, 16) 95MTERP_OFFSET(offGlue_methodClassDex, MterpGlue, methodClassDex, 20) 96MTERP_OFFSET(offGlue_self, MterpGlue, self, 24) 97MTERP_OFFSET(offGlue_bailPtr, MterpGlue, bailPtr, 28) 98MTERP_OFFSET(offGlue_interpStackEnd, MterpGlue, interpStackEnd, 32) 99MTERP_OFFSET(offGlue_pSelfSuspendCount, MterpGlue, pSelfSuspendCount, 36) 100#if defined(WITH_DEBUGGER) && defined(WITH_PROFILER) 101MTERP_OFFSET(offGlue_pDebuggerActive, MterpGlue, pDebuggerActive, 40) 102MTERP_OFFSET(offGlue_pActiveProfilers, MterpGlue, pActiveProfilers, 44) 103MTERP_OFFSET(offGlue_entryPoint, MterpGlue, entryPoint, 48) 104#if defined(WITH_JIT) 105MTERP_OFFSET(offGlue_pJitProfTable, MterpGlue, pJitProfTable, 56) 106MTERP_OFFSET(offGlue_jitState, MterpGlue, jitState, 60) 107MTERP_OFFSET(offGlue_jitResume, MterpGlue, jitResume, 64) 108MTERP_OFFSET(offGlue_jitResumePC, MterpGlue, jitResumePC, 68) 109MTERP_OFFSET(offGlue_jitThreshold, MterpGlue, jitThreshold, 72) 110MTERP_OFFSET(offGlue_ppJitProfTable, MterpGlue, ppJitProfTable, 76) 111#endif 112#elif defined(WITH_DEBUGGER) 113MTERP_OFFSET(offGlue_pDebuggerActive, MterpGlue, pDebuggerActive, 40) 114MTERP_OFFSET(offGlue_entryPoint, MterpGlue, entryPoint, 44) 115#if defined(WITH_JIT) 116MTERP_OFFSET(offGlue_pJitProfTable, MterpGlue, pJitProfTable, 52) 117MTERP_OFFSET(offGlue_jitState, MterpGlue, jitState, 56) 118MTERP_OFFSET(offGlue_jitResume, MterpGlue, jitResume, 60) 119MTERP_OFFSET(offGlue_jitResumePC, MterpGlue, jitResumePC, 64) 120MTERP_OFFSET(offGlue_jitThreshold, MterpGlue, jitThreshold, 68) 121MTERP_OFFSET(offGlue_ppJitProfTable, MterpGlue, ppJitProfTable, 72) 122#endif 123#elif defined(WITH_PROFILER) 124MTERP_OFFSET(offGlue_pActiveProfilers, MterpGlue, pActiveProfilers, 40) 125MTERP_OFFSET(offGlue_entryPoint, MterpGlue, entryPoint, 44) 126#if defined(WITH_JIT) 127MTERP_OFFSET(offGlue_pJitProfTable, MterpGlue, pJitProfTable, 52) 128MTERP_OFFSET(offGlue_jitState, MterpGlue, jitState, 56) 129MTERP_OFFSET(offGlue_jitResume, MterpGlue, jitResume, 60) 130MTERP_OFFSET(offGlue_jitResumePC, MterpGlue, jitResumePC, 64) 131MTERP_OFFSET(offGlue_jitThreshold, MterpGlue, jitThreshold, 68) 132MTERP_OFFSET(offGlue_ppJitProfTable, MterpGlue, ppJitProfTable, 72) 133#endif 134#else 135MTERP_OFFSET(offGlue_entryPoint, MterpGlue, entryPoint, 40) 136#if defined(WITH_JIT) 137MTERP_OFFSET(offGlue_pJitProfTable, MterpGlue, pJitProfTable, 48) 138MTERP_OFFSET(offGlue_jitState, MterpGlue, jitState, 52) 139MTERP_OFFSET(offGlue_jitResume, MterpGlue, jitResume, 56) 140MTERP_OFFSET(offGlue_jitResumePC, MterpGlue, jitResumePC, 60) 141MTERP_OFFSET(offGlue_jitThreshold, MterpGlue, jitThreshold, 64) 142MTERP_OFFSET(offGlue_ppJitProfTable, MterpGlue, ppJitProfTable, 68) 143#endif 144#endif 145/* make sure all JValue union members are stored at the same offset */ 146MTERP_OFFSET(offGlue_retval_z, MterpGlue, retval.z, 8) 147MTERP_OFFSET(offGlue_retval_i, MterpGlue, retval.i, 8) 148MTERP_OFFSET(offGlue_retval_j, MterpGlue, retval.j, 8) 149MTERP_OFFSET(offGlue_retval_l, MterpGlue, retval.l, 8) 150 151/* DvmDex fields */ 152MTERP_OFFSET(offDvmDex_pResStrings, DvmDex, pResStrings, 8) 153MTERP_OFFSET(offDvmDex_pResClasses, DvmDex, pResClasses, 12) 154MTERP_OFFSET(offDvmDex_pResMethods, DvmDex, pResMethods, 16) 155MTERP_OFFSET(offDvmDex_pResFields, DvmDex, pResFields, 20) 156MTERP_OFFSET(offDvmDex_pInterfaceCache, DvmDex, pInterfaceCache, 24) 157 158/* StackSaveArea fields */ 159#ifdef EASY_GDB 160MTERP_OFFSET(offStackSaveArea_prevSave, StackSaveArea, prevSave, 0) 161MTERP_OFFSET(offStackSaveArea_prevFrame, StackSaveArea, prevFrame, 4) 162MTERP_OFFSET(offStackSaveArea_savedPc, StackSaveArea, savedPc, 8) 163MTERP_OFFSET(offStackSaveArea_method, StackSaveArea, method, 12) 164MTERP_OFFSET(offStackSaveArea_currentPc, StackSaveArea, xtra.currentPc, 16) 165MTERP_OFFSET(offStackSaveArea_localRefCookie, \ 166 StackSaveArea, xtra.localRefCookie, 16) 167MTERP_OFFSET(offStackSaveArea_returnAddr, StackSaveArea, returnAddr, 20) 168MTERP_SIZEOF(sizeofStackSaveArea, StackSaveArea, 24) 169#else 170MTERP_OFFSET(offStackSaveArea_prevFrame, StackSaveArea, prevFrame, 0) 171MTERP_OFFSET(offStackSaveArea_savedPc, StackSaveArea, savedPc, 4) 172MTERP_OFFSET(offStackSaveArea_method, StackSaveArea, method, 8) 173MTERP_OFFSET(offStackSaveArea_currentPc, StackSaveArea, xtra.currentPc, 12) 174MTERP_OFFSET(offStackSaveArea_localRefCookie, \ 175 StackSaveArea, xtra.localRefCookie, 12) 176MTERP_OFFSET(offStackSaveArea_returnAddr, StackSaveArea, returnAddr, 16) 177MTERP_SIZEOF(sizeofStackSaveArea, StackSaveArea, 20) 178#endif 179 180 /* ShadowSpace fields */ 181#if defined(WITH_JIT) && defined(WITH_SELF_VERIFICATION) 182MTERP_OFFSET(offShadowSpace_startPC, ShadowSpace, startPC, 0) 183MTERP_OFFSET(offShadowSpace_fp, ShadowSpace, fp, 4) 184MTERP_OFFSET(offShadowSpace_glue, ShadowSpace, glue, 8) 185MTERP_OFFSET(offShadowSpace_svState, ShadowSpace, selfVerificationState, 12) 186MTERP_OFFSET(offShadowSpace_shadowFP, ShadowSpace, shadowFP, 20) 187MTERP_OFFSET(offShadowSpace_interpState, ShadowSpace, interpState, 24) 188#endif 189 190/* InstField fields */ 191#ifdef PROFILE_FIELD_ACCESS 192MTERP_OFFSET(offInstField_byteOffset, InstField, byteOffset, 24) 193#else 194MTERP_OFFSET(offInstField_byteOffset, InstField, byteOffset, 16) 195#endif 196 197/* StaticField fields */ 198#ifdef PROFILE_FIELD_ACCESS 199MTERP_OFFSET(offStaticField_value, StaticField, value, 24) 200#else 201MTERP_OFFSET(offStaticField_value, StaticField, value, 16) 202#endif 203 204/* Method fields */ 205MTERP_OFFSET(offMethod_clazz, Method, clazz, 0) 206MTERP_OFFSET(offMethod_accessFlags, Method, accessFlags, 4) 207MTERP_OFFSET(offMethod_methodIndex, Method, methodIndex, 8) 208MTERP_OFFSET(offMethod_registersSize, Method, registersSize, 10) 209MTERP_OFFSET(offMethod_outsSize, Method, outsSize, 12) 210MTERP_OFFSET(offMethod_name, Method, name, 16) 211MTERP_OFFSET(offMethod_insns, Method, insns, 32) 212MTERP_OFFSET(offMethod_nativeFunc, Method, nativeFunc, 40) 213 214/* InlineOperation fields -- code assumes "func" offset is zero, do not alter */ 215MTERP_OFFSET(offInlineOperation_func, InlineOperation, func, 0) 216 217/* Thread fields */ 218MTERP_OFFSET(offThread_stackOverflowed, Thread, stackOverflowed, 40) 219MTERP_OFFSET(offThread_curFrame, Thread, curFrame, 44) 220MTERP_OFFSET(offThread_exception, Thread, exception, 48) 221 222#if defined(WITH_JIT) 223MTERP_OFFSET(offThread_inJitCodeCache, Thread, inJitCodeCache, 76) 224#ifdef USE_INDIRECT_REF 225MTERP_OFFSET(offThread_jniLocal_topCookie, \ 226 Thread, jniLocalRefTable.segmentState.all, 80) 227#else 228MTERP_OFFSET(offThread_jniLocal_topCookie, \ 229 Thread, jniLocalRefTable.nextEntry, 80) 230#endif 231#else 232#ifdef USE_INDIRECT_REF 233MTERP_OFFSET(offThread_jniLocal_topCookie, \ 234 Thread, jniLocalRefTable.segmentState.all, 76) 235#else 236MTERP_OFFSET(offThread_jniLocal_topCookie, \ 237 Thread, jniLocalRefTable.nextEntry, 76) 238#endif 239#endif 240 241/* Object fields */ 242MTERP_OFFSET(offObject_clazz, Object, clazz, 0) 243MTERP_OFFSET(offObject_lock, Object, lock, 4) 244 245/* Lock shape */ 246MTERP_CONSTANT(LW_LOCK_OWNER_SHIFT, 3) 247MTERP_CONSTANT(LW_HASH_STATE_SHIFT, 1) 248 249/* ArrayObject fields */ 250MTERP_OFFSET(offArrayObject_length, ArrayObject, length, 8) 251#ifdef MTERP_NO_UNALIGN_64 252MTERP_OFFSET(offArrayObject_contents, ArrayObject, contents, 16) 253#else 254MTERP_OFFSET(offArrayObject_contents, ArrayObject, contents, 12) 255#endif 256 257/* String fields */ 258MTERP_CONSTANT(STRING_FIELDOFF_VALUE, 8) 259MTERP_CONSTANT(STRING_FIELDOFF_HASHCODE, 12) 260MTERP_CONSTANT(STRING_FIELDOFF_OFFSET, 16) 261MTERP_CONSTANT(STRING_FIELDOFF_COUNT, 20) 262 263#if defined(WITH_JIT) 264/* 265 * Reasons for the non-chaining interpreter entry points 266 * Enums defined in vm/Globals.h 267 */ 268MTERP_CONSTANT(kInlineCacheMiss, 0) 269MTERP_CONSTANT(kCallsiteInterpreted, 1) 270MTERP_CONSTANT(kSwitchOverflow, 2) 271 272/* Size of callee save area */ 273MTERP_CONSTANT(JIT_CALLEE_SAVE_DOUBLE_COUNT, 8) 274#endif 275 276/* ClassObject fields */ 277MTERP_OFFSET(offClassObject_descriptor, ClassObject, descriptor, 24) 278MTERP_OFFSET(offClassObject_accessFlags, ClassObject, accessFlags, 32) 279MTERP_OFFSET(offClassObject_pDvmDex, ClassObject, pDvmDex, 40) 280MTERP_OFFSET(offClassObject_status, ClassObject, status, 44) 281MTERP_OFFSET(offClassObject_super, ClassObject, super, 72) 282MTERP_OFFSET(offClassObject_vtableCount, ClassObject, vtableCount, 112) 283MTERP_OFFSET(offClassObject_vtable, ClassObject, vtable, 116) 284 285/* InterpEntry enumeration */ 286MTERP_SIZEOF(sizeofClassStatus, InterpEntry, MTERP_SMALL_ENUM) 287MTERP_CONSTANT(kInterpEntryInstr, 0) 288MTERP_CONSTANT(kInterpEntryReturn, 1) 289MTERP_CONSTANT(kInterpEntryThrow, 2) 290#if defined(WITH_JIT) 291MTERP_CONSTANT(kInterpEntryResume, 3) 292#endif 293 294#if defined(WITH_JIT) 295MTERP_CONSTANT(kJitOff, 0) 296MTERP_CONSTANT(kJitNormal, 1) 297MTERP_CONSTANT(kJitTSelectRequest, 2) 298MTERP_CONSTANT(kJitTSelect, 3) 299MTERP_CONSTANT(kJitTSelectAbort, 4) 300MTERP_CONSTANT(kJitTSelectEnd, 5) 301MTERP_CONSTANT(kJitSingleStep, 6) 302MTERP_CONSTANT(kJitSingleStepEnd, 7) 303MTERP_CONSTANT(kJitSelfVerification, 8) 304 305#if defined(WITH_SELF_VERIFICATION) 306MTERP_CONSTANT(kSVSIdle, 0) 307MTERP_CONSTANT(kSVSStart, 1) 308MTERP_CONSTANT(kSVSPunt, 2) 309MTERP_CONSTANT(kSVSSingleStep, 3) 310MTERP_CONSTANT(kSVSTraceSelect, 4) 311MTERP_CONSTANT(kSVSNormal, 5) 312MTERP_CONSTANT(kSVSNoChain, 6) 313MTERP_CONSTANT(kSVSBackwardBranch, 7) 314MTERP_CONSTANT(kSVSDebugInterp, 8) 315#endif 316#endif 317 318/* ClassStatus enumeration */ 319MTERP_SIZEOF(sizeofClassStatus, ClassStatus, MTERP_SMALL_ENUM) 320MTERP_CONSTANT(CLASS_INITIALIZED, 7) 321 322/* MethodType enumeration */ 323MTERP_SIZEOF(sizeofMethodType, MethodType, MTERP_SMALL_ENUM) 324MTERP_CONSTANT(METHOD_DIRECT, 1) 325MTERP_CONSTANT(METHOD_STATIC, 2) 326MTERP_CONSTANT(METHOD_VIRTUAL, 3) 327MTERP_CONSTANT(METHOD_INTERFACE, 4) 328 329/* ClassObject constants */ 330MTERP_CONSTANT(ACC_PRIVATE, 0x0002) 331MTERP_CONSTANT(ACC_STATIC, 0x0008) 332MTERP_CONSTANT(ACC_NATIVE, 0x0100) 333MTERP_CONSTANT(ACC_INTERFACE, 0x0200) 334MTERP_CONSTANT(ACC_ABSTRACT, 0x0400) 335 336/* flags for dvmMalloc */ 337MTERP_CONSTANT(ALLOC_DONT_TRACK, 0x02) 338 339/* opcode number */ 340MTERP_CONSTANT(OP_MOVE_EXCEPTION, 0x0d) 341