1a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 2a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * This file was generated automatically by gen-mterp.py for 'armv7-a'. 3a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 4a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * --> DO NOT EDIT <-- 5a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 6a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 7cd8f5e701547739f241594b43e9470c92d98e9cfCarl Shapiro/* File: c/header.cpp */ 8a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 9a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Copyright (C) 2008 The Android Open Source Project 10a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 11a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Licensed under the Apache License, Version 2.0 (the "License"); 12a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * you may not use this file except in compliance with the License. 13a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * You may obtain a copy of the License at 14a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 15a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * http://www.apache.org/licenses/LICENSE-2.0 16a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 17a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Unless required by applicable law or agreed to in writing, software 18a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * distributed under the License is distributed on an "AS IS" BASIS, 19a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * See the License for the specific language governing permissions and 21a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * limitations under the License. 22a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 23a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 24a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* common includes */ 25a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#include "Dalvik.h" 26a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#include "interp/InterpDefs.h" 27a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#include "mterp/Mterp.h" 28a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#include <math.h> // needed for fmod, fmodf 29a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#include "mterp/common/FindInterface.h" 30a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 31a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 32a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Configuration defines. These affect the C implementations, i.e. the 33a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * portable interpreter(s) and C stubs. 34a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 35a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Some defines are controlled by the Makefile, e.g.: 36a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * WITH_INSTR_CHECKS 37a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * WITH_TRACKREF_CHECKS 38a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * EASY_GDB 39a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * NDEBUG 40a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 41a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 42a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef WITH_INSTR_CHECKS /* instruction-level paranoia (slow!) */ 43a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define CHECK_BRANCH_OFFSETS 44a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define CHECK_REGISTER_INDICES 45a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 46a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 47a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 48529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * Some architectures require 64-bit alignment for access to 64-bit data 49529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * types. We can't just use pointers to copy 64-bit values out of our 50529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * interpreted register set, because gcc may assume the pointer target is 51529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * aligned and generate invalid code. 52a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 53529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * There are two common approaches: 54529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * (1) Use a union that defines a 32-bit pair and a 64-bit value. 55529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * (2) Call memcpy(). 56529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * 57529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * Depending upon what compiler you're using and what options are specified, 58529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * one may be faster than the other. For example, the compiler might 59529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * convert a memcpy() of 8 bytes into a series of instructions and omit 60529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * the call. The union version could cause some strange side-effects, 61529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * e.g. for a while ARM gcc thought it needed separate storage for each 62529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * inlined instance, and generated instructions to zero out ~700 bytes of 63529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * stack space at the top of the interpreter. 64529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * 65529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * The default is to use memcpy(). The current gcc for ARM seems to do 66529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden * better with the union. 67a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 68a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if defined(__ARM_EABI__) 69529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden# define NO_UNALIGN_64__UNION 70a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 71a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 72529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden 73a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden//#define LOG_INSTR /* verbose debugging */ 74a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* set and adjust ANDROID_LOG_TAGS='*:i jdwp:i dalvikvm:i dalvikvmi:i' */ 75a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 76a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 77a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Export another copy of the PC on every instruction; this is largely 78a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * redundant with EXPORT_PC and the debugger code. This value can be 79a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * compared against what we have stored on the stack with EXPORT_PC to 80a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * help ensure that we aren't missing any export calls. 81a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 82a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if WITH_EXTRA_GC_CHECKS > 1 83a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define EXPORT_EXTRA_PC() (self->currentPc2 = pc) 84a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else 85a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define EXPORT_EXTRA_PC() 86a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 87a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 88a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 89a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Adjust the program counter. "_offset" is a signed int, in 16-bit units. 90a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 91a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Assumes the existence of "const u2* pc" and "const u2* curMethod->insns". 92a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 93a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * We don't advance the program counter until we finish an instruction or 94a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * branch, because we do want to have to unroll the PC if there's an 95a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * exception. 96a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 97a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef CHECK_BRANCH_OFFSETS 98a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ADJUST_PC(_offset) do { \ 99a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden int myoff = _offset; /* deref only once */ \ 100a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (pc + myoff < curMethod->insns || \ 101a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden pc + myoff >= curMethod->insns + dvmGetMethodInsnsSize(curMethod)) \ 102a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 103a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden char* desc; \ 104a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden desc = dexProtoCopyMethodDescriptor(&curMethod->prototype); \ 105c1a4ab9c313d8a3d12007f2dbef7b5a6fa4ac2efSteve Block ALOGE("Invalid branch %d at 0x%04x in %s.%s %s", \ 106a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden myoff, (int) (pc - curMethod->insns), \ 107a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden curMethod->clazz->descriptor, curMethod->name, desc); \ 108a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden free(desc); \ 109a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden dvmAbort(); \ 110a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 111a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden pc += myoff; \ 112a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_EXTRA_PC(); \ 113a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } while (false) 114a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else 115a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ADJUST_PC(_offset) do { \ 116a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden pc += _offset; \ 117a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_EXTRA_PC(); \ 118a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } while (false) 119a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 120a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 121a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 122a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * If enabled, log instructions as we execute them. 123a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 124a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef LOG_INSTR 125a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ILOGD(...) ILOG(LOG_DEBUG, __VA_ARGS__) 126a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ILOGV(...) ILOG(LOG_VERBOSE, __VA_ARGS__) 127a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ILOG(_level, ...) do { \ 128a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden char debugStrBuf[128]; \ 129a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden snprintf(debugStrBuf, sizeof(debugStrBuf), __VA_ARGS__); \ 13060fc806b679a3655c228b4093058c59941a49cfeDan Bornstein if (curMethod != NULL) \ 1311663a6c12fdf4732d7ea0a0406af6085b3c408e4Steve Block ALOG(_level, LOG_TAG"i", "%-2d|%04x%s", \ 132a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden self->threadId, (int)(pc - curMethod->insns), debugStrBuf); \ 133a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else \ 1341663a6c12fdf4732d7ea0a0406af6085b3c408e4Steve Block ALOG(_level, LOG_TAG"i", "%-2d|####%s", \ 135a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden self->threadId, debugStrBuf); \ 136a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } while(false) 137a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenvoid dvmDumpRegs(const Method* method, const u4* framePtr, bool inOnly); 138a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define DUMP_REGS(_meth, _frame, _inOnly) dvmDumpRegs(_meth, _frame, _inOnly) 139a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic const char kSpacing[] = " "; 140a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else 141a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ILOGD(...) ((void)0) 142a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define ILOGV(...) ((void)0) 143a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define DUMP_REGS(_meth, _frame, _inOnly) ((void)0) 144a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 145a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 146a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* get a long from an array of u4 */ 147a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic inline s8 getLongFromArray(const u4* ptr, int idx) 148a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{ 149a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if defined(NO_UNALIGN_64__UNION) 150a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden union { s8 ll; u4 parts[2]; } conv; 151a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 152a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ptr += idx; 153a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden conv.parts[0] = ptr[0]; 154a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden conv.parts[1] = ptr[1]; 155a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return conv.ll; 156529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden#else 157a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden s8 val; 158a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden memcpy(&val, &ptr[idx], 8); 159a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return val; 160a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 161a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden} 162a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 163a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* store a long into an array of u4 */ 164a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic inline void putLongToArray(u4* ptr, int idx, s8 val) 165a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{ 166a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if defined(NO_UNALIGN_64__UNION) 167a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden union { s8 ll; u4 parts[2]; } conv; 168a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 169a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ptr += idx; 170a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden conv.ll = val; 171a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ptr[0] = conv.parts[0]; 172a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ptr[1] = conv.parts[1]; 173a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else 174529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden memcpy(&ptr[idx], &val, 8); 175a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 176a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden} 177a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 178a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* get a double from an array of u4 */ 179a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic inline double getDoubleFromArray(const u4* ptr, int idx) 180a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{ 181a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if defined(NO_UNALIGN_64__UNION) 182a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden union { double d; u4 parts[2]; } conv; 183a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 184a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ptr += idx; 185a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden conv.parts[0] = ptr[0]; 186a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden conv.parts[1] = ptr[1]; 187a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return conv.d; 188529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden#else 189a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden double dval; 190a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden memcpy(&dval, &ptr[idx], 8); 191a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return dval; 192a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 193a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden} 194a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 195a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* store a double into an array of u4 */ 196a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic inline void putDoubleToArray(u4* ptr, int idx, double dval) 197a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{ 198a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#if defined(NO_UNALIGN_64__UNION) 199a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden union { double d; u4 parts[2]; } conv; 200a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 201a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ptr += idx; 202a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden conv.d = dval; 203a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ptr[0] = conv.parts[0]; 204a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ptr[1] = conv.parts[1]; 205a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else 206529d6b8112a06daca3bf4a89dec9fbad95efe46bAndy McFadden memcpy(&ptr[idx], &dval, 8); 207a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 208a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden} 209a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 210a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 211a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * If enabled, validate the register number on every access. Otherwise, 212a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * just do an array access. 213a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 214a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Assumes the existence of "u4* fp". 215a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 216a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * "_idx" may be referenced more than once. 217a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 218a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef CHECK_REGISTER_INDICES 219a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER(_idx) \ 220a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ( (_idx) < curMethod->registersSize ? \ 221a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (fp[(_idx)]) : (assert(!"bad reg"),1969) ) 222a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER(_idx, _val) \ 223a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ( (_idx) < curMethod->registersSize ? \ 224a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (fp[(_idx)] = (u4)(_val)) : (assert(!"bad reg"),1969) ) 225a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_AS_OBJECT(_idx) ((Object *)GET_REGISTER(_idx)) 226a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_AS_OBJECT(_idx, _val) SET_REGISTER(_idx, (s4)_val) 227a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_INT(_idx) ((s4) GET_REGISTER(_idx)) 228a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_INT(_idx, _val) SET_REGISTER(_idx, (s4)_val) 229a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_WIDE(_idx) \ 230a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ( (_idx) < curMethod->registersSize-1 ? \ 231a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden getLongFromArray(fp, (_idx)) : (assert(!"bad reg"),1969) ) 232a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_WIDE(_idx, _val) \ 233a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ( (_idx) < curMethod->registersSize-1 ? \ 2349c6f0a6a36fcce4a55e3764db45c6c7cced077a5Carl Shapiro (void)putLongToArray(fp, (_idx), (_val)) : assert(!"bad reg") ) 235a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_FLOAT(_idx) \ 236a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ( (_idx) < curMethod->registersSize ? \ 237a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (*((float*) &fp[(_idx)])) : (assert(!"bad reg"),1969.0f) ) 238a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_FLOAT(_idx, _val) \ 239a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ( (_idx) < curMethod->registersSize ? \ 240a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (*((float*) &fp[(_idx)]) = (_val)) : (assert(!"bad reg"),1969.0f) ) 241a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_DOUBLE(_idx) \ 242a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ( (_idx) < curMethod->registersSize-1 ? \ 243a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden getDoubleFromArray(fp, (_idx)) : (assert(!"bad reg"),1969.0) ) 244a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_DOUBLE(_idx, _val) \ 245a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ( (_idx) < curMethod->registersSize-1 ? \ 2469c6f0a6a36fcce4a55e3764db45c6c7cced077a5Carl Shapiro (void)putDoubleToArray(fp, (_idx), (_val)) : assert(!"bad reg") ) 247a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else 248a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER(_idx) (fp[(_idx)]) 249a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER(_idx, _val) (fp[(_idx)] = (_val)) 250a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_AS_OBJECT(_idx) ((Object*) fp[(_idx)]) 251a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_AS_OBJECT(_idx, _val) (fp[(_idx)] = (u4)(_val)) 252a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_INT(_idx) ((s4)GET_REGISTER(_idx)) 253a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_INT(_idx, _val) SET_REGISTER(_idx, (s4)_val) 254a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_WIDE(_idx) getLongFromArray(fp, (_idx)) 255a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_WIDE(_idx, _val) putLongToArray(fp, (_idx), (_val)) 256a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_FLOAT(_idx) (*((float*) &fp[(_idx)])) 257a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_FLOAT(_idx, _val) (*((float*) &fp[(_idx)]) = (_val)) 258a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define GET_REGISTER_DOUBLE(_idx) getDoubleFromArray(fp, (_idx)) 259a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden# define SET_REGISTER_DOUBLE(_idx, _val) putDoubleToArray(fp, (_idx), (_val)) 260a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 261a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 262a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 263a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Get 16 bits from the specified offset of the program counter. We always 264a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * want to load 16 bits at a time from the instruction stream -- it's more 265a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * efficient than 8 and won't have the alignment problems that 32 might. 266a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 267a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Assumes existence of "const u2* pc". 268a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 269a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define FETCH(_offset) (pc[(_offset)]) 270a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 271a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 272a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Extract instruction byte from 16-bit fetch (_inst is a u2). 273a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 274a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define INST_INST(_inst) ((_inst) & 0xff) 275a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 276a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 27796516932f1557d8f48a8b2dbbb885af01a11ef6eAndy McFadden * Replace the opcode (used when handling breakpoints). _opcode is a u1. 27896516932f1557d8f48a8b2dbbb885af01a11ef6eAndy McFadden */ 27996516932f1557d8f48a8b2dbbb885af01a11ef6eAndy McFadden#define INST_REPLACE_OP(_inst, _opcode) (((_inst) & 0xff00) | _opcode) 28096516932f1557d8f48a8b2dbbb885af01a11ef6eAndy McFadden 28196516932f1557d8f48a8b2dbbb885af01a11ef6eAndy McFadden/* 282a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Extract the "vA, vB" 4-bit registers from the instruction word (_inst is u2). 283a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 284a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define INST_A(_inst) (((_inst) >> 8) & 0x0f) 285a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define INST_B(_inst) ((_inst) >> 12) 286a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 287a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 288a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Get the 8-bit "vAA" 8-bit register index from the instruction word. 289a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * (_inst is u2) 290a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 291a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define INST_AA(_inst) ((_inst) >> 8) 292a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 293a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 294a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * The current PC must be available to Throwable constructors, e.g. 29598f3eb12bf2a33c49712e093d5cc2aa713a93aa5buzbee * those created by the various exception throw routines, so that the 29698f3eb12bf2a33c49712e093d5cc2aa713a93aa5buzbee * exception stack trace can be generated correctly. If we don't do this, 29798f3eb12bf2a33c49712e093d5cc2aa713a93aa5buzbee * the offset within the current method won't be shown correctly. See the 29898f3eb12bf2a33c49712e093d5cc2aa713a93aa5buzbee * notes in Exception.c. 299a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 300a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * This is also used to determine the address for precise GC. 301a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 302a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Assumes existence of "u4* fp" and "const u2* pc". 303a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 304a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define EXPORT_PC() (SAVEAREA_FROM_FP(fp)->xtra.currentPc = pc) 305a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 306a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 307a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Check to see if "obj" is NULL. If so, throw an exception. Assumes the 308a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * pc has already been exported to the stack. 309a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 310a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Perform additional checks on debug builds. 311a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 312a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Use this to check for NULL when the instruction handler calls into 313a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * something that could throw an exception (so we have already called 314a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * EXPORT_PC at the top). 315a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 316a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic inline bool checkForNull(Object* obj) 317a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{ 318a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (obj == NULL) { 319d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein dvmThrowNullPointerException(NULL); 320a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return false; 321a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } 322a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef WITH_EXTRA_OBJECT_VALIDATION 32334987b48d216786454aca59474cb76015af48bd9Jeff Brown if (!dvmIsHeapAddress(obj)) { 324c1a4ab9c313d8a3d12007f2dbef7b5a6fa4ac2efSteve Block ALOGE("Invalid object %p", obj); 325a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden dvmAbort(); 326a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } 327a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 328a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifndef NDEBUG 329a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (obj->clazz == NULL || ((u4) obj->clazz) <= 65536) { 330a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden /* probable heap corruption */ 331c1a4ab9c313d8a3d12007f2dbef7b5a6fa4ac2efSteve Block ALOGE("Invalid object class %p (in %p)", obj->clazz, obj); 332a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden dvmAbort(); 333a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } 334a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 335a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return true; 336a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden} 337a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 338a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 339a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Check to see if "obj" is NULL. If so, export the PC into the stack 340a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * frame and throw an exception. 341a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 342a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Perform additional checks on debug builds. 343a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 344a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Use this to check for NULL when the instruction handler doesn't do 345a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * anything else that can throw an exception. 346a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 347a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenstatic inline bool checkForNullExportPC(Object* obj, u4* fp, const u2* pc) 348a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{ 349a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (obj == NULL) { 350a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); 351d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein dvmThrowNullPointerException(NULL); 352a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return false; 353a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } 354a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef WITH_EXTRA_OBJECT_VALIDATION 3558bc8bf71a52e17d483021b4c9dc8e735d9bce3edElliott Hughes if (!dvmIsHeapAddress(obj)) { 356c1a4ab9c313d8a3d12007f2dbef7b5a6fa4ac2efSteve Block ALOGE("Invalid object %p", obj); 357a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden dvmAbort(); 358a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } 359a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 360a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifndef NDEBUG 361a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (obj->clazz == NULL || ((u4) obj->clazz) <= 65536) { 362a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden /* probable heap corruption */ 363c1a4ab9c313d8a3d12007f2dbef7b5a6fa4ac2efSteve Block ALOGE("Invalid object class %p (in %p)", obj->clazz, obj); 364a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden dvmAbort(); 365a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } 366a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 367a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return true; 368a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden} 369a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 370cd8f5e701547739f241594b43e9470c92d98e9cfCarl Shapiro/* File: cstubs/stubdefs.cpp */ 371a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 372a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * In the C mterp stubs, "goto" is a function call followed immediately 373a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * by a return. 374a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 375a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 376a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_TARGET_DECL(_target, ...) \ 377cd8f5e701547739f241594b43e9470c92d98e9cfCarl Shapiro extern "C" void dvmMterp_##_target(Thread* self, ## __VA_ARGS__); 378a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 3797520ee7ff226e12e06818561b15741d2575072e3buzbee/* (void)xxx to quiet unused variable compiler warnings. */ 380a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_TARGET(_target, ...) \ 3819f601a917c8878204482c37aec7005054b6776fabuzbee void dvmMterp_##_target(Thread* self, ## __VA_ARGS__) { \ 382a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 ref, vsrc1, vsrc2, vdst; \ 383a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 inst = FETCH(0); \ 384a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden const Method* methodToCall; \ 3857520ee7ff226e12e06818561b15741d2575072e3buzbee StackSaveArea* debugSaveArea; \ 3867520ee7ff226e12e06818561b15741d2575072e3buzbee (void)ref; (void)vsrc1; (void)vsrc2; (void)vdst; (void)inst; \ 3877520ee7ff226e12e06818561b15741d2575072e3buzbee (void)methodToCall; (void)debugSaveArea; 388a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 389a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_TARGET_END } 390a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 391a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 3929f601a917c8878204482c37aec7005054b6776fabuzbee * Redefine what used to be local variable accesses into Thread struct 393bbf31b58c50fb892423b7fef0d8c1093bd0c1a6cBrian Carlstrom * references. (These are undefined down in "footer.cpp".) 394a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 395cf4a20cf0cbc53f03a5b16c7152bbb29907f7108buzbee#define retval self->interpSave.retval 3969f601a917c8878204482c37aec7005054b6776fabuzbee#define pc self->interpSave.pc 39730bc0d46ae730d78c42c39cfa56a59ba3025380bbuzbee#define fp self->interpSave.curFrame 3989f601a917c8878204482c37aec7005054b6776fabuzbee#define curMethod self->interpSave.method 3999f601a917c8878204482c37aec7005054b6776fabuzbee#define methodClassDex self->interpSave.methodClassDex 4009f601a917c8878204482c37aec7005054b6776fabuzbee#define debugTrackedRefStart self->interpSave.debugTrackedRefStart 401a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 402a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* ugh */ 403a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define STUB_HACK(x) x 4049a3147c7412f4794434b4c2604aa2ba784867774buzbee#if defined(WITH_JIT) 4059a3147c7412f4794434b4c2604aa2ba784867774buzbee#define JIT_STUB_HACK(x) x 4069a3147c7412f4794434b4c2604aa2ba784867774buzbee#else 4079a3147c7412f4794434b4c2604aa2ba784867774buzbee#define JIT_STUB_HACK(x) 4089a3147c7412f4794434b4c2604aa2ba784867774buzbee#endif 409a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 41099e3e6e72e3471eb85fc2e405866392b01c080febuzbee/* 41199e3e6e72e3471eb85fc2e405866392b01c080febuzbee * InterpSave's pc and fp must be valid when breaking out to a 41299e3e6e72e3471eb85fc2e405866392b01c080febuzbee * "Reportxxx" routine. Because the portable interpreter uses local 41399e3e6e72e3471eb85fc2e405866392b01c080febuzbee * variables for these, we must flush prior. Stubs, however, use 41499e3e6e72e3471eb85fc2e405866392b01c080febuzbee * the interpSave vars directly, so this is a nop for stubs. 41599e3e6e72e3471eb85fc2e405866392b01c080febuzbee */ 41699e3e6e72e3471eb85fc2e405866392b01c080febuzbee#define PC_FP_TO_SELF() 41730bc0d46ae730d78c42c39cfa56a59ba3025380bbuzbee#define PC_TO_SELF() 418a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 419a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 420a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Opcode handler framing macros. Here, each opcode is a separate function 4219f601a917c8878204482c37aec7005054b6776fabuzbee * that takes a "self" argument and returns void. We can't declare 422a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * these "static" because they may be called from an assembly stub. 4237520ee7ff226e12e06818561b15741d2575072e3buzbee * (void)xxx to quiet unused variable compiler warnings. 424a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 425a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OPCODE(_op) \ 426cd8f5e701547739f241594b43e9470c92d98e9cfCarl Shapiro extern "C" void dvmMterp_##_op(Thread* self); \ 4279f601a917c8878204482c37aec7005054b6776fabuzbee void dvmMterp_##_op(Thread* self) { \ 4286aed656b06aa274948bf5c5f8f65873814554c13Andy McFadden u4 ref; \ 4296aed656b06aa274948bf5c5f8f65873814554c13Andy McFadden u2 vsrc1, vsrc2, vdst; \ 4307520ee7ff226e12e06818561b15741d2575072e3buzbee u2 inst = FETCH(0); \ 4317520ee7ff226e12e06818561b15741d2575072e3buzbee (void)ref; (void)vsrc1; (void)vsrc2; (void)vdst; (void)inst; 432a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 433a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define OP_END } 434a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 435a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 436a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Like the "portable" FINISH, but don't reload "inst", and return to caller 4379a3147c7412f4794434b4c2604aa2ba784867774buzbee * when done. Further, debugger/profiler checks are handled 4389a3147c7412f4794434b4c2604aa2ba784867774buzbee * before handler execution in mterp, so we don't do them here either. 439a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 4409a3147c7412f4794434b4c2604aa2ba784867774buzbee#if defined(WITH_JIT) 441a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define FINISH(_offset) { \ 442a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ADJUST_PC(_offset); \ 4439a3147c7412f4794434b4c2604aa2ba784867774buzbee if (self->interpBreak.ctl.subMode & kSubModeJitTraceBuild) { \ 4449a3147c7412f4794434b4c2604aa2ba784867774buzbee dvmCheckJit(pc, self); \ 4459a3147c7412f4794434b4c2604aa2ba784867774buzbee } \ 446a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return; \ 447a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } 4489a3147c7412f4794434b4c2604aa2ba784867774buzbee#else 4499a3147c7412f4794434b4c2604aa2ba784867774buzbee#define FINISH(_offset) { \ 4509a3147c7412f4794434b4c2604aa2ba784867774buzbee ADJUST_PC(_offset); \ 4519a3147c7412f4794434b4c2604aa2ba784867774buzbee return; \ 4529a3147c7412f4794434b4c2604aa2ba784867774buzbee } 4539a3147c7412f4794434b4c2604aa2ba784867774buzbee#endif 454a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 455a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 456a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 457a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * The "goto label" statements turn into function calls followed by 458a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * return statements. Some of the functions take arguments, which in the 459a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * portable interpreter are handled by assigning values to globals. 460a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 461a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 462a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_exceptionThrown() \ 463a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden do { \ 4649f601a917c8878204482c37aec7005054b6776fabuzbee dvmMterp_exceptionThrown(self); \ 465a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return; \ 466a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } while(false) 467a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 468a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_returnFromMethod() \ 469a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden do { \ 4709f601a917c8878204482c37aec7005054b6776fabuzbee dvmMterp_returnFromMethod(self); \ 471a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return; \ 472a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } while(false) 473a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 474ab35b50311951feea3782151dd5422ee944685c2Elliott Hughes#define GOTO_invoke(_target, _methodCallRange) \ 475a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden do { \ 476ab35b50311951feea3782151dd5422ee944685c2Elliott Hughes dvmMterp_##_target(self, _methodCallRange); \ 477a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return; \ 478a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } while(false) 479a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 480a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_invokeMethod(_methodCallRange, _methodToCall, _vsrc1, _vdst) \ 481a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden do { \ 4829f601a917c8878204482c37aec7005054b6776fabuzbee dvmMterp_invokeMethod(self, _methodCallRange, _methodToCall, \ 483a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden _vsrc1, _vdst); \ 484a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden return; \ 485a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } while(false) 486a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 487a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 4889a3147c7412f4794434b4c2604aa2ba784867774buzbee * As a special case, "goto bail" turns into a longjmp. 489a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 490a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define GOTO_bail() \ 4919f601a917c8878204482c37aec7005054b6776fabuzbee dvmMterpStdBail(self, false); 492a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 493a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 494a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Periodically check for thread suspension. 495a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 496a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * While we're at it, see if a debugger has attached or the profiler has 4979a3147c7412f4794434b4c2604aa2ba784867774buzbee * started. 498a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 4999a3147c7412f4794434b4c2604aa2ba784867774buzbee#define PERIODIC_CHECKS(_pcadj) { \ 500a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (dvmCheckSuspendQuick(self)) { \ 501a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); /* need for precise GC */ \ 502a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden dvmCheckSuspendPending(self); \ 503a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 504a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } 505a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 506cd8f5e701547739f241594b43e9470c92d98e9cfCarl Shapiro/* File: c/opcommon.cpp */ 507a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* forward declarations of goto targets */ 508ab35b50311951feea3782151dd5422ee944685c2Elliott HughesGOTO_TARGET_DECL(filledNewArray, bool methodCallRange); 509ab35b50311951feea3782151dd5422ee944685c2Elliott HughesGOTO_TARGET_DECL(invokeVirtual, bool methodCallRange); 510ab35b50311951feea3782151dd5422ee944685c2Elliott HughesGOTO_TARGET_DECL(invokeSuper, bool methodCallRange); 511ab35b50311951feea3782151dd5422ee944685c2Elliott HughesGOTO_TARGET_DECL(invokeInterface, bool methodCallRange); 512ab35b50311951feea3782151dd5422ee944685c2Elliott HughesGOTO_TARGET_DECL(invokeDirect, bool methodCallRange); 513ab35b50311951feea3782151dd5422ee944685c2Elliott HughesGOTO_TARGET_DECL(invokeStatic, bool methodCallRange); 514ab35b50311951feea3782151dd5422ee944685c2Elliott HughesGOTO_TARGET_DECL(invokeVirtualQuick, bool methodCallRange); 515ab35b50311951feea3782151dd5422ee944685c2Elliott HughesGOTO_TARGET_DECL(invokeSuperQuick, bool methodCallRange); 516a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenGOTO_TARGET_DECL(invokeMethod, bool methodCallRange, const Method* methodToCall, 517a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 count, u2 regs); 518a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenGOTO_TARGET_DECL(returnFromMethod); 519a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenGOTO_TARGET_DECL(exceptionThrown); 520a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 521a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 522a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * =========================================================================== 523a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 524a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * What follows are opcode definitions shared between multiple opcodes with 525a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * minor substitutions handled by the C pre-processor. These should probably 526a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * use the mterp substitution mechanism instead, with the code here moved 527a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * into common fragment files (like the asm "binop.S"), although it's hard 528a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * to give up the C preprocessor in favor of the much simpler text subst. 529a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 530a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * =========================================================================== 531a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 532a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 533a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_NUMCONV(_opcode, _opname, _fromtype, _totype) \ 534a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB*/) \ 535a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 536a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); \ 537a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \ 538a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER##_totype(vdst, \ 539a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GET_REGISTER##_fromtype(vsrc1)); \ 540a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(1); 541a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 542a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_FLOAT_TO_INT(_opcode, _opname, _fromvtype, _fromrtype, \ 543a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden _tovtype, _tortype) \ 544a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB*/) \ 545a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 546a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden /* spec defines specific handling for +/- inf and NaN values */ \ 547a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden _fromvtype val; \ 548a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden _tovtype intMin, intMax, result; \ 549a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 550a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); \ 551a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \ 552a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden val = GET_REGISTER##_fromrtype(vsrc1); \ 553a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden intMin = (_tovtype) 1 << (sizeof(_tovtype) * 8 -1); \ 554a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden intMax = ~intMin; \ 555a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = (_tovtype) val; \ 556a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (val >= intMax) /* +inf */ \ 557a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = intMax; \ 558a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else if (val <= intMin) /* -inf */ \ 559a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = intMin; \ 560a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else if (val != val) /* NaN */ \ 561a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = 0; \ 562a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else \ 563a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = (_tovtype) val; \ 564a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER##_tortype(vdst, result); \ 565a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 566a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(1); 567a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 568a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_INT_TO_SMALL(_opcode, _opname, _type) \ 569a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB*/) \ 570a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 571a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); \ 572a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|int-to-%s v%d,v%d", (_opname), vdst, vsrc1); \ 573a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, (_type) GET_REGISTER(vsrc1)); \ 574a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(1); 575a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 576a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* NOTE: the comparison result is always a signed 4-byte integer */ 577a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_CMPX(_opcode, _opname, _varType, _type, _nanVal) \ 578a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ 579a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 580a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden int result; \ 581a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 regs; \ 582a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden _varType val1, val2; \ 583a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); \ 584a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden regs = FETCH(1); \ 585a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = regs & 0xff; \ 586a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = regs >> 8; \ 587a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|cmp%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ 588a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden val1 = GET_REGISTER##_type(vsrc1); \ 589a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden val2 = GET_REGISTER##_type(vsrc2); \ 590a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (val1 == val2) \ 591a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = 0; \ 592a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else if (val1 < val2) \ 593a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = -1; \ 594a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else if (val1 > val2) \ 595a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = 1; \ 596a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else \ 597a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = (_nanVal); \ 59860fc806b679a3655c228b4093058c59941a49cfeDan Bornstein ILOGV("+ result=%d", result); \ 599a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, result); \ 600a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 601a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 602a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 603a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_IF_XX(_opcode, _opname, _cmp) \ 604a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB, +CCCC*/) \ 605a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_A(inst); \ 606a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = INST_B(inst); \ 607a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if ((s4) GET_REGISTER(vsrc1) _cmp (s4) GET_REGISTER(vsrc2)) { \ 608a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden int branchOffset = (s2)FETCH(1); /* sign-extended */ \ 609a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|if-%s v%d,v%d,+0x%04x", (_opname), vsrc1, vsrc2, \ 610a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden branchOffset); \ 611a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("> branch taken"); \ 612a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (branchOffset < 0) \ 6139a3147c7412f4794434b4c2604aa2ba784867774buzbee PERIODIC_CHECKS(branchOffset); \ 614a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(branchOffset); \ 615a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 616a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|if-%s v%d,v%d,-", (_opname), vsrc1, vsrc2); \ 617a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); \ 618a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } 619a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 620a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_IF_XXZ(_opcode, _opname, _cmp) \ 621a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, +BBBB*/) \ 622a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_AA(inst); \ 623a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if ((s4) GET_REGISTER(vsrc1) _cmp 0) { \ 624a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden int branchOffset = (s2)FETCH(1); /* sign-extended */ \ 625a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|if-%s v%d,+0x%04x", (_opname), vsrc1, branchOffset); \ 626a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("> branch taken"); \ 627a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (branchOffset < 0) \ 6289a3147c7412f4794434b4c2604aa2ba784867774buzbee PERIODIC_CHECKS(branchOffset); \ 629a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(branchOffset); \ 630a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 631a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|if-%s v%d,-", (_opname), vsrc1); \ 632a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); \ 633a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } 634a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 635a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_UNOP(_opcode, _opname, _pfx, _sfx, _type) \ 636a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB*/) \ 637a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 638a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); \ 639a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s v%d,v%d", (_opname), vdst, vsrc1); \ 640a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER##_type(vdst, _pfx GET_REGISTER##_type(vsrc1) _sfx); \ 641a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(1); 642a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 643a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_INT(_opcode, _opname, _op, _chkdiv) \ 644a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ 645a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 646a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 srcRegs; \ 647a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); \ 648a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden srcRegs = FETCH(1); \ 649a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = srcRegs & 0xff; \ 650a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = srcRegs >> 8; \ 651a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-int v%d,v%d", (_opname), vdst, vsrc1); \ 652a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (_chkdiv != 0) { \ 653a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden s4 firstVal, secondVal, result; \ 654a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden firstVal = GET_REGISTER(vsrc1); \ 655a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden secondVal = GET_REGISTER(vsrc2); \ 656a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (secondVal == 0) { \ 657a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); \ 658d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein dvmThrowArithmeticException("divide by zero"); \ 659a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 660a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 661a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if ((u4)firstVal == 0x80000000 && secondVal == -1) { \ 662a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (_chkdiv == 1) \ 663a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = firstVal; /* division */ \ 664a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else \ 665a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = 0; /* remainder */ \ 666a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 667a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = firstVal _op secondVal; \ 668a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 669a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, result); \ 670a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 671a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden /* non-div/rem case */ \ 672a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, \ 673a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (s4) GET_REGISTER(vsrc1) _op (s4) GET_REGISTER(vsrc2)); \ 674a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 675a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 676a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 677a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 678a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_SHX_INT(_opcode, _opname, _cast, _op) \ 679a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ 680a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 681a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 srcRegs; \ 682a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); \ 683a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden srcRegs = FETCH(1); \ 684a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = srcRegs & 0xff; \ 685a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = srcRegs >> 8; \ 686a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-int v%d,v%d", (_opname), vdst, vsrc1); \ 687a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, \ 688a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden _cast GET_REGISTER(vsrc1) _op (GET_REGISTER(vsrc2) & 0x1f)); \ 689a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 690a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 691a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 692a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_INT_LIT16(_opcode, _opname, _op, _chkdiv) \ 693a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB, #+CCCC*/) \ 694a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 695a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); \ 696a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = FETCH(1); \ 697a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-int/lit16 v%d,v%d,#+0x%04x", \ 698a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (_opname), vdst, vsrc1, vsrc2); \ 699a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (_chkdiv != 0) { \ 700a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden s4 firstVal, result; \ 701a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden firstVal = GET_REGISTER(vsrc1); \ 702a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if ((s2) vsrc2 == 0) { \ 703a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); \ 704d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein dvmThrowArithmeticException("divide by zero"); \ 705d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein GOTO_exceptionThrown(); \ 706a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 707a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if ((u4)firstVal == 0x80000000 && ((s2) vsrc2) == -1) { \ 708a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden /* won't generate /lit16 instr for this; check anyway */ \ 709a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (_chkdiv == 1) \ 710a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = firstVal; /* division */ \ 711a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else \ 712a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = 0; /* remainder */ \ 713a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 714a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = firstVal _op (s2) vsrc2; \ 715a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 716a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, result); \ 717a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 718a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden /* non-div/rem case */ \ 719a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, GET_REGISTER(vsrc1) _op (s2) vsrc2); \ 720a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 721a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 722a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 723a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_INT_LIT8(_opcode, _opname, _op, _chkdiv) \ 724a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, vBB, #+CC*/) \ 725a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 726a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 litInfo; \ 727a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); \ 728a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden litInfo = FETCH(1); \ 729a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = litInfo & 0xff; \ 730a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = litInfo >> 8; /* constant */ \ 731a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", \ 732a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (_opname), vdst, vsrc1, vsrc2); \ 733a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (_chkdiv != 0) { \ 734a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden s4 firstVal, result; \ 735a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden firstVal = GET_REGISTER(vsrc1); \ 736a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if ((s1) vsrc2 == 0) { \ 737a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); \ 738d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein dvmThrowArithmeticException("divide by zero"); \ 739a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 740a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 741a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if ((u4)firstVal == 0x80000000 && ((s1) vsrc2) == -1) { \ 742a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (_chkdiv == 1) \ 743a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = firstVal; /* division */ \ 744a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else \ 745a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = 0; /* remainder */ \ 746a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 747a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = firstVal _op ((s1) vsrc2); \ 748a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 749a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, result); \ 750a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 751a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, \ 752a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (s4) GET_REGISTER(vsrc1) _op (s1) vsrc2); \ 753a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 754a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 755a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 756a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 757a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_SHX_INT_LIT8(_opcode, _opname, _cast, _op) \ 758a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, vBB, #+CC*/) \ 759a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 760a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 litInfo; \ 761a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); \ 762a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden litInfo = FETCH(1); \ 763a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = litInfo & 0xff; \ 764a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = litInfo >> 8; /* constant */ \ 765a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-int/lit8 v%d,v%d,#+0x%02x", \ 766a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (_opname), vdst, vsrc1, vsrc2); \ 767a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, \ 768a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden _cast GET_REGISTER(vsrc1) _op (vsrc2 & 0x1f)); \ 769a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 770a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 771a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 772a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_INT_2ADDR(_opcode, _opname, _op, _chkdiv) \ 773a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB*/) \ 774a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 775a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); \ 776a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-int-2addr v%d,v%d", (_opname), vdst, vsrc1); \ 777a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (_chkdiv != 0) { \ 778a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden s4 firstVal, secondVal, result; \ 779a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden firstVal = GET_REGISTER(vdst); \ 780a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden secondVal = GET_REGISTER(vsrc1); \ 781a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (secondVal == 0) { \ 782a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); \ 783d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein dvmThrowArithmeticException("divide by zero"); \ 784a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 785a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 786a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if ((u4)firstVal == 0x80000000 && secondVal == -1) { \ 787a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (_chkdiv == 1) \ 788a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = firstVal; /* division */ \ 789a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else \ 790a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = 0; /* remainder */ \ 791a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 792a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = firstVal _op secondVal; \ 793a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 794a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, result); \ 795a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 796a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, \ 797a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (s4) GET_REGISTER(vdst) _op (s4) GET_REGISTER(vsrc1)); \ 798a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 799a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(1); 800a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 801a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_SHX_INT_2ADDR(_opcode, _opname, _cast, _op) \ 802a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB*/) \ 803a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 804a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); \ 805a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-int-2addr v%d,v%d", (_opname), vdst, vsrc1); \ 806a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER(vdst, \ 807a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden _cast GET_REGISTER(vdst) _op (GET_REGISTER(vsrc1) & 0x1f)); \ 808a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(1); 809a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 810a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_LONG(_opcode, _opname, _op, _chkdiv) \ 811a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ 812a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 813a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 srcRegs; \ 814a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); \ 815a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden srcRegs = FETCH(1); \ 816a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = srcRegs & 0xff; \ 817a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = srcRegs >> 8; \ 818a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-long v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ 819a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (_chkdiv != 0) { \ 820a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden s8 firstVal, secondVal, result; \ 821a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden firstVal = GET_REGISTER_WIDE(vsrc1); \ 822a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden secondVal = GET_REGISTER_WIDE(vsrc2); \ 823a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (secondVal == 0LL) { \ 824a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); \ 825d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein dvmThrowArithmeticException("divide by zero"); \ 826a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 827a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 828a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if ((u8)firstVal == 0x8000000000000000ULL && \ 829a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden secondVal == -1LL) \ 830a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 831a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (_chkdiv == 1) \ 832a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = firstVal; /* division */ \ 833a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else \ 834a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = 0; /* remainder */ \ 835a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 836a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = firstVal _op secondVal; \ 837a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 838a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER_WIDE(vdst, result); \ 839a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 840a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER_WIDE(vdst, \ 841a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (s8) GET_REGISTER_WIDE(vsrc1) _op (s8) GET_REGISTER_WIDE(vsrc2)); \ 842a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 843a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 844a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 845a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 846a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_SHX_LONG(_opcode, _opname, _cast, _op) \ 847a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ 848a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 849a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 srcRegs; \ 850a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); \ 851a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden srcRegs = FETCH(1); \ 852a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = srcRegs & 0xff; \ 853a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = srcRegs >> 8; \ 854a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-long v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ 855a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER_WIDE(vdst, \ 856a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden _cast GET_REGISTER_WIDE(vsrc1) _op (GET_REGISTER(vsrc2) & 0x3f)); \ 857a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 858a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 859a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 860a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_LONG_2ADDR(_opcode, _opname, _op, _chkdiv) \ 861a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB*/) \ 862a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 863a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); \ 864a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-long-2addr v%d,v%d", (_opname), vdst, vsrc1); \ 865a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (_chkdiv != 0) { \ 866a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden s8 firstVal, secondVal, result; \ 867a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden firstVal = GET_REGISTER_WIDE(vdst); \ 868a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden secondVal = GET_REGISTER_WIDE(vsrc1); \ 869a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (secondVal == 0LL) { \ 870a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); \ 871d27f3cf3e7b373487f39e035fc4b55168d55c454Dan Bornstein dvmThrowArithmeticException("divide by zero"); \ 872a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 873a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 874a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if ((u8)firstVal == 0x8000000000000000ULL && \ 875a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden secondVal == -1LL) \ 876a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 877a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (_chkdiv == 1) \ 878a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = firstVal; /* division */ \ 879a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden else \ 880a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = 0; /* remainder */ \ 881a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 882a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden result = firstVal _op secondVal; \ 883a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 884a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER_WIDE(vdst, result); \ 885a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } else { \ 886a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER_WIDE(vdst, \ 887a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (s8) GET_REGISTER_WIDE(vdst) _op (s8)GET_REGISTER_WIDE(vsrc1));\ 888a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 889a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(1); 890a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 891a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_SHX_LONG_2ADDR(_opcode, _opname, _cast, _op) \ 892a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB*/) \ 893a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 894a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); \ 895a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-long-2addr v%d,v%d", (_opname), vdst, vsrc1); \ 896a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER_WIDE(vdst, \ 897a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden _cast GET_REGISTER_WIDE(vdst) _op (GET_REGISTER(vsrc1) & 0x3f)); \ 898a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(1); 899a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 900a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_FLOAT(_opcode, _opname, _op) \ 901a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ 902a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 903a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 srcRegs; \ 904a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); \ 905a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden srcRegs = FETCH(1); \ 906a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = srcRegs & 0xff; \ 907a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = srcRegs >> 8; \ 908a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-float v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ 909a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER_FLOAT(vdst, \ 910a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GET_REGISTER_FLOAT(vsrc1) _op GET_REGISTER_FLOAT(vsrc2)); \ 911a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 912a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 913a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 914a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_DOUBLE(_opcode, _opname, _op) \ 915a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ 916a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 917a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 srcRegs; \ 918a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); \ 919a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden srcRegs = FETCH(1); \ 920a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = srcRegs & 0xff; \ 921a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = srcRegs >> 8; \ 922a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-double v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ 923a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER_DOUBLE(vdst, \ 924a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GET_REGISTER_DOUBLE(vsrc1) _op GET_REGISTER_DOUBLE(vsrc2)); \ 925a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 926a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 927a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 928a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_FLOAT_2ADDR(_opcode, _opname, _op) \ 929a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB*/) \ 930a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 931a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); \ 932a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-float-2addr v%d,v%d", (_opname), vdst, vsrc1); \ 933a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER_FLOAT(vdst, \ 934a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GET_REGISTER_FLOAT(vdst) _op GET_REGISTER_FLOAT(vsrc1)); \ 935a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(1); 936a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 937a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_X_DOUBLE_2ADDR(_opcode, _opname, _op) \ 938a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB*/) \ 939a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 940a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); \ 941a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|%s-double-2addr v%d,v%d", (_opname), vdst, vsrc1); \ 942a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER_DOUBLE(vdst, \ 943a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GET_REGISTER_DOUBLE(vdst) _op GET_REGISTER_DOUBLE(vsrc1)); \ 944a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(1); 945a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 946a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_AGET(_opcode, _opname, _type, _regsize) \ 947a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ 948a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 949a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ArrayObject* arrayObj; \ 950a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 arrayInfo; \ 951a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); \ 952a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); \ 953a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden arrayInfo = FETCH(1); \ 954a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = arrayInfo & 0xff; /* array ptr */ \ 955a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = arrayInfo >> 8; /* index */ \ 956a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|aget%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ 957a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden arrayObj = (ArrayObject*) GET_REGISTER(vsrc1); \ 958a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (!checkForNull((Object*) arrayObj)) \ 959a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 960a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (GET_REGISTER(vsrc2) >= arrayObj->length) { \ 96174501e600dcb5634aa26aee0a3f57f2b45b213f2Dan Bornstein dvmThrowArrayIndexOutOfBoundsException( \ 96247f58250c5177adba475b0b11a36151ac0ce9ab9Dan Bornstein arrayObj->length, GET_REGISTER(vsrc2)); \ 963a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 964a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 965a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER##_regsize(vdst, \ 966cd8f5e701547739f241594b43e9470c92d98e9cfCarl Shapiro ((_type*)(void*)arrayObj->contents)[GET_REGISTER(vsrc2)]); \ 967291c84f60853d30e1c0d79dd08c5e5164f588e26Dan Bornstein ILOGV("+ AGET[%d]=%#x", GET_REGISTER(vsrc2), GET_REGISTER(vdst)); \ 968a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 969a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 970a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 971a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_OP_APUT(_opcode, _opname, _type, _regsize) \ 972a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, vBB, vCC*/) \ 973a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 974a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ArrayObject* arrayObj; \ 975a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden u2 arrayInfo; \ 976a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); \ 977a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); /* AA: source value */ \ 978a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden arrayInfo = FETCH(1); \ 979a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = arrayInfo & 0xff; /* BB: array ptr */ \ 980a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc2 = arrayInfo >> 8; /* CC: index */ \ 981a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|aput%s v%d,v%d,v%d", (_opname), vdst, vsrc1, vsrc2); \ 982a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden arrayObj = (ArrayObject*) GET_REGISTER(vsrc1); \ 983a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (!checkForNull((Object*) arrayObj)) \ 984a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 985a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (GET_REGISTER(vsrc2) >= arrayObj->length) { \ 98674501e600dcb5634aa26aee0a3f57f2b45b213f2Dan Bornstein dvmThrowArrayIndexOutOfBoundsException( \ 98747f58250c5177adba475b0b11a36151ac0ce9ab9Dan Bornstein arrayObj->length, GET_REGISTER(vsrc2)); \ 988a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 989a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 990a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("+ APUT[%d]=0x%08x", GET_REGISTER(vsrc2), GET_REGISTER(vdst));\ 991cd8f5e701547739f241594b43e9470c92d98e9cfCarl Shapiro ((_type*)(void*)arrayObj->contents)[GET_REGISTER(vsrc2)] = \ 992a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GET_REGISTER##_regsize(vdst); \ 993a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 994a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 995a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 996a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 997a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * It's possible to get a bad value out of a field with sub-32-bit stores 998a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * because the -quick versions always operate on 32 bits. Consider: 999a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * short foo = -1 (sets a 32-bit register to 0xffffffff) 1000a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * iput-quick foo (writes all 32 bits to the field) 1001a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * short bar = 1 (sets a 32-bit register to 0x00000001) 1002a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * iput-short (writes the low 16 bits to the field) 1003a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * iget-quick foo (reads all 32 bits from the field, yielding 0xffff0001) 1004a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * This can only happen when optimized and non-optimized code has interleaved 1005a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * access to the same field. This is unlikely but possible. 1006a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 1007a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * The easiest way to fix this is to always read/write 32 bits at a time. On 1008a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * a device with a 16-bit data bus this is sub-optimal. (The alternative 1009a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * approach is to have sub-int versions of iget-quick, but now we're wasting 1010a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Dalvik instruction space and making it less likely that handler code will 1011a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * already be in the CPU i-cache.) 1012a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 1013a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_IGET_X(_opcode, _opname, _ftype, _regsize) \ 1014a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \ 1015a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 1016a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden InstField* ifield; \ 1017a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden Object* obj; \ 1018a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); \ 1019a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 1020a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); /* object ptr */ \ 1021a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ref = FETCH(1); /* field ref */ \ 1022a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|iget%s v%d,v%d,field@0x%04x", (_opname), vdst, vsrc1, ref); \ 1023a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden obj = (Object*) GET_REGISTER(vsrc1); \ 1024a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (!checkForNull(obj)) \ 1025a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 1026a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref); \ 1027a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (ifield == NULL) { \ 1028a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ifield = dvmResolveInstField(curMethod->clazz, ref); \ 1029a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (ifield == NULL) \ 1030a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 1031a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 1032a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER##_regsize(vdst, \ 1033a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden dvmGetField##_ftype(obj, ifield->byteOffset)); \ 1034a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("+ IGET '%s'=0x%08llx", ifield->field.name, \ 1035a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (u8) GET_REGISTER##_regsize(vdst)); \ 1036a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 1037a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 1038a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1039a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_IGET_X_QUICK(_opcode, _opname, _ftype, _regsize) \ 1040a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \ 1041a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 1042a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden Object* obj; \ 1043a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 1044a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); /* object ptr */ \ 1045a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ref = FETCH(1); /* field offset */ \ 1046a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|iget%s-quick v%d,v%d,field@+%u", \ 1047a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (_opname), vdst, vsrc1, ref); \ 1048a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden obj = (Object*) GET_REGISTER(vsrc1); \ 1049a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (!checkForNullExportPC(obj, fp, pc)) \ 1050a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 1051a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER##_regsize(vdst, dvmGetField##_ftype(obj, ref)); \ 1052a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("+ IGETQ %d=0x%08llx", ref, \ 1053a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (u8) GET_REGISTER##_regsize(vdst)); \ 1054a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 1055a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 1056a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1057a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_IPUT_X(_opcode, _opname, _ftype, _regsize) \ 1058a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \ 1059a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 1060a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden InstField* ifield; \ 1061a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden Object* obj; \ 1062a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); \ 1063a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 1064a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); /* object ptr */ \ 1065a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ref = FETCH(1); /* field ref */ \ 1066a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|iput%s v%d,v%d,field@0x%04x", (_opname), vdst, vsrc1, ref); \ 1067a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden obj = (Object*) GET_REGISTER(vsrc1); \ 1068a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (!checkForNull(obj)) \ 1069a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 1070a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ifield = (InstField*) dvmDexGetResolvedField(methodClassDex, ref); \ 1071a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (ifield == NULL) { \ 1072a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ifield = dvmResolveInstField(curMethod->clazz, ref); \ 1073a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (ifield == NULL) \ 1074a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 1075a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 1076a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden dvmSetField##_ftype(obj, ifield->byteOffset, \ 1077a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GET_REGISTER##_regsize(vdst)); \ 1078a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("+ IPUT '%s'=0x%08llx", ifield->field.name, \ 1079a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (u8) GET_REGISTER##_regsize(vdst)); \ 1080a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 1081a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 1082a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1083a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_IPUT_X_QUICK(_opcode, _opname, _ftype, _regsize) \ 1084a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vA, vB, field@CCCC*/) \ 1085a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 1086a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden Object* obj; \ 1087a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_A(inst); \ 1088a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vsrc1 = INST_B(inst); /* object ptr */ \ 1089a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ref = FETCH(1); /* field offset */ \ 1090a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|iput%s-quick v%d,v%d,field@0x%04x", \ 1091a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (_opname), vdst, vsrc1, ref); \ 1092a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden obj = (Object*) GET_REGISTER(vsrc1); \ 1093a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (!checkForNullExportPC(obj, fp, pc)) \ 1094a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 1095a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden dvmSetField##_ftype(obj, ref, GET_REGISTER##_regsize(vdst)); \ 1096a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("+ IPUTQ %d=0x%08llx", ref, \ 1097a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (u8) GET_REGISTER##_regsize(vdst)); \ 1098a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 1099a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 1100a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1101dd6e87095071e4e987910732062545f7303023e5Ben Cheng/* 1102dd6e87095071e4e987910732062545f7303023e5Ben Cheng * The JIT needs dvmDexGetResolvedField() to return non-null. 11039a3147c7412f4794434b4c2604aa2ba784867774buzbee * Because the portable interpreter is not involved with the JIT 11049a3147c7412f4794434b4c2604aa2ba784867774buzbee * and trace building, we only need the extra check here when this 11059a3147c7412f4794434b4c2604aa2ba784867774buzbee * code is massaged into a stub called from an assembly interpreter. 11069a3147c7412f4794434b4c2604aa2ba784867774buzbee * This is controlled by the JIT_STUB_HACK maco. 1107dd6e87095071e4e987910732062545f7303023e5Ben Cheng */ 11089a3147c7412f4794434b4c2604aa2ba784867774buzbee 1109a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_SGET_X(_opcode, _opname, _ftype, _regsize) \ 1110a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, field@BBBB*/) \ 1111a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 1112a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden StaticField* sfield; \ 1113a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); \ 1114a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ref = FETCH(1); /* field ref */ \ 1115a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|sget%s v%d,sfield@0x%04x", (_opname), vdst, ref); \ 1116a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \ 1117a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (sfield == NULL) { \ 1118a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); \ 1119a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden sfield = dvmResolveStaticField(curMethod->clazz, ref); \ 1120a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (sfield == NULL) \ 1121a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 1122dd6e87095071e4e987910732062545f7303023e5Ben Cheng if (dvmDexGetResolvedField(methodClassDex, ref) == NULL) { \ 112360fc806b679a3655c228b4093058c59941a49cfeDan Bornstein JIT_STUB_HACK(dvmJitEndTraceSelect(self,pc)); \ 1124dd6e87095071e4e987910732062545f7303023e5Ben Cheng } \ 1125a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 1126a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden SET_REGISTER##_regsize(vdst, dvmGetStaticField##_ftype(sfield)); \ 1127a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("+ SGET '%s'=0x%08llx", \ 1128a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden sfield->field.name, (u8)GET_REGISTER##_regsize(vdst)); \ 1129a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 1130a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 1131a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1132a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#define HANDLE_SPUT_X(_opcode, _opname, _ftype, _regsize) \ 1133a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden HANDLE_OPCODE(_opcode /*vAA, field@BBBB*/) \ 1134a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden { \ 1135a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden StaticField* sfield; \ 1136a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden vdst = INST_AA(inst); \ 1137a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ref = FETCH(1); /* field ref */ \ 1138a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("|sput%s v%d,sfield@0x%04x", (_opname), vdst, ref); \ 1139a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden sfield = (StaticField*)dvmDexGetResolvedField(methodClassDex, ref); \ 1140a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (sfield == NULL) { \ 1141a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden EXPORT_PC(); \ 1142a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden sfield = dvmResolveStaticField(curMethod->clazz, ref); \ 1143a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden if (sfield == NULL) \ 1144a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden GOTO_exceptionThrown(); \ 1145dd6e87095071e4e987910732062545f7303023e5Ben Cheng if (dvmDexGetResolvedField(methodClassDex, ref) == NULL) { \ 114660fc806b679a3655c228b4093058c59941a49cfeDan Bornstein JIT_STUB_HACK(dvmJitEndTraceSelect(self,pc)); \ 1147dd6e87095071e4e987910732062545f7303023e5Ben Cheng } \ 1148a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 1149a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden dvmSetStaticField##_ftype(sfield, GET_REGISTER##_regsize(vdst)); \ 1150a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ILOGV("+ SPUT '%s'=0x%08llx", \ 1151a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden sfield->field.name, (u8)GET_REGISTER##_regsize(vdst)); \ 1152a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden } \ 1153a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden FINISH(2); 1154a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1155cd8f5e701547739f241594b43e9470c92d98e9cfCarl Shapiro/* File: cstubs/enddefs.cpp */ 1156a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1157a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* undefine "magic" name remapping */ 1158a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef retval 1159a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef pc 1160a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef fp 1161a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef curMethod 1162a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef methodClassDex 1163a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef self 1164a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#undef debugTrackedRefStart 1165a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1166cd8f5e701547739f241594b43e9470c92d98e9cfCarl Shapiro/* File: armv5te/debug.cpp */ 1167a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#include <inttypes.h> 1168a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1169a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 1170a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Dump the fixed-purpose ARM registers, along with some other info. 1171a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 1172a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * This function MUST be compiled in ARM mode -- THUMB will yield bogus 1173a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * results. 1174a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * 1175a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * This will NOT preserve r0-r3/ip. 1176a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 1177a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenvoid dvmMterpDumpArmRegs(uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3) 1178a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{ 117995b0899ad3412596baa600b22ea2ecd7dd1acc43Evgeniy Stepanov // TODO: Clang does not support asm declaration syntax. 118095b0899ad3412596baa600b22ea2ecd7dd1acc43Evgeniy Stepanov#ifndef __clang__ 1181a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden register uint32_t rPC asm("r4"); 1182a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden register uint32_t rFP asm("r5"); 11839f601a917c8878204482c37aec7005054b6776fabuzbee register uint32_t rSELF asm("r6"); 1184a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden register uint32_t rINST asm("r7"); 1185a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden register uint32_t rIBASE asm("r8"); 1186a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden register uint32_t r9 asm("r9"); 1187a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden register uint32_t r10 asm("r10"); 1188a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1189b31b30131bbf58280a515c40027aa958b81b5cd6Carl Shapiro //extern char dvmAsmInstructionStart[]; 1190a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1191a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden printf("REGS: r0=%08x r1=%08x r2=%08x r3=%08x\n", r0, r1, r2, r3); 11929f601a917c8878204482c37aec7005054b6776fabuzbee printf(" : rPC=%08x rFP=%08x rSELF=%08x rINST=%08x\n", 11939f601a917c8878204482c37aec7005054b6776fabuzbee rPC, rFP, rSELF, rINST); 1194a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden printf(" : rIBASE=%08x r9=%08x r10=%08x\n", rIBASE, r9, r10); 119595b0899ad3412596baa600b22ea2ecd7dd1acc43Evgeniy Stepanov#endif 1196a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 11979f601a917c8878204482c37aec7005054b6776fabuzbee //Thread* self = (Thread*) rSELF; 11989f601a917c8878204482c37aec7005054b6776fabuzbee //const Method* method = self->method; 1199a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden printf(" + self is %p\n", dvmThreadSelf()); 1200a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden //printf(" + currently in %s.%s %s\n", 1201be323ec573918ef1674e4883c8766ddc4ee2a10cJean-Baptiste Queru // method->clazz->descriptor, method->name, method->shorty); 1202a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden //printf(" + dvmAsmInstructionStart = %p\n", dvmAsmInstructionStart); 1203a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden //printf(" + next handler for 0x%02x = %p\n", 1204a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden // rINST & 0xff, dvmAsmInstructionStart + (rINST & 0xff) * 64); 1205a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden} 1206a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1207a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 1208a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Dump the StackSaveArea for the specified frame pointer. 1209a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 1210a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenvoid dvmDumpFp(void* fp, StackSaveArea* otherSaveArea) 1211a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{ 1212a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden StackSaveArea* saveArea = SAVEAREA_FROM_FP(fp); 1213a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden printf("StackSaveArea for fp %p [%p/%p]:\n", fp, saveArea, otherSaveArea); 1214a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#ifdef EASY_GDB 1215a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden printf(" prevSave=%p, prevFrame=%p savedPc=%p meth=%p curPc=%p\n", 1216a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden saveArea->prevSave, saveArea->prevFrame, saveArea->savedPc, 1217a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden saveArea->method, saveArea->xtra.currentPc); 1218a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#else 1219a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden printf(" prevFrame=%p savedPc=%p meth=%p curPc=%p fp[0]=0x%08x\n", 1220a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden saveArea->prevFrame, saveArea->savedPc, 1221a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden saveArea->method, saveArea->xtra.currentPc, 1222a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden *(u4*)fp); 1223a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden#endif 1224a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden} 1225a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1226a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden/* 1227a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * Does the bulk of the work for common_printMethod(). 1228a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 1229a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFaddenvoid dvmMterpPrintMethod(Method* method) 1230a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden{ 1231a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden /* 1232a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * It is a direct (non-virtual) method if it is static, private, 1233a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden * or a constructor. 1234a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden */ 1235a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden bool isDirect = 1236a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden ((method->accessFlags & (ACC_STATIC|ACC_PRIVATE)) != 0) || 1237a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden (method->name[0] == '<'); 1238a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1239a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden char* desc = dexProtoCopyMethodDescriptor(&method->prototype); 1240a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1241a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden printf("<%c:%s.%s %s> ", 1242a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden isDirect ? 'D' : 'V', 1243a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden method->clazz->descriptor, 1244a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden method->name, 1245a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden desc); 1246a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1247a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden free(desc); 1248a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden} 1249a5069fb7eb2da846ff1fc2c903ebd8ce9fa3647fAndy McFadden 1250