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,
330 /* verifier/optimizer output -- nothing below here is generated by "dx" */
331 OP_IGET_WIDE_VOLATILE = 0xe8,
332 OP_IPUT_WIDE_VOLATILE = 0xe9,
333 OP_SGET_WIDE_VOLATILE = 0xea,
334 OP_SPUT_WIDE_VOLATILE = 0xeb,
337 * The "breakpoint" instruction is special, in that it should never
338 * be seen by anything but the debug interpreter. During debugging
339 * it takes the place of an arbitrary opcode, which means operations
340 * like "tell me the opcode width so I can find the next instruction"
341 * aren't possible. (This is correctable, but probably not useful.)
343 OP_BREAKPOINT = 0xec,
345 OP_THROW_VERIFICATION_ERROR = 0xed,
346 OP_EXECUTE_INLINE = 0xee,
347 OP_EXECUTE_INLINE_RANGE = 0xef,
349 OP_INVOKE_DIRECT_EMPTY = 0xf0,
350 OP_UNUSED_F1 = 0xf1, /* OP_INVOKE_DIRECT_EMPTY_RANGE? */
351 OP_IGET_QUICK = 0xf2,
352 OP_IGET_WIDE_QUICK = 0xf3,
353 OP_IGET_OBJECT_QUICK = 0xf4,
354 OP_IPUT_QUICK = 0xf5,
355 OP_IPUT_WIDE_QUICK = 0xf6,
356 OP_IPUT_OBJECT_QUICK = 0xf7,
358 OP_INVOKE_VIRTUAL_QUICK = 0xf8,
359 OP_INVOKE_VIRTUAL_QUICK_RANGE = 0xf9,
360 OP_INVOKE_SUPER_QUICK = 0xfa,
361 OP_INVOKE_SUPER_QUICK_RANGE = 0xfb,
362 OP_UNUSED_FC = 0xfc, /* OP_INVOKE_DIRECT_QUICK? */
363 OP_UNUSED_FD = 0xfd, /* OP_INVOKE_DIRECT_QUICK_RANGE? */
364 OP_UNUSED_FE = 0xfe, /* OP_INVOKE_INTERFACE_QUICK? */
365 OP_UNUSED_FF = 0xff, /* OP_INVOKE_INTERFACE_QUICK_RANGE*/
368 #define kNumDalvikInstructions 256
372 * Switch-statement signatures are a "NOP" followed by a code. (A true NOP
375 #define kPackedSwitchSignature 0x0100
376 #define kSparseSwitchSignature 0x0200
377 #define kArrayDataSignature 0x0300
380 * Macro used to generate computed goto tables for the C interpreter.
382 * The labels here must match up with the labels in the interpreter
383 * implementation. There is no direct connection between these and the
384 * numeric definitions above, but if the two get out of sync strange things
387 #define DEFINE_GOTO_TABLE(_name) \
388 static const void* _name[kNumDalvikInstructions] = { \
395 H(OP_MOVE_WIDE_FROM16), \
396 H(OP_MOVE_WIDE_16), \
398 H(OP_MOVE_OBJECT_FROM16), \
399 H(OP_MOVE_OBJECT_16), \
401 H(OP_MOVE_RESULT_WIDE), \
402 H(OP_MOVE_RESULT_OBJECT), \
403 H(OP_MOVE_EXCEPTION), \
408 H(OP_RETURN_OBJECT), \
412 H(OP_CONST_HIGH16), \
413 H(OP_CONST_WIDE_16), \
414 H(OP_CONST_WIDE_32), \
416 H(OP_CONST_WIDE_HIGH16), \
417 H(OP_CONST_STRING), \
418 H(OP_CONST_STRING_JUMBO), \
420 H(OP_MONITOR_ENTER), \
421 H(OP_MONITOR_EXIT), \
425 H(OP_ARRAY_LENGTH), \
426 H(OP_NEW_INSTANCE), \
428 H(OP_FILLED_NEW_ARRAY), \
429 H(OP_FILLED_NEW_ARRAY_RANGE), \
430 H(OP_FILL_ARRAY_DATA), \
435 H(OP_PACKED_SWITCH), \
436 H(OP_SPARSE_SWITCH), \
465 H(OP_AGET_BOOLEAN), \
472 H(OP_APUT_BOOLEAN), \
480 H(OP_IGET_BOOLEAN), \
487 H(OP_IPUT_BOOLEAN), \
495 H(OP_SGET_BOOLEAN), \
502 H(OP_SPUT_BOOLEAN), \
506 H(OP_INVOKE_VIRTUAL), \
507 H(OP_INVOKE_SUPER), \
509 H(OP_INVOKE_DIRECT), \
510 H(OP_INVOKE_STATIC), \
511 H(OP_INVOKE_INTERFACE), \
513 H(OP_INVOKE_VIRTUAL_RANGE), \
514 H(OP_INVOKE_SUPER_RANGE), \
515 H(OP_INVOKE_DIRECT_RANGE), \
516 H(OP_INVOKE_STATIC_RANGE), \
517 H(OP_INVOKE_INTERFACE_RANGE), \
528 H(OP_INT_TO_FLOAT), \
529 H(OP_INT_TO_DOUBLE), \
531 H(OP_LONG_TO_FLOAT), \
532 H(OP_LONG_TO_DOUBLE), \
533 H(OP_FLOAT_TO_INT), \
534 H(OP_FLOAT_TO_LONG), \
535 H(OP_FLOAT_TO_DOUBLE), \
536 H(OP_DOUBLE_TO_INT), \
537 H(OP_DOUBLE_TO_LONG), \
538 H(OP_DOUBLE_TO_FLOAT), \
541 H(OP_INT_TO_SHORT), \
577 H(OP_ADD_INT_2ADDR), \
578 H(OP_SUB_INT_2ADDR), \
579 H(OP_MUL_INT_2ADDR), \
580 H(OP_DIV_INT_2ADDR), \
581 H(OP_REM_INT_2ADDR), \
582 H(OP_AND_INT_2ADDR), \
583 H(OP_OR_INT_2ADDR), \
584 H(OP_XOR_INT_2ADDR), \
585 H(OP_SHL_INT_2ADDR), \
586 H(OP_SHR_INT_2ADDR), \
587 H(OP_USHR_INT_2ADDR), \
588 H(OP_ADD_LONG_2ADDR), \
589 H(OP_SUB_LONG_2ADDR), \
590 H(OP_MUL_LONG_2ADDR), \
591 H(OP_DIV_LONG_2ADDR), \
592 H(OP_REM_LONG_2ADDR), \
594 H(OP_AND_LONG_2ADDR), \
595 H(OP_OR_LONG_2ADDR), \
596 H(OP_XOR_LONG_2ADDR), \
597 H(OP_SHL_LONG_2ADDR), \
598 H(OP_SHR_LONG_2ADDR), \
599 H(OP_USHR_LONG_2ADDR), \
600 H(OP_ADD_FLOAT_2ADDR), \
601 H(OP_SUB_FLOAT_2ADDR), \
602 H(OP_MUL_FLOAT_2ADDR), \
603 H(OP_DIV_FLOAT_2ADDR), \
604 H(OP_REM_FLOAT_2ADDR), \
605 H(OP_ADD_DOUBLE_2ADDR), \
606 H(OP_SUB_DOUBLE_2ADDR), \
607 H(OP_MUL_DOUBLE_2ADDR), \
608 H(OP_DIV_DOUBLE_2ADDR), \
609 H(OP_REM_DOUBLE_2ADDR), \
611 H(OP_ADD_INT_LIT16), \
613 H(OP_MUL_INT_LIT16), \
614 H(OP_DIV_INT_LIT16), \
615 H(OP_REM_INT_LIT16), \
616 H(OP_AND_INT_LIT16), \
617 H(OP_OR_INT_LIT16), \
618 H(OP_XOR_INT_LIT16), \
619 H(OP_ADD_INT_LIT8), \
620 H(OP_RSUB_INT_LIT8), \
621 H(OP_MUL_INT_LIT8), \
622 H(OP_DIV_INT_LIT8), \
623 H(OP_REM_INT_LIT8), \
624 H(OP_AND_INT_LIT8), \
626 H(OP_XOR_INT_LIT8), \
628 H(OP_SHL_INT_LIT8), \
629 H(OP_SHR_INT_LIT8), \
630 H(OP_USHR_INT_LIT8), \
636 H(OP_IGET_WIDE_VOLATILE), \
637 H(OP_IPUT_WIDE_VOLATILE), \
638 H(OP_SGET_WIDE_VOLATILE), \
639 H(OP_SPUT_WIDE_VOLATILE), \
641 H(OP_THROW_VERIFICATION_ERROR), \
642 H(OP_EXECUTE_INLINE), \
643 H(OP_EXECUTE_INLINE_RANGE), \
645 H(OP_INVOKE_DIRECT_EMPTY), \
648 H(OP_IGET_WIDE_QUICK), \
649 H(OP_IGET_OBJECT_QUICK), \
651 H(OP_IPUT_WIDE_QUICK), \
652 H(OP_IPUT_OBJECT_QUICK), \
653 H(OP_INVOKE_VIRTUAL_QUICK), \
654 H(OP_INVOKE_VIRTUAL_QUICK_RANGE), \
655 H(OP_INVOKE_SUPER_QUICK), \
656 H(OP_INVOKE_SUPER_QUICK_RANGE), \
663 #endif /*_LIBDEX_OPCODE*/