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 information.
20 * IMPORTANT NOTE: The contents of this file are mostly generated
21 * automatically by the opcode-gen tool. Any edits to the generated
22 * sections will get wiped out the next time the tool is run.
24 * See the file opcode-gen/README.txt for information about updating
25 * opcodes and instruction formats.
28 #ifndef LIBDEX_DEXOPCODES_H_
29 #define LIBDEX_DEXOPCODES_H_
34 * kMaxOpcodeValue: the highest possible raw (unpacked) opcode value
36 * kNumPackedOpcodes: the highest possible packed opcode value of a
37 * valid Dalvik opcode, plus one
39 * TODO: Change this once the rest of the code is prepared to deal with
42 // BEGIN(libdex-maximum-values); GENERATED AUTOMATICALLY BY opcode-gen
43 #define kMaxOpcodeValue 0xffff
44 #define kNumPackedOpcodes 0x100
45 // END(libdex-maximum-values); GENERATED AUTOMATICALLY BY opcode-gen
48 * Switch table and array data signatures are a code unit consisting
49 * of "NOP" (0x00) in the low-order byte and a non-zero identifying
50 * code in the high-order byte. (A true NOP is 0x0000.)
52 #define kPackedSwitchSignature 0x0100
53 #define kSparseSwitchSignature 0x0200
54 #define kArrayDataSignature 0x0300
57 * Enumeration of all Dalvik opcodes, where the enumeration value
58 * associated with each is the corresponding packed opcode number.
59 * This is different than the opcode value from the Dalvik bytecode
60 * spec for opcode values >= 0xff; see dexOpcodeFromCodeUnit() below.
62 * A note about the "breakpoint" opcode. This instruction is special,
63 * in that it should never be seen by anything but the debug
64 * interpreter. During debugging it takes the place of an arbitrary
65 * opcode, which means operations like "tell me the opcode width so I
66 * can find the next instruction" aren't possible. (This is
67 * correctable, but probably not useful.)
70 // BEGIN(libdex-opcode-enum); GENERATED AUTOMATICALLY BY opcode-gen
73 OP_MOVE_FROM16 = 0x02,
76 OP_MOVE_WIDE_FROM16 = 0x05,
77 OP_MOVE_WIDE_16 = 0x06,
78 OP_MOVE_OBJECT = 0x07,
79 OP_MOVE_OBJECT_FROM16 = 0x08,
80 OP_MOVE_OBJECT_16 = 0x09,
81 OP_MOVE_RESULT = 0x0a,
82 OP_MOVE_RESULT_WIDE = 0x0b,
83 OP_MOVE_RESULT_OBJECT = 0x0c,
84 OP_MOVE_EXCEPTION = 0x0d,
85 OP_RETURN_VOID = 0x0e,
87 OP_RETURN_WIDE = 0x10,
88 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,
100 OP_MONITOR_ENTER = 0x1d,
101 OP_MONITOR_EXIT = 0x1e,
102 OP_CHECK_CAST = 0x1f,
103 OP_INSTANCE_OF = 0x20,
104 OP_ARRAY_LENGTH = 0x21,
105 OP_NEW_INSTANCE = 0x22,
107 OP_FILLED_NEW_ARRAY = 0x24,
108 OP_FILLED_NEW_ARRAY_RANGE = 0x25,
109 OP_FILL_ARRAY_DATA = 0x26,
114 OP_PACKED_SWITCH = 0x2b,
115 OP_SPARSE_SWITCH = 0x2c,
116 OP_CMPL_FLOAT = 0x2d,
117 OP_CMPG_FLOAT = 0x2e,
118 OP_CMPL_DOUBLE = 0x2f,
119 OP_CMPG_DOUBLE = 0x30,
141 OP_AGET_OBJECT = 0x46,
142 OP_AGET_BOOLEAN = 0x47,
145 OP_AGET_SHORT = 0x4a,
148 OP_APUT_OBJECT = 0x4d,
149 OP_APUT_BOOLEAN = 0x4e,
152 OP_APUT_SHORT = 0x51,
155 OP_IGET_OBJECT = 0x54,
156 OP_IGET_BOOLEAN = 0x55,
159 OP_IGET_SHORT = 0x58,
162 OP_IPUT_OBJECT = 0x5b,
163 OP_IPUT_BOOLEAN = 0x5c,
166 OP_IPUT_SHORT = 0x5f,
169 OP_SGET_OBJECT = 0x62,
170 OP_SGET_BOOLEAN = 0x63,
173 OP_SGET_SHORT = 0x66,
176 OP_SPUT_OBJECT = 0x69,
177 OP_SPUT_BOOLEAN = 0x6a,
180 OP_SPUT_SHORT = 0x6d,
181 OP_INVOKE_VIRTUAL = 0x6e,
182 OP_INVOKE_SUPER = 0x6f,
183 OP_INVOKE_DIRECT = 0x70,
184 OP_INVOKE_STATIC = 0x71,
185 OP_INVOKE_INTERFACE = 0x72,
187 OP_INVOKE_VIRTUAL_RANGE = 0x74,
188 OP_INVOKE_SUPER_RANGE = 0x75,
189 OP_INVOKE_DIRECT_RANGE = 0x76,
190 OP_INVOKE_STATIC_RANGE = 0x77,
191 OP_INVOKE_INTERFACE_RANGE = 0x78,
199 OP_NEG_DOUBLE = 0x80,
200 OP_INT_TO_LONG = 0x81,
201 OP_INT_TO_FLOAT = 0x82,
202 OP_INT_TO_DOUBLE = 0x83,
203 OP_LONG_TO_INT = 0x84,
204 OP_LONG_TO_FLOAT = 0x85,
205 OP_LONG_TO_DOUBLE = 0x86,
206 OP_FLOAT_TO_INT = 0x87,
207 OP_FLOAT_TO_LONG = 0x88,
208 OP_FLOAT_TO_DOUBLE = 0x89,
209 OP_DOUBLE_TO_INT = 0x8a,
210 OP_DOUBLE_TO_LONG = 0x8b,
211 OP_DOUBLE_TO_FLOAT = 0x8c,
212 OP_INT_TO_BYTE = 0x8d,
213 OP_INT_TO_CHAR = 0x8e,
214 OP_INT_TO_SHORT = 0x8f,
242 OP_ADD_DOUBLE = 0xab,
243 OP_SUB_DOUBLE = 0xac,
244 OP_MUL_DOUBLE = 0xad,
245 OP_DIV_DOUBLE = 0xae,
246 OP_REM_DOUBLE = 0xaf,
247 OP_ADD_INT_2ADDR = 0xb0,
248 OP_SUB_INT_2ADDR = 0xb1,
249 OP_MUL_INT_2ADDR = 0xb2,
250 OP_DIV_INT_2ADDR = 0xb3,
251 OP_REM_INT_2ADDR = 0xb4,
252 OP_AND_INT_2ADDR = 0xb5,
253 OP_OR_INT_2ADDR = 0xb6,
254 OP_XOR_INT_2ADDR = 0xb7,
255 OP_SHL_INT_2ADDR = 0xb8,
256 OP_SHR_INT_2ADDR = 0xb9,
257 OP_USHR_INT_2ADDR = 0xba,
258 OP_ADD_LONG_2ADDR = 0xbb,
259 OP_SUB_LONG_2ADDR = 0xbc,
260 OP_MUL_LONG_2ADDR = 0xbd,
261 OP_DIV_LONG_2ADDR = 0xbe,
262 OP_REM_LONG_2ADDR = 0xbf,
263 OP_AND_LONG_2ADDR = 0xc0,
264 OP_OR_LONG_2ADDR = 0xc1,
265 OP_XOR_LONG_2ADDR = 0xc2,
266 OP_SHL_LONG_2ADDR = 0xc3,
267 OP_SHR_LONG_2ADDR = 0xc4,
268 OP_USHR_LONG_2ADDR = 0xc5,
269 OP_ADD_FLOAT_2ADDR = 0xc6,
270 OP_SUB_FLOAT_2ADDR = 0xc7,
271 OP_MUL_FLOAT_2ADDR = 0xc8,
272 OP_DIV_FLOAT_2ADDR = 0xc9,
273 OP_REM_FLOAT_2ADDR = 0xca,
274 OP_ADD_DOUBLE_2ADDR = 0xcb,
275 OP_SUB_DOUBLE_2ADDR = 0xcc,
276 OP_MUL_DOUBLE_2ADDR = 0xcd,
277 OP_DIV_DOUBLE_2ADDR = 0xce,
278 OP_REM_DOUBLE_2ADDR = 0xcf,
279 OP_ADD_INT_LIT16 = 0xd0,
281 OP_MUL_INT_LIT16 = 0xd2,
282 OP_DIV_INT_LIT16 = 0xd3,
283 OP_REM_INT_LIT16 = 0xd4,
284 OP_AND_INT_LIT16 = 0xd5,
285 OP_OR_INT_LIT16 = 0xd6,
286 OP_XOR_INT_LIT16 = 0xd7,
287 OP_ADD_INT_LIT8 = 0xd8,
288 OP_RSUB_INT_LIT8 = 0xd9,
289 OP_MUL_INT_LIT8 = 0xda,
290 OP_DIV_INT_LIT8 = 0xdb,
291 OP_REM_INT_LIT8 = 0xdc,
292 OP_AND_INT_LIT8 = 0xdd,
293 OP_OR_INT_LIT8 = 0xde,
294 OP_XOR_INT_LIT8 = 0xdf,
295 OP_SHL_INT_LIT8 = 0xe0,
296 OP_SHR_INT_LIT8 = 0xe1,
297 OP_USHR_INT_LIT8 = 0xe2,
298 OP_IGET_VOLATILE = 0xe3,
299 OP_IPUT_VOLATILE = 0xe4,
300 OP_SGET_VOLATILE = 0xe5,
301 OP_SPUT_VOLATILE = 0xe6,
302 OP_IGET_OBJECT_VOLATILE = 0xe7,
303 OP_IGET_WIDE_VOLATILE = 0xe8,
304 OP_IPUT_WIDE_VOLATILE = 0xe9,
305 OP_SGET_WIDE_VOLATILE = 0xea,
306 OP_SPUT_WIDE_VOLATILE = 0xeb,
307 OP_BREAKPOINT = 0xec,
308 OP_THROW_VERIFICATION_ERROR = 0xed,
309 OP_EXECUTE_INLINE = 0xee,
310 OP_EXECUTE_INLINE_RANGE = 0xef,
311 OP_INVOKE_OBJECT_INIT_RANGE = 0xf0,
312 OP_RETURN_VOID_BARRIER = 0xf1,
313 OP_IGET_QUICK = 0xf2,
314 OP_IGET_WIDE_QUICK = 0xf3,
315 OP_IGET_OBJECT_QUICK = 0xf4,
316 OP_IPUT_QUICK = 0xf5,
317 OP_IPUT_WIDE_QUICK = 0xf6,
318 OP_IPUT_OBJECT_QUICK = 0xf7,
319 OP_INVOKE_VIRTUAL_QUICK = 0xf8,
320 OP_INVOKE_VIRTUAL_QUICK_RANGE = 0xf9,
321 OP_INVOKE_SUPER_QUICK = 0xfa,
322 OP_INVOKE_SUPER_QUICK_RANGE = 0xfb,
323 OP_IPUT_OBJECT_VOLATILE = 0xfc,
324 OP_SGET_OBJECT_VOLATILE = 0xfd,
325 OP_SPUT_OBJECT_VOLATILE = 0xfe,
327 // END(libdex-opcode-enum)
331 * Macro used to generate a computed goto table for use in implementing
332 * an interpreter in C.
334 #define DEFINE_GOTO_TABLE(_name) \
335 static const void* _name[kNumPackedOpcodes] = { \
336 /* BEGIN(libdex-goto-table); GENERATED AUTOMATICALLY BY opcode-gen */ \
342 H(OP_MOVE_WIDE_FROM16), \
343 H(OP_MOVE_WIDE_16), \
345 H(OP_MOVE_OBJECT_FROM16), \
346 H(OP_MOVE_OBJECT_16), \
348 H(OP_MOVE_RESULT_WIDE), \
349 H(OP_MOVE_RESULT_OBJECT), \
350 H(OP_MOVE_EXCEPTION), \
354 H(OP_RETURN_OBJECT), \
358 H(OP_CONST_HIGH16), \
359 H(OP_CONST_WIDE_16), \
360 H(OP_CONST_WIDE_32), \
362 H(OP_CONST_WIDE_HIGH16), \
363 H(OP_CONST_STRING), \
364 H(OP_CONST_STRING_JUMBO), \
366 H(OP_MONITOR_ENTER), \
367 H(OP_MONITOR_EXIT), \
370 H(OP_ARRAY_LENGTH), \
371 H(OP_NEW_INSTANCE), \
373 H(OP_FILLED_NEW_ARRAY), \
374 H(OP_FILLED_NEW_ARRAY_RANGE), \
375 H(OP_FILL_ARRAY_DATA), \
380 H(OP_PACKED_SWITCH), \
381 H(OP_SPARSE_SWITCH), \
408 H(OP_AGET_BOOLEAN), \
415 H(OP_APUT_BOOLEAN), \
422 H(OP_IGET_BOOLEAN), \
429 H(OP_IPUT_BOOLEAN), \
436 H(OP_SGET_BOOLEAN), \
443 H(OP_SPUT_BOOLEAN), \
447 H(OP_INVOKE_VIRTUAL), \
448 H(OP_INVOKE_SUPER), \
449 H(OP_INVOKE_DIRECT), \
450 H(OP_INVOKE_STATIC), \
451 H(OP_INVOKE_INTERFACE), \
453 H(OP_INVOKE_VIRTUAL_RANGE), \
454 H(OP_INVOKE_SUPER_RANGE), \
455 H(OP_INVOKE_DIRECT_RANGE), \
456 H(OP_INVOKE_STATIC_RANGE), \
457 H(OP_INVOKE_INTERFACE_RANGE), \
467 H(OP_INT_TO_FLOAT), \
468 H(OP_INT_TO_DOUBLE), \
470 H(OP_LONG_TO_FLOAT), \
471 H(OP_LONG_TO_DOUBLE), \
472 H(OP_FLOAT_TO_INT), \
473 H(OP_FLOAT_TO_LONG), \
474 H(OP_FLOAT_TO_DOUBLE), \
475 H(OP_DOUBLE_TO_INT), \
476 H(OP_DOUBLE_TO_LONG), \
477 H(OP_DOUBLE_TO_FLOAT), \
480 H(OP_INT_TO_SHORT), \
513 H(OP_ADD_INT_2ADDR), \
514 H(OP_SUB_INT_2ADDR), \
515 H(OP_MUL_INT_2ADDR), \
516 H(OP_DIV_INT_2ADDR), \
517 H(OP_REM_INT_2ADDR), \
518 H(OP_AND_INT_2ADDR), \
519 H(OP_OR_INT_2ADDR), \
520 H(OP_XOR_INT_2ADDR), \
521 H(OP_SHL_INT_2ADDR), \
522 H(OP_SHR_INT_2ADDR), \
523 H(OP_USHR_INT_2ADDR), \
524 H(OP_ADD_LONG_2ADDR), \
525 H(OP_SUB_LONG_2ADDR), \
526 H(OP_MUL_LONG_2ADDR), \
527 H(OP_DIV_LONG_2ADDR), \
528 H(OP_REM_LONG_2ADDR), \
529 H(OP_AND_LONG_2ADDR), \
530 H(OP_OR_LONG_2ADDR), \
531 H(OP_XOR_LONG_2ADDR), \
532 H(OP_SHL_LONG_2ADDR), \
533 H(OP_SHR_LONG_2ADDR), \
534 H(OP_USHR_LONG_2ADDR), \
535 H(OP_ADD_FLOAT_2ADDR), \
536 H(OP_SUB_FLOAT_2ADDR), \
537 H(OP_MUL_FLOAT_2ADDR), \
538 H(OP_DIV_FLOAT_2ADDR), \
539 H(OP_REM_FLOAT_2ADDR), \
540 H(OP_ADD_DOUBLE_2ADDR), \
541 H(OP_SUB_DOUBLE_2ADDR), \
542 H(OP_MUL_DOUBLE_2ADDR), \
543 H(OP_DIV_DOUBLE_2ADDR), \
544 H(OP_REM_DOUBLE_2ADDR), \
545 H(OP_ADD_INT_LIT16), \
547 H(OP_MUL_INT_LIT16), \
548 H(OP_DIV_INT_LIT16), \
549 H(OP_REM_INT_LIT16), \
550 H(OP_AND_INT_LIT16), \
551 H(OP_OR_INT_LIT16), \
552 H(OP_XOR_INT_LIT16), \
553 H(OP_ADD_INT_LIT8), \
554 H(OP_RSUB_INT_LIT8), \
555 H(OP_MUL_INT_LIT8), \
556 H(OP_DIV_INT_LIT8), \
557 H(OP_REM_INT_LIT8), \
558 H(OP_AND_INT_LIT8), \
560 H(OP_XOR_INT_LIT8), \
561 H(OP_SHL_INT_LIT8), \
562 H(OP_SHR_INT_LIT8), \
563 H(OP_USHR_INT_LIT8), \
564 H(OP_IGET_VOLATILE), \
565 H(OP_IPUT_VOLATILE), \
566 H(OP_SGET_VOLATILE), \
567 H(OP_SPUT_VOLATILE), \
568 H(OP_IGET_OBJECT_VOLATILE), \
569 H(OP_IGET_WIDE_VOLATILE), \
570 H(OP_IPUT_WIDE_VOLATILE), \
571 H(OP_SGET_WIDE_VOLATILE), \
572 H(OP_SPUT_WIDE_VOLATILE), \
574 H(OP_THROW_VERIFICATION_ERROR), \
575 H(OP_EXECUTE_INLINE), \
576 H(OP_EXECUTE_INLINE_RANGE), \
577 H(OP_INVOKE_OBJECT_INIT_RANGE), \
578 H(OP_RETURN_VOID_BARRIER), \
580 H(OP_IGET_WIDE_QUICK), \
581 H(OP_IGET_OBJECT_QUICK), \
583 H(OP_IPUT_WIDE_QUICK), \
584 H(OP_IPUT_OBJECT_QUICK), \
585 H(OP_INVOKE_VIRTUAL_QUICK), \
586 H(OP_INVOKE_VIRTUAL_QUICK_RANGE), \
587 H(OP_INVOKE_SUPER_QUICK), \
588 H(OP_INVOKE_SUPER_QUICK_RANGE), \
589 H(OP_IPUT_OBJECT_VOLATILE), \
590 H(OP_SGET_OBJECT_VOLATILE), \
591 H(OP_SPUT_OBJECT_VOLATILE), \
593 /* END(libdex-goto-table) */ \
597 * Return the Opcode for a given raw opcode code unit (which may
598 * include data payload). The packed index is a zero-based index which
599 * can be used to point into various opcode-related tables. The Dalvik
600 * opcode space is inherently sparse, in that the opcode unit is 16
601 * bits wide, but for most opcodes, eight of those bits are for data.
603 DEX_INLINE Opcode dexOpcodeFromCodeUnit(u2 codeUnit) {
605 * This will want to become table-driven should the opcode layout
606 * get more complicated.
608 * Note: This has to match the corresponding code in opcode-gen, so
609 * that data tables get generated in a consistent way.
611 int lowByte = codeUnit & 0xff;
612 if (lowByte != 0xff) {
613 return (Opcode) lowByte;
615 return (Opcode) ((codeUnit >> 8) | 0x100);
620 * Return the name of an opcode.
622 const char* dexGetOpcodeName(Opcode op);
624 #endif // LIBDEX_DEXOPCODES_H_