1 /*
  2  * Copyright (c) 1996, 2014, Oracle and/or its affiliates. All rights reserved.
  3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4  *
  5  * This code is free software; you can redistribute it and/or modify it
  6  * under the terms of the GNU General Public License version 2 only, as
  7  * published by the Free Software Foundation.
  8  *
  9  * This code is distributed in the hope that it will be useful, but WITHOUT
 10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  */
 23 package org.openjdk.asmtools.jasm;
 24 
 25 import java.util.HashMap;
 26 
 27 /**
 28  *
 29  * OpcodeTables
 30  *
 31  * The OpcodeTables class follows a Singleton Pattern. This class contains Enums, that are
 32  * contained in private hash maps (lookup tables and reverse lookup tables). These hash
 33  * maps all have public accessors, which clients use to look-up opcodes.
 34  *
 35  * Tokens in this table carry no external state, and are typically treated as constants.
 36  * They do not need to be reset.
 37  *
 38  */
 39 public class OpcodeTables {
 40 
 41     /**
 42      * Initialized keyword and token Hash Maps (and Reverse Tables)
 43      */
 44     static private final int MaxOpcodes = 301;
 45     static private HashMap<Integer, Opcode> IntToNormalOpcodes = new HashMap<>(MaxOpcodes);
 46     static private HashMap<Integer, Opcode> IntToAllOpcodes = new HashMap<>(MaxOpcodes);
 47     static private HashMap<String, Opcode> mnemocodes = new HashMap<>(MaxOpcodes);
 48 
 49     static private HashMap<Integer, Opcode> IntToPrivOpcode = new HashMap<>(MaxOpcodes);
 50     static private HashMap<String, Opcode> PrivMnemocodes = new HashMap<>(MaxOpcodes);
 51 
 52     static private HashMap<Integer, Opcode> IntToNonPrivOpcode = new HashMap<>(MaxOpcodes);
 53     static private HashMap<String, Opcode> NonPrivMnemocodes = new HashMap<>(MaxOpcodes);
 54 
 55     static {
 56         // register all of the tokens
 57         for (Opcode opc : Opcode.values()) {
 58             registerOpcode(opc);
 59         }
 60 
 61     }
 62 
 63     private static void registerOpcode(Opcode opc) {
 64         IntToAllOpcodes.put(opc.value, opc);
 65         mnemocodes.put(opc.parsekey, opc);
 66         if (opc.alias != null) {
 67             mnemocodes.put(opc.alias, opc);
 68         }
 69 
 70         if (opc.type == OpcodeType.PRIVELEGED) {
 71             PrivMnemocodes.put(opc.parsekey, opc);
 72             IntToPrivOpcode.put(opc.baseVal, opc);
 73         } else if (opc.type == OpcodeType.NONPRIVELEGED) {
 74             NonPrivMnemocodes.put(opc.parsekey, opc);
 75             IntToNonPrivOpcode.put(opc.baseVal, opc);
 76         }
 77 
 78     }
 79 
 80     public static Opcode opcode(String mnemonic) {
 81         return mnemocodes.get(mnemonic);
 82     }
 83 
 84     public static Opcode opcode(Integer mnem_code) {
 85         return IntToAllOpcodes.get(mnem_code);
 86     }
 87 
 88     /*-------------------------------------------------------- */
 89     /**
 90      * Marker: describes the type of Opcode.
 91      *
 92      * certain types of Opcodes will be added to specific lookup tables.
 93      */
 94     static public enum OpcodeType {
 95         NORMAL            (0, "Normal"),
 96         NONPRIVELEGED     (1, "NonPriv"),
 97         PRIVELEGED        (2, "Priv"),
 98         WIDE              (3, "Wide");
 99 
100         private final Integer value;
101         private final String printval;
102 
103         OpcodeType(Integer val, String print) {
104             value = val;
105             printval = print;
106         }
107 
108         public String printval() {
109             return printval;
110         }
111 
112     }
113 
114     /*-------------------------------------------------------- */
115     /* Opcode Enums */
116     static public enum Opcode {
117      /* Opcodes */
118     opc_dead                (-2, " opc_dead", 0),
119     opc_label               (-1, "opc_label", 0),
120     opc_nop                 (0, "nop", 1),
121     opc_aconst_null         (1, "aconst_null", 1),
122     opc_iconst_m1           (2, "iconst_m1", 1),
123     opc_iconst_0            (3, "iconst_0", 1),
124     opc_iconst_1            (4, "iconst_1", 1),
125     opc_iconst_2            (5, "iconst_2", 1),
126     opc_iconst_3            (6, "iconst_3", 1),
127     opc_iconst_4            (7, "iconst_4", 1),
128     opc_iconst_5            (8, "iconst_5", 1),
129     opc_lconst_0            (9, "lconst_0", 1),
130     opc_lconst_1            (10, "lconst_1", 1),
131     opc_fconst_0            (11, "fconst_0", 1),
132     opc_fconst_1            (12, "fconst_1", 1),
133     opc_fconst_2            (13, "fconst_2", 1),
134     opc_dconst_0            (14, "dconst_0", 1),
135     opc_dconst_1            (15, "dconst_1", 1),
136     opc_bipush              (16, "bipush", 2),
137     opc_sipush              (17, "sipush", 3),
138     opc_ldc                 (18, "ldc", 2),
139     opc_ldc_w               (19, "ldc_w", 3),
140     opc_ldc2_w              (20, "ldc2_w", 3),
141     opc_iload               (21, "iload", 2),
142     opc_lload               (22, "lload", 2),
143     opc_fload               (23, "fload", 2),
144     opc_dload               (24, "dload", 2),
145     opc_aload               (25, "aload", 2),
146     opc_iload_0            (26, "iload_0", 1),
147     opc_iload_1            (27, "iload_1", 1),
148     opc_iload_2            (28, "iload_2", 1),
149     opc_iload_3            (29, "iload_3", 1),
150     opc_lload_0            (30, "lload_0", 1),
151     opc_lload_1            (31, "lload_1", 1),
152     opc_lload_2            (32, "lload_2", 1),
153     opc_lload_3            (33, "lload_3", 1),
154     opc_fload_0            (34, "fload_0", 1),
155     opc_fload_1            (35, "fload_1", 1),
156     opc_fload_2            (36, "fload_2", 1),
157     opc_fload_3            (37, "fload_3", 1),
158     opc_dload_0            (38, "dload_0", 1),
159     opc_dload_1            (39, "dload_1", 1),
160     opc_dload_2            (40, "dload_2", 1),
161     opc_dload_3            (41, "dload_3", 1),
162     opc_aload_0            (42, "aload_0", 1),
163     opc_aload_1            (43, "aload_1", 1),
164     opc_aload_2            (44, "aload_2", 1),
165     opc_aload_3            (45, "aload_3", 1),
166     opc_iaload            (46, "iaload", 1),
167     opc_laload            (47, "laload", 1),
168     opc_faload            (48, "faload", 1),
169     opc_daload            (49, "daload", 1),
170     opc_aaload            (50, "aaload", 1),
171     opc_baload            (51, "baload", 1),
172     opc_caload            (52, "caload", 1),
173     opc_saload            (53, "saload", 1),
174     opc_istore            (54, "istore", 2),
175     opc_lstore            (55, "lstore", 2),
176     opc_fstore            (56, "fstore", 2),
177     opc_dstore            (57, "dstore", 2),
178     opc_astore            (58, "astore", 2),
179     opc_istore_0            (59, "istore_0", 1),
180     opc_istore_1            (60, "istore_1", 1),
181     opc_istore_2            (61, "istore_2", 1),
182     opc_istore_3            (62, "istore_3", 1),
183     opc_lstore_0            (63, "lstore_0", 1),
184     opc_lstore_1            (64, "lstore_1", 1),
185     opc_lstore_2            (65, "lstore_2", 1),
186     opc_lstore_3            (66, "lstore_3", 1),
187     opc_fstore_0            (67, "fstore_0", 1),
188     opc_fstore_1            (68, "fstore_1", 1),
189     opc_fstore_2            (69, "fstore_2", 1),
190     opc_fstore_3            (70, "fstore_3", 1),
191     opc_dstore_0            (71, "dstore_0", 1),
192     opc_dstore_1            (72, "dstore_1", 1),
193     opc_dstore_2            (73, "dstore_2", 1),
194     opc_dstore_3            (74, "dstore_3", 1),
195     opc_astore_0            (75, "astore_0", 1),
196     opc_astore_1            (76, "astore_1", 1),
197     opc_astore_2            (77, "astore_2", 1),
198     opc_astore_3            (78, "astore_3", 1),
199     opc_iastore             (79, "iastore", 1),
200     opc_lastore             (80, "lastore", 1),
201     opc_fastore             (81, "fastore", 1),
202     opc_dastore             (82, "dastore", 1),
203     opc_aastore             (83, "aastore", 1),
204     opc_bastore             (84, "bastore", 1),
205     opc_castore             (85, "castore", 1),
206     opc_sastore             (86, "sastore", 1),
207     opc_pop                 (87, "pop", 1),
208     opc_pop2                (88, "pop2", 1),
209     opc_dup                 (89, "dup", 1),
210     opc_dup_x1              (90, "dup_x1", 1),
211     opc_dup_x2              (91, "dup_x2", 1),
212     opc_dup2                (92, "dup2", 1),
213     opc_dup2_x1             (93, "dup2_x1", 1),
214     opc_dup2_x2             (94, "dup2_x2", 1),
215     opc_swap                (95, "swap", 1),
216     opc_iadd                (96, "iadd", 1),
217     opc_ladd                (97, "ladd", 1),
218     opc_fadd                (98, "fadd", 1),
219     opc_dadd                (99, "dadd", 1),
220     opc_isub                (100, "isub", 1),
221     opc_lsub                (101, "lsub", 1),
222     opc_fsub                (102, "fsub", 1),
223     opc_dsub                (103, "dsub", 1),
224     opc_imul                (104, "imul", 1),
225     opc_lmul                (105, "lmul", 1),
226     opc_fmul                (106, "fmul", 1),
227     opc_dmul                (107, "dmul", 1),
228     opc_idiv                (108, "idiv", 1),
229     opc_ldiv                (109, "ldiv", 1),
230     opc_fdiv                (110, "fdiv", 1),
231     opc_ddiv                (111, "ddiv", 1),
232     opc_irem                (112, "irem", 1),
233     opc_lrem                (113, "lrem", 1),
234     opc_frem                (114, "frem", 1),
235     opc_drem                (115, "drem", 1),
236     opc_ineg                (116, "ineg", 1),
237     opc_lneg                (117, "lneg", 1),
238     opc_fneg                (118, "fneg", 1),
239     opc_dneg                (119, "dneg", 1),
240     opc_ishl                (120, "ishl", 1),
241     opc_lshl                (121, "lshl", 1),
242     opc_ishr                (122, "ishr", 1),
243     opc_lshr                (123, "lshr", 1),
244     opc_iushr               (124, "iushr", 1),
245     opc_lushr               (125, "lushr", 1),
246     opc_iand                (126, "iand", 1),
247     opc_land                (127, "land", 1),
248     opc_ior                 (128, "ior", 1),
249     opc_lor                 (129, "lor", 1),
250     opc_ixor                (130, "ixor", 1),
251     opc_lxor                (131, "lxor", 1),
252     opc_iinc                (132, "iinc", 3),
253     opc_i2l                 (133, "i2l", 1),
254     opc_i2f                 (134, "i2f", 1),
255     opc_i2d                 (135, "i2d", 1),
256     opc_l2i                 (136, "l2i", 1),
257     opc_l2f                 (137, "l2f", 1),
258     opc_l2d                 (138, "l2d", 1),
259     opc_f2i                 (139, "f2i", 1),
260     opc_f2l                 (140, "f2l", 1),
261     opc_f2d                 (141, "f2d", 1),
262     opc_d2i                 (142, "d2i", 1),
263     opc_d2l                 (143, "d2l", 1),
264     opc_d2f                 (144, "d2f", 1),
265     opc_i2b                 (145, "i2b", 1),
266     opc_i2c                 (146, "i2c", 1),
267     opc_i2s                 (147, "i2s", 1),
268     opc_lcmp                (148, "lcmp", 1),
269     opc_fcmpl               (149, "fcmpl", 1),
270     opc_fcmpg               (150, "fcmpg", 1),
271     opc_dcmpl               (151, "dcmpl", 1),
272     opc_dcmpg               (152, "dcmpg", 1),
273     opc_ifeq                (153, "ifeq", 3),
274     opc_ifne                (154, "ifne", 3),
275     opc_iflt                (155, "iflt", 3),
276     opc_ifge                (156, "ifge", 3),
277     opc_ifgt                (157, "ifgt", 3),
278     opc_ifle                (158, "ifle", 3),
279     opc_if_icmpeq           (159, "if_icmpeq", 3),
280     opc_if_icmpne           (160, "if_icmpne", 3),
281     opc_if_icmplt           (161, "if_icmplt", 3),
282     opc_if_icmpge           (162, "if_icmpge", 3),
283     opc_if_icmpgt           (163, "if_icmpgt", 3),
284     opc_if_icmple           (164, "if_icmple", 3),
285     opc_if_acmpeq           (165, "if_acmpeq", 3),
286     opc_if_acmpne           (166, "if_acmpne", 3),
287     opc_goto                (167, "goto", 3),
288     opc_jsr                 (168, "jsr", 3),
289     opc_ret                 (169, "ret", 2),
290     opc_tableswitch         (170, "tableswitch", 99),
291     opc_lookupswitch        (171, "lookupswitch", 99),
292     opc_ireturn             (172, "ireturn", 1),
293     opc_lreturn             (173, "lreturn", 1),
294     opc_freturn             (174, "freturn", 1),
295     opc_dreturn             (175, "dreturn", 1),
296     opc_areturn             (176, "areturn", 1),
297     opc_return              (177, "return", 1),
298     opc_getstatic           (178, "getstatic", 3),
299     opc_putstatic           (179, "putstatic", 3),
300     opc_getfield            (180, "getfield", 3),
301     opc_putfield            (181, "putfield", 3),
302     opc_invokevirtual       (182, "invokevirtual", 3),
303     opc_invokespecial       (183, "invokespecial", "invokenonvirtual", 3),
304     opc_invokestatic        (184, "invokestatic", 3),
305     opc_invokeinterface     (185, "invokeinterface", 5),
306     opc_invokedynamic       (186, "invokedynamic", 5),
307     opc_new                 (187, "new", 3),
308     opc_newarray            (188, "newarray", 2),
309     opc_anewarray           (189, "anewarray", 3),
310     opc_arraylength         (190, "arraylength", 1),
311     opc_athrow              (191, "athrow", 1),
312     opc_checkcast           (192, "checkcast", 3),
313     opc_instanceof          (193, "instanceof", 3),
314     opc_monitorenter        (194, "monitorenter", 1),
315     opc_monitorexit         (195, "monitorexit", 1),
316 
317         // Wide Marker (not really an opcode)
318         opc_wide            (196, null, 0),
319     opc_multianewarray      (197, "multianewarray", 4),
320     opc_ifnull              (198, "ifnull", 3),
321     opc_ifnonnull           (199, "ifnonnull", 3),
322     opc_goto_w              (200, "goto_w", 5),
323     opc_jsr_w               (201, "jsr_w", 5),
324     opc_aconst_init         (203, "aconst_init", 3),
325     opc_withfield           (204, "withfield", 3),
326 
327         /* Pseudo-instructions */
328     opc_bytecode            (210, "bytecode", 1),
329     opc_try                 (211, "try", 0),
330     opc_endtry              (212, "endtry", 0),
331     opc_catch               (213, "catch", 0),
332     opc_var                 (214, "var", 0),
333     opc_endvar              (215, "endvar", 0),
334     opc_locals_map          (216, "locals_map", 0),
335     opc_stack_map           (217, "stack_map", 0),
336     opc_stack_frame_type    (218, "stack_frame_type", 0),
337 
338 
339         // Priv/NonPriv Marker (not really an opcode)
340         opc_nonpriv         (254, "priv", 0),
341         opc_priv            (255, "nonpriv", 0),
342 
343 
344         /* Wide instructions */
345         opc_iload_w                     (opc_iload.value, "iload_w", 4, OpcodeType.WIDE),
346         opc_lload_w                     (opc_lload.value, "lload_w", 4, OpcodeType.WIDE),
347         opc_fload_w                     (opc_fload.value, "fload_w", 4, OpcodeType.WIDE),
348         opc_dload_w                     (opc_dload.value, "dload_w", 4, OpcodeType.WIDE),
349         opc_aload_w                     (opc_aload.value, "aload_w", 4, OpcodeType.WIDE),
350         opc_istore_w                    (opc_istore.value, "istore_w", 4, OpcodeType.WIDE),
351         opc_lstore_w                    (opc_lstore.value, "lstore_w", 4, OpcodeType.WIDE),
352         opc_fstore_w                    (opc_fstore.value, "fstore_w", 4, OpcodeType.WIDE),
353         opc_dstore_w                    (opc_dstore.value, "dstore_w", 4, OpcodeType.WIDE),
354         opc_astore_w                    (opc_astore.value, "astore_w", 4, OpcodeType.WIDE),
355         opc_ret_w                       (opc_ret.value, "ret_w", 4, OpcodeType.WIDE),
356         opc_iinc_w                      (opc_iinc.value, "iinc_w", 6, OpcodeType.WIDE),
357 
358 
359         /* Priveleged instructions */
360     opc_load_ubyte                  (0, "load_ubyte", OpcodeType.NONPRIVELEGED),
361     opc_priv_load_ubyte        (0, "priv_load_ubyte", OpcodeType.PRIVELEGED),
362     opc_load_byte            (1, "load_byte", OpcodeType.NONPRIVELEGED),
363     opc_priv_load_byte        (1, "priv_load_byte", OpcodeType.PRIVELEGED),
364     opc_load_char            (2, "load_char", OpcodeType.NONPRIVELEGED),
365     opc_priv_load_char        (2, "priv_load_char", OpcodeType.PRIVELEGED),
366     opc_load_short            (3, "load_short", OpcodeType.NONPRIVELEGED),
367     opc_priv_load_short        (3, "priv_load_short", OpcodeType.PRIVELEGED),
368     opc_load_word            (4, "load_word", OpcodeType.NONPRIVELEGED),
369     opc_priv_load_word        (4, "priv_load_word", OpcodeType.PRIVELEGED),
370     opc_load_char_oe            (10, "load_char_oe", OpcodeType.NONPRIVELEGED),
371     opc_priv_load_char_oe        (10, "priv_load_char_oe", OpcodeType.PRIVELEGED),
372     opc_load_short_oe        (11, "load_short_oe", OpcodeType.NONPRIVELEGED),
373     opc_priv_load_short_oe        (11, "priv_load_short_oe", OpcodeType.PRIVELEGED),
374     opc_load_word_oe            (12, "load_word_oe", OpcodeType.NONPRIVELEGED),
375     opc_priv_load_word_oe        (12, "priv_load_word_oe", OpcodeType.PRIVELEGED),
376     opc_ncload_ubyte            (16, "ncload_ubyte", OpcodeType.NONPRIVELEGED),
377     opc_priv_ncload_ubyte        (16, "priv_ncload_ubyte", OpcodeType.PRIVELEGED),
378     opc_ncload_byte            (17, "ncload_byte", OpcodeType.NONPRIVELEGED),
379     opc_priv_ncload_byte        (17, "priv_ncload_byte", OpcodeType.PRIVELEGED),
380     opc_ncload_char            (18, "ncload_char", OpcodeType.NONPRIVELEGED),
381     opc_priv_ncload_char        (18, "priv_ncload_char", OpcodeType.PRIVELEGED),
382     opc_ncload_short            (19, "ncload_short", OpcodeType.NONPRIVELEGED),
383     opc_priv_ncload_short        (19, "priv_ncload_short", OpcodeType.PRIVELEGED),
384     opc_ncload_word            (20, "ncload_word", OpcodeType.NONPRIVELEGED),
385     opc_priv_ncload_word        (20, "priv_ncload_word", OpcodeType.PRIVELEGED),
386     opc_ncload_char_oe        (26, "ncload_char_oe", OpcodeType.NONPRIVELEGED),
387     opc_priv_ncload_char_oe        (26, "priv_ncload_char_oe", OpcodeType.PRIVELEGED),
388     opc_ncload_short_oe        (27, "ncload_short_oe", OpcodeType.NONPRIVELEGED),
389     opc_priv_ncload_short_oe        (27, "priv_ncload_short_oe", OpcodeType.PRIVELEGED),
390     opc_ncload_word_oe        (28, "ncload_word_oe", OpcodeType.NONPRIVELEGED),
391     opc_priv_ncload_word_oe        (28, "priv_ncload_word_oe", OpcodeType.PRIVELEGED),
392     opc_cache_flush            (30, "cache_flush", OpcodeType.NONPRIVELEGED),
393     opc_priv_cache_flush        (30, "priv_cache_flush", OpcodeType.PRIVELEGED),
394     opc_store_byte            (32, "store_byte", OpcodeType.NONPRIVELEGED),
395     opc_priv_store_byte        (32, "priv_store_byte", OpcodeType.PRIVELEGED),
396     opc_store_short            (34, "store_short", OpcodeType.NONPRIVELEGED),
397     opc_priv_store_short        (34, "priv_store_short", OpcodeType.PRIVELEGED),
398     opc_store_word            (36, "store_word", OpcodeType.NONPRIVELEGED),
399     opc_priv_store_word        (36, "priv_store_word", OpcodeType.PRIVELEGED),
400     opc_store_short_oe        (42, "store_short_oe", OpcodeType.NONPRIVELEGED),
401     opc_priv_store_short_oe        (42, "priv_store_short_oe", OpcodeType.PRIVELEGED),
402     opc_store_word_oe        (44, "store_word_oe", OpcodeType.NONPRIVELEGED),
403     opc_priv_store_word_oe        (44, "priv_store_word_oe", OpcodeType.PRIVELEGED),
404     opc_ncstore_byte            (48, "ncstore_byte", OpcodeType.NONPRIVELEGED),
405     opc_priv_ncstore_byte        (48, "priv_ncstore_byte", OpcodeType.PRIVELEGED),
406     opc_ncstore_short        (50, "ncstore_short", OpcodeType.NONPRIVELEGED),
407     opc_priv_ncstore_short        (50, "priv_ncstore_short", OpcodeType.PRIVELEGED),
408     opc_ncstore_word        (52, "ncstore_word", OpcodeType.NONPRIVELEGED),
409     opc_priv_ncstore_word        (52, "priv_ncstore_word", OpcodeType.PRIVELEGED),
410     opc_ncstore_short_oe        (58, "ncstore_short_oe", OpcodeType.NONPRIVELEGED),
411     opc_priv_ncstore_short_oe    (58, "priv_ncstore_short_oe", OpcodeType.PRIVELEGED),
412     opc_ncstore_word_oe        (60, "ncstore_word_oe", OpcodeType.NONPRIVELEGED),
413     opc_priv_ncstore_word_oe        (60, "priv_ncstore_word_oe", OpcodeType.PRIVELEGED),
414     opc_zero_line            (62, "zero_line", OpcodeType.NONPRIVELEGED),
415     opc_priv_zero_line        (62, "priv_zero_line", OpcodeType.PRIVELEGED),
416     opc_ret_from_sub            (5, "ret_from_sub", OpcodeType.NONPRIVELEGED),
417     opc_enter_sync_method        (63, "enter_sync_method", OpcodeType.NONPRIVELEGED),
418     opc_priv_ret_from_trap        (5, "priv_ret_from_trap", OpcodeType.PRIVELEGED),
419     opc_priv_read_dcache_tag    (6, "priv_read_dcache_tag", OpcodeType.PRIVELEGED),
420     opc_priv_read_dcache_data    (7, "priv_read_dcache_data", OpcodeType.PRIVELEGED),
421     opc_priv_read_icache_tag    (14, "priv_read_icache_tag", OpcodeType.PRIVELEGED),
422     opc_priv_read_icache_data    (15, "priv_read_icache_data", OpcodeType.PRIVELEGED),
423     opc_priv_powerdown        (22, "priv_powerdown", OpcodeType.PRIVELEGED),
424     opc_priv_read_scache_data    (23, "priv_read_scache_data", OpcodeType.PRIVELEGED),
425     opc_priv_cache_index_flush    (31, "priv_cache_index_flush", OpcodeType.PRIVELEGED),
426     opc_priv_write_dcache_tag    (38, "priv_write_dcache_tag", OpcodeType.PRIVELEGED),
427     opc_priv_write_dcache_data    (39, "priv_write_dcache_data", OpcodeType.PRIVELEGED),
428     opc_priv_write_icache_tag    (46, "priv_write_icache_tag", OpcodeType.PRIVELEGED),
429     opc_priv_write_icache_data    (47, "priv_write_icache_data", OpcodeType.PRIVELEGED),
430     opc_priv_reset            (54, "priv_reset", OpcodeType.PRIVELEGED),
431     opc_priv_write_scache_data    (55, "priv_write_scache_data", OpcodeType.PRIVELEGED),
432     opc_priv_read_reg_0        (64, "priv_read_reg_0", OpcodeType.PRIVELEGED),
433     opc_priv_read_reg_1        (65, "priv_read_reg_1", OpcodeType.PRIVELEGED),
434     opc_priv_read_reg_2        (66, "priv_read_reg_2", OpcodeType.PRIVELEGED),
435     opc_priv_read_reg_3        (67, "priv_read_reg_3", OpcodeType.PRIVELEGED),
436     opc_priv_read_reg_4        (68, "priv_read_reg_4", OpcodeType.PRIVELEGED),
437     opc_priv_read_reg_5        (69, "priv_read_reg_5", OpcodeType.PRIVELEGED),
438     opc_priv_read_reg_6        (70, "priv_read_reg_6", OpcodeType.PRIVELEGED),
439     opc_priv_read_reg_7        (71, "priv_read_reg_7", OpcodeType.PRIVELEGED),
440     opc_priv_read_reg_8        (72, "priv_read_reg_8", OpcodeType.PRIVELEGED),
441     opc_priv_read_reg_9        (73, "priv_read_reg_9", OpcodeType.PRIVELEGED),
442     opc_priv_read_reg_10        (74, "priv_read_reg_10", OpcodeType.PRIVELEGED),
443     opc_priv_read_reg_11        (75, "priv_read_reg_11", OpcodeType.PRIVELEGED),
444     opc_priv_read_reg_12        (76, "priv_read_reg_12", OpcodeType.PRIVELEGED),
445     opc_priv_read_reg_13        (77, "priv_read_reg_13", OpcodeType.PRIVELEGED),
446     opc_priv_read_reg_14        (78, "priv_read_reg_14", OpcodeType.PRIVELEGED),
447     opc_priv_read_reg_15        (79, "priv_read_reg_15", OpcodeType.PRIVELEGED),
448     opc_priv_read_reg_16        (80, "priv_read_reg_16", OpcodeType.PRIVELEGED),
449     opc_priv_read_reg_17        (81, "priv_read_reg_17", OpcodeType.PRIVELEGED),
450     opc_priv_read_reg_18        (82, "priv_read_reg_18", OpcodeType.PRIVELEGED),
451     opc_priv_read_reg_19        (83, "priv_read_reg_19", OpcodeType.PRIVELEGED),
452     opc_priv_read_reg_20        (84, "priv_read_reg_20", OpcodeType.PRIVELEGED),
453     opc_priv_read_reg_21        (85, "priv_read_reg_21", OpcodeType.PRIVELEGED),
454     opc_priv_read_reg_22        (86, "priv_read_reg_22", OpcodeType.PRIVELEGED),
455     opc_priv_read_reg_23        (87, "priv_read_reg_23", OpcodeType.PRIVELEGED),
456     opc_priv_read_reg_24        (88, "priv_read_reg_24", OpcodeType.PRIVELEGED),
457     opc_priv_read_reg_25        (89, "priv_read_reg_25", OpcodeType.PRIVELEGED),
458     opc_priv_read_reg_26        (90, "priv_read_reg_26", OpcodeType.PRIVELEGED),
459     opc_priv_read_reg_27        (91, "priv_read_reg_27", OpcodeType.PRIVELEGED),
460     opc_priv_read_reg_28        (92, "priv_read_reg_28", OpcodeType.PRIVELEGED),
461     opc_priv_read_reg_29        (93, "priv_read_reg_29", OpcodeType.PRIVELEGED),
462     opc_priv_read_reg_30        (94, "priv_read_reg_30", OpcodeType.PRIVELEGED),
463     opc_priv_read_reg_31        (95, "priv_read_reg_31", OpcodeType.PRIVELEGED),
464     opc_priv_write_reg_0        (96, "priv_write_reg_0", OpcodeType.PRIVELEGED),
465     opc_priv_write_reg_1        (97, "priv_write_reg_1", OpcodeType.PRIVELEGED),
466     opc_priv_write_reg_2        (98, "priv_write_reg_2", OpcodeType.PRIVELEGED),
467     opc_priv_write_reg_3        (99, "priv_write_reg_3", OpcodeType.PRIVELEGED),
468     opc_priv_write_reg_4        (100, "priv_write_reg_4", OpcodeType.PRIVELEGED),
469     opc_priv_write_reg_5        (101, "priv_write_reg_5", OpcodeType.PRIVELEGED),
470     opc_priv_write_reg_6        (102, "priv_write_reg_6", OpcodeType.PRIVELEGED),
471     opc_priv_write_reg_7        (103, "priv_write_reg_7", OpcodeType.PRIVELEGED),
472     opc_priv_write_reg_8        (104, "priv_write_reg_8", OpcodeType.PRIVELEGED),
473     opc_priv_write_reg_9        (105, "priv_write_reg_9", OpcodeType.PRIVELEGED),
474     opc_priv_write_reg_10        (106, "priv_write_reg_10", OpcodeType.PRIVELEGED),
475     opc_priv_write_reg_11        (107, "priv_write_reg_11", OpcodeType.PRIVELEGED),
476     opc_priv_write_reg_12        (108, "priv_write_reg_12", OpcodeType.PRIVELEGED),
477     opc_priv_write_reg_13        (109, "priv_write_reg_13", OpcodeType.PRIVELEGED),
478     opc_priv_write_reg_14        (110, "priv_write_reg_14", OpcodeType.PRIVELEGED),
479     opc_priv_write_reg_15        (111, "priv_write_reg_15", OpcodeType.PRIVELEGED),
480     opc_priv_write_reg_16        (112, "priv_write_reg_16", OpcodeType.PRIVELEGED),
481     opc_priv_write_reg_17        (113, "priv_write_reg_17", OpcodeType.PRIVELEGED),
482     opc_priv_write_reg_18        (114, "priv_write_reg_18", OpcodeType.PRIVELEGED),
483     opc_priv_write_reg_19        (115, "priv_write_reg_19", OpcodeType.PRIVELEGED),
484     opc_priv_write_reg_20        (116, "priv_write_reg_20", OpcodeType.PRIVELEGED),
485     opc_priv_write_reg_21        (117, "priv_write_reg_21", OpcodeType.PRIVELEGED),
486     opc_priv_write_reg_22        (118, "priv_write_reg_22", OpcodeType.PRIVELEGED),
487     opc_priv_write_reg_23        (119, "priv_write_reg_23", OpcodeType.PRIVELEGED),
488     opc_priv_write_reg_24        (120, "priv_write_reg_24", OpcodeType.PRIVELEGED),
489     opc_priv_write_reg_25        (121, "priv_write_reg_25", OpcodeType.PRIVELEGED),
490     opc_priv_write_reg_26        (122, "priv_write_reg_26", OpcodeType.PRIVELEGED),
491     opc_priv_write_reg_27        (123, "priv_write_reg_27", OpcodeType.PRIVELEGED),
492     opc_priv_write_reg_28        (124, "priv_write_reg_28", OpcodeType.PRIVELEGED),
493     opc_priv_write_reg_29        (125, "priv_write_reg_29", OpcodeType.PRIVELEGED),
494     opc_priv_write_reg_30        (126, "priv_write_reg_30", OpcodeType.PRIVELEGED),
495     opc_priv_write_reg_31        (127, "priv_write_reg_31", OpcodeType.PRIVELEGED);
496 
497         private Integer value;
498         private String parsekey;
499         private String alias;
500         private Integer length;
501         private Integer baseVal;
502         private OpcodeType type;
503 
504         Opcode(Integer val, String parse, OpcodeType tp) {
505             init(val, parse, null, 2, tp);
506         }
507 
508         Opcode(Integer val, String parse, int len, OpcodeType tp) {
509             init(val, parse, null, len, tp);
510         }
511 
512         Opcode(Integer val, String parse) {
513             init(val, parse, null, 2, OpcodeType.NORMAL);
514         }
515 
516         Opcode(Integer val, String parse, int len) {
517             init(val, parse, null, len, OpcodeType.NORMAL);
518         }
519 
520         Opcode(Integer val, String parse, String als, int len) {
521             init(val, parse, als, len, OpcodeType.NORMAL);
522         }
523 
524         Opcode(Integer val, String parse, String als, int len, OpcodeType tp) {
525             init(val, parse, als, len, tp);
526         }
527 
528         private void init(Integer val, String parse, String als, int len, OpcodeType tp) {
529             type = tp;
530             baseVal = null;
531             switch (tp) {
532                 case NORMAL:
533                     value = val;
534                     break;
535                 case WIDE:
536                     value = (opc_wide.value << 8) | val;
537                     break;
538                 case PRIVELEGED:
539                     value = (opc_priv.value * 0xFF) + val;
540                     baseVal = val;
541                     break;
542                 case NONPRIVELEGED:
543                     value = (opc_nonpriv.value * 0xFF) + val;
544                     baseVal = val;
545                     break;
546             }
547             parsekey = parse;
548             alias = als;
549             length = len;
550         }
551 
552         public Integer value() {
553             return value;
554         }
555 
556         public int length() {
557             return length;
558         }
559 
560         public String parsekey() {
561             return parsekey;
562         }
563 
564         public OpcodeType type() {
565             return type;
566         }
567     }
568 
569 }