Home | History | Annotate | Download | only in common
      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         ALOGE("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         ALOGE("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         ALOGE("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__) || defined(__mips__)
     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 #ifdef HAVE_BIG_ENDIAN
    156 MTERP_OFFSET(offThread_retval_z,          Thread, interpSave.retval.z, 19)
    157 #else
    158 MTERP_OFFSET(offThread_retval_z,          Thread, interpSave.retval.z, 16)
    159 #endif
    160 MTERP_OFFSET(offThread_retval_i,          Thread, interpSave.retval.i, 16)
    161 MTERP_OFFSET(offThread_retval_j,          Thread, interpSave.retval.j, 16)
    162 MTERP_OFFSET(offThread_retval_l,          Thread, interpSave.retval.l, 16)
    163 MTERP_OFFSET(offThread_bailPtr,           Thread, interpSave.bailPtr, 24)
    164 MTERP_OFFSET(offThread_threadId,          Thread, threadId, 36)
    165 
    166 //40
    167 MTERP_OFFSET(offThread_subMode, \
    168                                Thread, interpBreak.ctl.subMode, 40)
    169 MTERP_OFFSET(offThread_breakFlags, \
    170                                Thread, interpBreak.ctl.breakFlags, 42)
    171 MTERP_OFFSET(offThread_curHandlerTable, \
    172                                Thread, interpBreak.ctl.curHandlerTable, 44)
    173 MTERP_OFFSET(offThread_suspendCount,      Thread, suspendCount, 48);
    174 MTERP_OFFSET(offThread_dbgSuspendCount,   Thread, dbgSuspendCount, 52);
    175 MTERP_OFFSET(offThread_cardTable,         Thread, cardTable, 56)
    176 MTERP_OFFSET(offThread_interpStackEnd,    Thread, interpStackEnd, 60)
    177 MTERP_OFFSET(offThread_exception,         Thread, exception, 68)
    178 MTERP_OFFSET(offThread_debugIsMethodEntry, Thread, debugIsMethodEntry, 72)
    179 MTERP_OFFSET(offThread_interpStackSize,   Thread, interpStackSize, 76)
    180 MTERP_OFFSET(offThread_stackOverflowed,   Thread, stackOverflowed, 80)
    181 MTERP_OFFSET(offThread_mainHandlerTable,  Thread, mainHandlerTable, 88)
    182 MTERP_OFFSET(offThread_singleStepCount,   Thread, singleStepCount, 96)
    183 
    184 #ifdef WITH_JIT
    185 MTERP_OFFSET(offThread_jitToInterpEntries,Thread, jitToInterpEntries, 100)
    186 MTERP_OFFSET(offThread_inJitCodeCache,    Thread, inJitCodeCache, 124)
    187 MTERP_OFFSET(offThread_pJitProfTable,     Thread, pJitProfTable, 128)
    188 MTERP_OFFSET(offThread_jitThreshold,      Thread, jitThreshold, 132)
    189 MTERP_OFFSET(offThread_jitResumeNPC,      Thread, jitResumeNPC, 136)
    190 MTERP_OFFSET(offThread_jitResumeNSP,      Thread, jitResumeNSP, 140)
    191 MTERP_OFFSET(offThread_jitResumeDPC,      Thread, jitResumeDPC, 144)
    192 MTERP_OFFSET(offThread_jitState,          Thread, jitState, 148)
    193 MTERP_OFFSET(offThread_icRechainCount,    Thread, icRechainCount, 152)
    194 MTERP_OFFSET(offThread_pProfileCountdown, Thread, pProfileCountdown, 156)
    195 MTERP_OFFSET(offThread_callsiteClass,     Thread, callsiteClass, 160)
    196 MTERP_OFFSET(offThread_methodToCall,      Thread, methodToCall, 164)
    197 MTERP_OFFSET(offThread_jniLocal_topCookie, \
    198                                 Thread, jniLocalRefTable.segmentState.all, 168)
    199 #if defined(WITH_SELF_VERIFICATION)
    200 MTERP_OFFSET(offThread_shadowSpace,       Thread, shadowSpace, 188)
    201 #endif
    202 #else
    203 MTERP_OFFSET(offThread_jniLocal_topCookie, \
    204                                 Thread, jniLocalRefTable.segmentState.all, 100)
    205 #endif
    206 
    207 /* Object fields */
    208 MTERP_OFFSET(offObject_clazz,           Object, clazz, 0)
    209 MTERP_OFFSET(offObject_lock,            Object, lock, 4)
    210 
    211 /* Lock shape */
    212 MTERP_CONSTANT(LW_LOCK_OWNER_SHIFT, 3)
    213 MTERP_CONSTANT(LW_HASH_STATE_SHIFT, 1)
    214 
    215 /* ArrayObject fields */
    216 MTERP_OFFSET(offArrayObject_length,     ArrayObject, length, 8)
    217 #ifdef MTERP_NO_UNALIGN_64
    218 MTERP_OFFSET(offArrayObject_contents,   ArrayObject, contents, 16)
    219 #else
    220 MTERP_OFFSET(offArrayObject_contents,   ArrayObject, contents, 12)
    221 #endif
    222 
    223 /* String fields */
    224 MTERP_CONSTANT(STRING_FIELDOFF_VALUE,     8)
    225 MTERP_CONSTANT(STRING_FIELDOFF_HASHCODE, 12)
    226 MTERP_CONSTANT(STRING_FIELDOFF_OFFSET,   16)
    227 MTERP_CONSTANT(STRING_FIELDOFF_COUNT,    20)
    228 
    229 #if defined(WITH_JIT)
    230 /*
    231  * Reasons for the non-chaining interpreter entry points
    232  * Enums defined in vm/Globals.h
    233  */
    234 MTERP_CONSTANT(kInlineCacheMiss,        0)
    235 MTERP_CONSTANT(kCallsiteInterpreted,    1)
    236 MTERP_CONSTANT(kSwitchOverflow,         2)
    237 MTERP_CONSTANT(kHeavyweightMonitor,     3)
    238 
    239 /* Size of callee save area */
    240 MTERP_CONSTANT(JIT_CALLEE_SAVE_DOUBLE_COUNT,   8)
    241 #endif
    242 
    243 /* ClassObject fields */
    244 MTERP_OFFSET(offClassObject_descriptor, ClassObject, descriptor, 24)
    245 MTERP_OFFSET(offClassObject_accessFlags, ClassObject, accessFlags, 32)
    246 MTERP_OFFSET(offClassObject_pDvmDex,    ClassObject, pDvmDex, 40)
    247 MTERP_OFFSET(offClassObject_status,     ClassObject, status, 44)
    248 MTERP_OFFSET(offClassObject_super,      ClassObject, super, 72)
    249 MTERP_OFFSET(offClassObject_vtableCount, ClassObject, vtableCount, 112)
    250 MTERP_OFFSET(offClassObject_vtable,     ClassObject, vtable, 116)
    251 
    252 #if defined(WITH_JIT)
    253 MTERP_CONSTANT(kJitNot,                 0)
    254 MTERP_CONSTANT(kJitTSelectRequest,      1)
    255 MTERP_CONSTANT(kJitTSelectRequestHot,   2)
    256 MTERP_CONSTANT(kJitSelfVerification,    3)
    257 MTERP_CONSTANT(kJitTSelect,             4)
    258 MTERP_CONSTANT(kJitTSelectEnd,          5)
    259 MTERP_CONSTANT(kJitDone,                6)
    260 
    261 #if defined(WITH_SELF_VERIFICATION)
    262 MTERP_CONSTANT(kSVSIdle, 0)
    263 MTERP_CONSTANT(kSVSStart, 1)
    264 MTERP_CONSTANT(kSVSPunt, 2)
    265 MTERP_CONSTANT(kSVSSingleStep, 3)
    266 MTERP_CONSTANT(kSVSNoProfile, 4)
    267 MTERP_CONSTANT(kSVSTraceSelect, 5)
    268 MTERP_CONSTANT(kSVSNormal, 6)
    269 MTERP_CONSTANT(kSVSNoChain, 7)
    270 MTERP_CONSTANT(kSVSBackwardBranch, 8)
    271 MTERP_CONSTANT(kSVSDebugInterp, 9)
    272 #endif
    273 #endif
    274 
    275 /* ClassStatus enumeration */
    276 MTERP_SIZEOF(sizeofClassStatus,         ClassStatus, MTERP_SMALL_ENUM)
    277 MTERP_CONSTANT(CLASS_INITIALIZED,   7)
    278 
    279 /* MethodType enumeration */
    280 MTERP_SIZEOF(sizeofMethodType,          MethodType, MTERP_SMALL_ENUM)
    281 MTERP_CONSTANT(METHOD_DIRECT,       1)
    282 MTERP_CONSTANT(METHOD_STATIC,       2)
    283 MTERP_CONSTANT(METHOD_VIRTUAL,      3)
    284 MTERP_CONSTANT(METHOD_INTERFACE,    4)
    285 
    286 /* ClassObject constants */
    287 MTERP_CONSTANT(ACC_PRIVATE,         0x0002)
    288 MTERP_CONSTANT(ACC_STATIC,          0x0008)
    289 MTERP_CONSTANT(ACC_NATIVE,          0x0100)
    290 MTERP_CONSTANT(ACC_INTERFACE,       0x0200)
    291 MTERP_CONSTANT(ACC_ABSTRACT,        0x0400)
    292 MTERP_CONSTANT(CLASS_ISFINALIZABLE, 1<<31)
    293 
    294 /* flags for dvmMalloc */
    295 MTERP_CONSTANT(ALLOC_DONT_TRACK,    0x01)
    296 
    297 /* for GC */
    298 MTERP_CONSTANT(GC_CARD_SHIFT, 7)
    299 
    300 /* opcode number */
    301 MTERP_CONSTANT(OP_MOVE_EXCEPTION,   0x0d)
    302 MTERP_CONSTANT(OP_INVOKE_DIRECT_RANGE, 0x76)
    303 
    304 /* flags for interpBreak */
    305 MTERP_CONSTANT(kSubModeNormal,          0x0000)
    306 MTERP_CONSTANT(kSubModeMethodTrace,     0x0001)
    307 MTERP_CONSTANT(kSubModeEmulatorTrace,   0x0002)
    308 MTERP_CONSTANT(kSubModeInstCounting,    0x0004)
    309 MTERP_CONSTANT(kSubModeDebuggerActive,  0x0008)
    310 MTERP_CONSTANT(kSubModeSuspendPending,  0x0010)
    311 MTERP_CONSTANT(kSubModeCallbackPending, 0x0020)
    312 MTERP_CONSTANT(kSubModeCountedStep,     0x0040)
    313 MTERP_CONSTANT(kSubModeJitTraceBuild,   0x4000)
    314 MTERP_CONSTANT(kSubModeJitSV,           0x8000)
    315 MTERP_CONSTANT(kSubModeDebugProfile,    0x000f)
    316 
    317 MTERP_CONSTANT(kInterpNoBreak,            0x00)
    318 MTERP_CONSTANT(kInterpSingleStep,         0x01)
    319 MTERP_CONSTANT(kInterpSafePoint,          0x02)
    320 
    321 MTERP_CONSTANT(DBG_METHOD_ENTRY,          0x04)
    322 MTERP_CONSTANT(DBG_METHOD_EXIT,           0x08)
    323 
    324 #if defined(__thumb__)
    325 # define PCREL_REF(sym,label) sym-(label+4)
    326 #else
    327 # define PCREL_REF(sym,label) sym-(label+8)
    328 #endif
    329