2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Dalvik opcode enumeration.
20 #ifndef _LIBDEX_OPCODE
21 #define _LIBDEX_OPCODE
24 * If you add, delete, or renumber instructions, you need to change things
25 * in various places. Renumbering really only affects the "unused" opcodes,
26 * which are given explicit enumeration values to make it easier to find
27 * the places in the code that need to be updated when making changes --
28 * if you replace "OP_UNUSED_2D" and neglect to update a switch statement,
29 * the compiler will complain about an unknown value.
31 * Opcode definitions and attributes:
32 * - update the OpCode enum below
33 * - update the "goto table" definition macro, DEFINE_GOTO_TABLE(), below
34 * - update the instruction info table generators and (if you changed an
35 * instruction format) instruction decoder in InstrUtils.c
36 * - update the instruction format list in InstrUtils.h, if necessary
37 * - update the parallel definitions in the class dalvik.bytecode.Opcodes
40 * - implement/update the instruction in C in mterp/c/...
41 * - verify new code by running with "dalvik.vm.execution-mode =
42 * int:portable" or "-Xint:portable"
43 * - implement/update the instruction in ARM in mterp/armv5/...
44 * - verify by enabling ARM handler for that instruction in mterp config
45 * and running int:fast as above
46 * - repeat for other platforms (x86, ...)
47 * (see notes in mterp/ReadMe.txt for rebuilding instructions)
49 * Verifier / optimizer:
50 * - update some stuff in analysis/DexOptimize.c, analysis/DexVerify.c,
51 * and/or analysis/CodeVerify.c as needed
52 * - verify by running with verifier enabled (it's on by default)
55 * - update the OpCodeNames table in dexdump/OpCodeNames.c
56 * - update dexdump/DexDump.c if an instruction format has changed
58 * Note: The Dalvik VM tests (in the tests subdirectory) provide a convenient
59 * way to test most of the above without doing any rebuilds. In particular,
60 * test 003-omnibus-opcodes will exercise most of the opcodes.
70 OP_MOVE_FROM16 = 0x02,
73 OP_MOVE_WIDE_FROM16 = 0x05,
74 OP_MOVE_WIDE_16 = 0x06,
75 OP_MOVE_OBJECT = 0x07,
76 OP_MOVE_OBJECT_FROM16 = 0x08,
77 OP_MOVE_OBJECT_16 = 0x09,
79 OP_MOVE_RESULT = 0x0a,
80 OP_MOVE_RESULT_WIDE = 0x0b,
81 OP_MOVE_RESULT_OBJECT = 0x0c,
82 OP_MOVE_EXCEPTION = 0x0d,
84 OP_RETURN_VOID = 0x0e,
86 OP_RETURN_WIDE = 0x10,
87 OP_RETURN_OBJECT = 0x11,
92 OP_CONST_HIGH16 = 0x15,
93 OP_CONST_WIDE_16 = 0x16,
94 OP_CONST_WIDE_32 = 0x17,
96 OP_CONST_WIDE_HIGH16 = 0x19,
97 OP_CONST_STRING = 0x1a,
98 OP_CONST_STRING_JUMBO = 0x1b,
99 OP_CONST_CLASS = 0x1c,
101 OP_MONITOR_ENTER = 0x1d,
102 OP_MONITOR_EXIT = 0x1e,
104 OP_CHECK_CAST = 0x1f,
105 OP_INSTANCE_OF = 0x20,
107 OP_ARRAY_LENGTH = 0x21,
109 OP_NEW_INSTANCE = 0x22,
112 OP_FILLED_NEW_ARRAY = 0x24,
113 OP_FILLED_NEW_ARRAY_RANGE = 0x25,
114 OP_FILL_ARRAY_DATA = 0x26,
120 OP_PACKED_SWITCH = 0x2b,
121 OP_SPARSE_SWITCH = 0x2c,
123 OP_CMPL_FLOAT = 0x2d,
124 OP_CMPG_FLOAT = 0x2e,
125 OP_CMPL_DOUBLE = 0x2f,
126 OP_CMPG_DOUBLE = 0x30,
151 OP_AGET_OBJECT = 0x46,
152 OP_AGET_BOOLEAN = 0x47,
155 OP_AGET_SHORT = 0x4a,
158 OP_APUT_OBJECT = 0x4d,
159 OP_APUT_BOOLEAN = 0x4e,
162 OP_APUT_SHORT = 0x51,
166 OP_IGET_OBJECT = 0x54,
167 OP_IGET_BOOLEAN = 0x55,
170 OP_IGET_SHORT = 0x58,
173 OP_IPUT_OBJECT = 0x5b,
174 OP_IPUT_BOOLEAN = 0x5c,
177 OP_IPUT_SHORT = 0x5f,
181 OP_SGET_OBJECT = 0x62,
182 OP_SGET_BOOLEAN = 0x63,
185 OP_SGET_SHORT = 0x66,
188 OP_SPUT_OBJECT = 0x69,
189 OP_SPUT_BOOLEAN = 0x6a,
192 OP_SPUT_SHORT = 0x6d,
194 OP_INVOKE_VIRTUAL = 0x6e,
195 OP_INVOKE_SUPER = 0x6f,
196 OP_INVOKE_DIRECT = 0x70,
197 OP_INVOKE_STATIC = 0x71,
198 OP_INVOKE_INTERFACE = 0x72,
202 OP_INVOKE_VIRTUAL_RANGE = 0x74,
203 OP_INVOKE_SUPER_RANGE = 0x75,
204 OP_INVOKE_DIRECT_RANGE = 0x76,
205 OP_INVOKE_STATIC_RANGE = 0x77,
206 OP_INVOKE_INTERFACE_RANGE = 0x78,
216 OP_NEG_DOUBLE = 0x80,
217 OP_INT_TO_LONG = 0x81,
218 OP_INT_TO_FLOAT = 0x82,
219 OP_INT_TO_DOUBLE = 0x83,
220 OP_LONG_TO_INT = 0x84,
221 OP_LONG_TO_FLOAT = 0x85,
222 OP_LONG_TO_DOUBLE = 0x86,
223 OP_FLOAT_TO_INT = 0x87,
224 OP_FLOAT_TO_LONG = 0x88,
225 OP_FLOAT_TO_DOUBLE = 0x89,
226 OP_DOUBLE_TO_INT = 0x8a,
227 OP_DOUBLE_TO_LONG = 0x8b,
228 OP_DOUBLE_TO_FLOAT = 0x8c,
229 OP_INT_TO_BYTE = 0x8d,
230 OP_INT_TO_CHAR = 0x8e,
231 OP_INT_TO_SHORT = 0x8f,
262 OP_ADD_DOUBLE = 0xab,
263 OP_SUB_DOUBLE = 0xac,
264 OP_MUL_DOUBLE = 0xad,
265 OP_DIV_DOUBLE = 0xae,
266 OP_REM_DOUBLE = 0xaf,
268 OP_ADD_INT_2ADDR = 0xb0,
269 OP_SUB_INT_2ADDR = 0xb1,
270 OP_MUL_INT_2ADDR = 0xb2,
271 OP_DIV_INT_2ADDR = 0xb3,
272 OP_REM_INT_2ADDR = 0xb4,
273 OP_AND_INT_2ADDR = 0xb5,
274 OP_OR_INT_2ADDR = 0xb6,
275 OP_XOR_INT_2ADDR = 0xb7,
276 OP_SHL_INT_2ADDR = 0xb8,
277 OP_SHR_INT_2ADDR = 0xb9,
278 OP_USHR_INT_2ADDR = 0xba,
280 OP_ADD_LONG_2ADDR = 0xbb,
281 OP_SUB_LONG_2ADDR = 0xbc,
282 OP_MUL_LONG_2ADDR = 0xbd,
283 OP_DIV_LONG_2ADDR = 0xbe,
284 OP_REM_LONG_2ADDR = 0xbf,
285 OP_AND_LONG_2ADDR = 0xc0,
286 OP_OR_LONG_2ADDR = 0xc1,
287 OP_XOR_LONG_2ADDR = 0xc2,
288 OP_SHL_LONG_2ADDR = 0xc3,
289 OP_SHR_LONG_2ADDR = 0xc4,
290 OP_USHR_LONG_2ADDR = 0xc5,
292 OP_ADD_FLOAT_2ADDR = 0xc6,
293 OP_SUB_FLOAT_2ADDR = 0xc7,
294 OP_MUL_FLOAT_2ADDR = 0xc8,
295 OP_DIV_FLOAT_2ADDR = 0xc9,
296 OP_REM_FLOAT_2ADDR = 0xca,
297 OP_ADD_DOUBLE_2ADDR = 0xcb,
298 OP_SUB_DOUBLE_2ADDR = 0xcc,
299 OP_MUL_DOUBLE_2ADDR = 0xcd,
300 OP_DIV_DOUBLE_2ADDR = 0xce,
301 OP_REM_DOUBLE_2ADDR = 0xcf,
303 OP_ADD_INT_LIT16 = 0xd0,
304 OP_RSUB_INT = 0xd1, /* no _LIT16 suffix for this */
305 OP_MUL_INT_LIT16 = 0xd2,
306 OP_DIV_INT_LIT16 = 0xd3,
307 OP_REM_INT_LIT16 = 0xd4,
308 OP_AND_INT_LIT16 = 0xd5,
309 OP_OR_INT_LIT16 = 0xd6,
310 OP_XOR_INT_LIT16 = 0xd7,
312 OP_ADD_INT_LIT8 = 0xd8,
313 OP_RSUB_INT_LIT8 = 0xd9,
314 OP_MUL_INT_LIT8 = 0xda,
315 OP_DIV_INT_LIT8 = 0xdb,
316 OP_REM_INT_LIT8 = 0xdc,
317 OP_AND_INT_LIT8 = 0xdd,
318 OP_OR_INT_LIT8 = 0xde,
319 OP_XOR_INT_LIT8 = 0xdf,
320 OP_SHL_INT_LIT8 = 0xe0,
321 OP_SHR_INT_LIT8 = 0xe1,
322 OP_USHR_INT_LIT8 = 0xe2,
336 /* optimizer output -- these are never generated by "dx" */
337 OP_EXECUTE_INLINE = 0xee,
338 OP_UNUSED_EF = 0xef, /* OP_EXECUTE_INLINE_RANGE? */
340 OP_INVOKE_DIRECT_EMPTY = 0xf0,
341 OP_UNUSED_F1 = 0xf1, /* OP_INVOKE_DIRECT_EMPTY_RANGE? */
342 OP_IGET_QUICK = 0xf2,
343 OP_IGET_WIDE_QUICK = 0xf3,
344 OP_IGET_OBJECT_QUICK = 0xf4,
345 OP_IPUT_QUICK = 0xf5,
346 OP_IPUT_WIDE_QUICK = 0xf6,
347 OP_IPUT_OBJECT_QUICK = 0xf7,
349 OP_INVOKE_VIRTUAL_QUICK = 0xf8,
350 OP_INVOKE_VIRTUAL_QUICK_RANGE = 0xf9,
351 OP_INVOKE_SUPER_QUICK = 0xfa,
352 OP_INVOKE_SUPER_QUICK_RANGE = 0xfb,
353 OP_UNUSED_FC = 0xfc, /* OP_INVOKE_DIRECT_QUICK? */
354 OP_UNUSED_FD = 0xfd, /* OP_INVOKE_DIRECT_QUICK_RANGE? */
355 OP_UNUSED_FE = 0xfe, /* OP_INVOKE_INTERFACE_QUICK? */
356 OP_UNUSED_FF = 0xff, /* OP_INVOKE_INTERFACE_QUICK_RANGE*/
359 #define kNumDalvikInstructions 256
362 * Switch-statement signatures are a "NOP" followed by a code. (A true NOP
365 #define kPackedSwitchSignature 0x0100
366 #define kSparseSwitchSignature 0x0200
367 #define kArrayDataSignature 0x0300
370 * Macro used to generate computed goto tables for the C interpreter.
372 * The labels here must match up with the labels in the interpreter
373 * implementation. There is no direct connection between these and the
374 * numeric definitions above, but if the two get out of sync strange things
377 #define DEFINE_GOTO_TABLE(_name) \
378 static const void* _name[kNumDalvikInstructions] = { \
385 H(OP_MOVE_WIDE_FROM16), \
386 H(OP_MOVE_WIDE_16), \
388 H(OP_MOVE_OBJECT_FROM16), \
389 H(OP_MOVE_OBJECT_16), \
391 H(OP_MOVE_RESULT_WIDE), \
392 H(OP_MOVE_RESULT_OBJECT), \
393 H(OP_MOVE_EXCEPTION), \
398 H(OP_RETURN_OBJECT), \
402 H(OP_CONST_HIGH16), \
403 H(OP_CONST_WIDE_16), \
404 H(OP_CONST_WIDE_32), \
406 H(OP_CONST_WIDE_HIGH16), \
407 H(OP_CONST_STRING), \
408 H(OP_CONST_STRING_JUMBO), \
410 H(OP_MONITOR_ENTER), \
411 H(OP_MONITOR_EXIT), \
415 H(OP_ARRAY_LENGTH), \
416 H(OP_NEW_INSTANCE), \
418 H(OP_FILLED_NEW_ARRAY), \
419 H(OP_FILLED_NEW_ARRAY_RANGE), \
420 H(OP_FILL_ARRAY_DATA), \
425 H(OP_PACKED_SWITCH), \
426 H(OP_SPARSE_SWITCH), \
455 H(OP_AGET_BOOLEAN), \
462 H(OP_APUT_BOOLEAN), \
470 H(OP_IGET_BOOLEAN), \
477 H(OP_IPUT_BOOLEAN), \
485 H(OP_SGET_BOOLEAN), \
492 H(OP_SPUT_BOOLEAN), \
496 H(OP_INVOKE_VIRTUAL), \
497 H(OP_INVOKE_SUPER), \
499 H(OP_INVOKE_DIRECT), \
500 H(OP_INVOKE_STATIC), \
501 H(OP_INVOKE_INTERFACE), \
503 H(OP_INVOKE_VIRTUAL_RANGE), \
504 H(OP_INVOKE_SUPER_RANGE), \
505 H(OP_INVOKE_DIRECT_RANGE), \
506 H(OP_INVOKE_STATIC_RANGE), \
507 H(OP_INVOKE_INTERFACE_RANGE), \
518 H(OP_INT_TO_FLOAT), \
519 H(OP_INT_TO_DOUBLE), \
521 H(OP_LONG_TO_FLOAT), \
522 H(OP_LONG_TO_DOUBLE), \
523 H(OP_FLOAT_TO_INT), \
524 H(OP_FLOAT_TO_LONG), \
525 H(OP_FLOAT_TO_DOUBLE), \
526 H(OP_DOUBLE_TO_INT), \
527 H(OP_DOUBLE_TO_LONG), \
528 H(OP_DOUBLE_TO_FLOAT), \
531 H(OP_INT_TO_SHORT), \
567 H(OP_ADD_INT_2ADDR), \
568 H(OP_SUB_INT_2ADDR), \
569 H(OP_MUL_INT_2ADDR), \
570 H(OP_DIV_INT_2ADDR), \
571 H(OP_REM_INT_2ADDR), \
572 H(OP_AND_INT_2ADDR), \
573 H(OP_OR_INT_2ADDR), \
574 H(OP_XOR_INT_2ADDR), \
575 H(OP_SHL_INT_2ADDR), \
576 H(OP_SHR_INT_2ADDR), \
577 H(OP_USHR_INT_2ADDR), \
578 H(OP_ADD_LONG_2ADDR), \
579 H(OP_SUB_LONG_2ADDR), \
580 H(OP_MUL_LONG_2ADDR), \
581 H(OP_DIV_LONG_2ADDR), \
582 H(OP_REM_LONG_2ADDR), \
584 H(OP_AND_LONG_2ADDR), \
585 H(OP_OR_LONG_2ADDR), \
586 H(OP_XOR_LONG_2ADDR), \
587 H(OP_SHL_LONG_2ADDR), \
588 H(OP_SHR_LONG_2ADDR), \
589 H(OP_USHR_LONG_2ADDR), \
590 H(OP_ADD_FLOAT_2ADDR), \
591 H(OP_SUB_FLOAT_2ADDR), \
592 H(OP_MUL_FLOAT_2ADDR), \
593 H(OP_DIV_FLOAT_2ADDR), \
594 H(OP_REM_FLOAT_2ADDR), \
595 H(OP_ADD_DOUBLE_2ADDR), \
596 H(OP_SUB_DOUBLE_2ADDR), \
597 H(OP_MUL_DOUBLE_2ADDR), \
598 H(OP_DIV_DOUBLE_2ADDR), \
599 H(OP_REM_DOUBLE_2ADDR), \
601 H(OP_ADD_INT_LIT16), \
603 H(OP_MUL_INT_LIT16), \
604 H(OP_DIV_INT_LIT16), \
605 H(OP_REM_INT_LIT16), \
606 H(OP_AND_INT_LIT16), \
607 H(OP_OR_INT_LIT16), \
608 H(OP_XOR_INT_LIT16), \
609 H(OP_ADD_INT_LIT8), \
610 H(OP_RSUB_INT_LIT8), \
611 H(OP_MUL_INT_LIT8), \
612 H(OP_DIV_INT_LIT8), \
613 H(OP_REM_INT_LIT8), \
614 H(OP_AND_INT_LIT8), \
616 H(OP_XOR_INT_LIT8), \
618 H(OP_SHL_INT_LIT8), \
619 H(OP_SHR_INT_LIT8), \
620 H(OP_USHR_INT_LIT8), \
632 H(OP_EXECUTE_INLINE), \
635 H(OP_INVOKE_DIRECT_EMPTY), \
638 H(OP_IGET_WIDE_QUICK), \
639 H(OP_IGET_OBJECT_QUICK), \
641 H(OP_IPUT_WIDE_QUICK), \
642 H(OP_IPUT_OBJECT_QUICK), \
643 H(OP_INVOKE_VIRTUAL_QUICK), \
644 H(OP_INVOKE_VIRTUAL_QUICK_RANGE), \
645 H(OP_INVOKE_SUPER_QUICK), \
646 H(OP_INVOKE_SUPER_QUICK_RANGE), \
653 #endif /*_LIBDEX_OPCODE*/