0
|
1 /*
|
|
2 * Copyright 2002 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 package sun.jvm.hotspot.asm.sparc;
|
|
26
|
|
27 import sun.jvm.hotspot.asm.*;
|
|
28
|
|
29 // basic instruction decoder class
|
|
30 abstract class InstructionDecoder implements /* imports */ SPARCOpcodes , RTLDataTypes, RTLOperations {
|
|
31 // some general utility functions - for format 2, 3 & 3A instructions
|
|
32
|
|
33 static int extractSignedIntFromNBits(int value, int num_bits) {
|
|
34 return (value << (32 - num_bits)) >> (32 - num_bits);
|
|
35 }
|
|
36
|
|
37 // "rs1"
|
|
38 static int getSourceRegister1(int instruction) {
|
|
39 return (instruction & RS1_MASK) >>> RS1_START_BIT;
|
|
40 }
|
|
41
|
|
42 // "rs2"
|
|
43 static int getSourceRegister2(int instruction) {
|
|
44 return (instruction & RS2_MASK);
|
|
45 }
|
|
46
|
|
47 // "rd"
|
|
48 static int getDestinationRegister(int instruction) {
|
|
49 return (instruction & RD_MASK) >>> RD_START_BIT;
|
|
50 }
|
|
51
|
|
52 static int getConditionCode(int instruction) {
|
|
53 return (instruction & CONDITION_CODE_MASK) >>> CONDITION_CODE_START_BIT;
|
|
54 }
|
|
55
|
|
56 // "i" bit - used to indicate whether second component in an indirect
|
|
57 // address is immediate value or a register. (format 3 & 3A).
|
|
58
|
|
59 static boolean isIBitSet(int instruction) {
|
|
60 return (instruction & I_MASK) != 0;
|
|
61 }
|
|
62
|
|
63 static ImmediateOrRegister getOperand2(int instruction) {
|
|
64 boolean iBit = isIBitSet(instruction);
|
|
65 ImmediateOrRegister operand2 = null;
|
|
66 if (iBit) {
|
|
67 operand2 = new Immediate(new Short((short)extractSignedIntFromNBits(instruction, 13)));
|
|
68 } else {
|
|
69 operand2 = SPARCRegisters.getRegister(getSourceRegister2(instruction));
|
|
70 }
|
|
71 return operand2;
|
|
72 }
|
|
73
|
|
74 // "opf" - floating point operation code.
|
|
75 static int getOpf(int instruction) {
|
|
76 return (instruction & OPF_MASK) >>> OPF_START_BIT;
|
|
77 }
|
|
78
|
|
79 abstract Instruction decode(int instruction, SPARCInstructionFactory factory);
|
|
80 }
|