From: <mic...@us...> - 2007-06-19 09:10:03
|
Revision: 134 http://svn.sourceforge.net/pearcolator/?rev=134&view=rev Author: michael_baer Date: 2007-06-19 02:10:03 -0700 (Tue, 19 Jun 2007) Log Message: ----------- - Made ARM_InstructionVisitor a subclass of ARM_Instructions - Moved decoder utilities class to package generic.decoder Modified Paths: -------------- src/org/binarytranslator/arch/arm/decoder/ARM_Disassembler.java src/org/binarytranslator/arch/arm/decoder/ARM_InstructionDecoder.java src/org/binarytranslator/arch/arm/decoder/ARM_Instructions.java src/org/binarytranslator/arch/arm/decoder/ARM_Interpreter.java Added Paths: ----------- src/org/binarytranslator/generic/decoder/Utils.java Removed Paths: ------------- src/org/binarytranslator/arch/arm/decoder/ARM_InstructionVisitor.java src/org/binarytranslator/arch/arm/decoder/Utils.java Modified: src/org/binarytranslator/arch/arm/decoder/ARM_Disassembler.java =================================================================== --- src/org/binarytranslator/arch/arm/decoder/ARM_Disassembler.java 2007-06-18 17:06:44 UTC (rev 133) +++ src/org/binarytranslator/arch/arm/decoder/ARM_Disassembler.java 2007-06-19 09:10:03 UTC (rev 134) @@ -16,6 +16,7 @@ import org.binarytranslator.arch.arm.decoder.ARM_Instructions.SingleDataTransfer; import org.binarytranslator.arch.arm.decoder.ARM_Instructions.SoftwareInterrupt; import org.binarytranslator.arch.arm.decoder.ARM_Instructions.Swap; +import org.binarytranslator.arch.arm.decoder.ARM_Instructions.ARM_InstructionVisitor; import org.binarytranslator.arch.arm.decoder.ARM_Instructions.Instruction.Condition; import org.binarytranslator.arch.arm.os.process.ARM_ProcessSpace; import org.binarytranslator.generic.decoder.DisassembledInstruction; Modified: src/org/binarytranslator/arch/arm/decoder/ARM_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/arm/decoder/ARM_InstructionDecoder.java 2007-06-18 17:06:44 UTC (rev 133) +++ src/org/binarytranslator/arch/arm/decoder/ARM_InstructionDecoder.java 2007-06-19 09:10:03 UTC (rev 134) @@ -1,6 +1,7 @@ package org.binarytranslator.arch.arm.decoder; import org.binarytranslator.arch.arm.decoder.ARM_Instructions.*; +import org.binarytranslator.generic.decoder.Utils; /** * This class decodes an ARM or Thumb instruction and uses a user-supplied Deleted: src/org/binarytranslator/arch/arm/decoder/ARM_InstructionVisitor.java =================================================================== --- src/org/binarytranslator/arch/arm/decoder/ARM_InstructionVisitor.java 2007-06-18 17:06:44 UTC (rev 133) +++ src/org/binarytranslator/arch/arm/decoder/ARM_InstructionVisitor.java 2007-06-19 09:10:03 UTC (rev 134) @@ -1,22 +0,0 @@ -package org.binarytranslator.arch.arm.decoder; - -import org.binarytranslator.arch.arm.decoder.ARM_Instructions.*; - -/** An interface that supports iterating over ARM instructions using the visitor pattern. */ -public interface ARM_InstructionVisitor { - - void visit(DataProcessing instr); - void visit(SingleDataTransfer instr); - void visit(IntMultiply instr); - void visit(LongMultiply instr); - void visit(Swap instr); - void visit(BlockDataTransfer instr); - void visit(SoftwareInterrupt instr); - void visit(Branch instr); - void visit(BranchExchange instr); - void visit(CoprocessorDataTransfer instr); - void visit(CoprocessorDataProcessing instr); - void visit(CoprocessorRegisterTransfer instr); - void visit(MoveFromStatusRegister instr); - void visit(MoveToStatusRegister instr); -} Modified: src/org/binarytranslator/arch/arm/decoder/ARM_Instructions.java =================================================================== --- src/org/binarytranslator/arch/arm/decoder/ARM_Instructions.java 2007-06-18 17:06:44 UTC (rev 133) +++ src/org/binarytranslator/arch/arm/decoder/ARM_Instructions.java 2007-06-19 09:10:03 UTC (rev 134) @@ -3,6 +3,7 @@ import org.binarytranslator.DBT; import org.binarytranslator.arch.arm.decoder.ARM_Instructions.OperandWrapper.ShiftType; import org.binarytranslator.arch.arm.os.process.ARM_Registers; +import org.binarytranslator.generic.decoder.Utils; /** * In the ARM decoder model, the decoding and usage (translating/interpreting/disassembling) of instructions @@ -1672,4 +1673,22 @@ visitor.visit(this); } } + + public interface ARM_InstructionVisitor { + + void visit(DataProcessing instr); + void visit(SingleDataTransfer instr); + void visit(IntMultiply instr); + void visit(LongMultiply instr); + void visit(Swap instr); + void visit(BlockDataTransfer instr); + void visit(SoftwareInterrupt instr); + void visit(Branch instr); + void visit(BranchExchange instr); + void visit(CoprocessorDataTransfer instr); + void visit(CoprocessorDataProcessing instr); + void visit(CoprocessorRegisterTransfer instr); + void visit(MoveFromStatusRegister instr); + void visit(MoveToStatusRegister instr); + } } Modified: src/org/binarytranslator/arch/arm/decoder/ARM_Interpreter.java =================================================================== --- src/org/binarytranslator/arch/arm/decoder/ARM_Interpreter.java 2007-06-18 17:06:44 UTC (rev 133) +++ src/org/binarytranslator/arch/arm/decoder/ARM_Interpreter.java 2007-06-19 09:10:03 UTC (rev 134) @@ -11,6 +11,7 @@ import org.binarytranslator.arch.arm.os.process.ARM_Registers.OperatingMode; import org.binarytranslator.generic.branch.BranchLogic.BranchType; import org.binarytranslator.generic.decoder.Interpreter; +import org.binarytranslator.generic.decoder.Utils; import com.sun.org.apache.bcel.internal.generic.InstructionFactory; Deleted: src/org/binarytranslator/arch/arm/decoder/Utils.java =================================================================== --- src/org/binarytranslator/arch/arm/decoder/Utils.java 2007-06-18 17:06:44 UTC (rev 133) +++ src/org/binarytranslator/arch/arm/decoder/Utils.java 2007-06-19 09:10:03 UTC (rev 134) @@ -1,196 +0,0 @@ -package org.binarytranslator.arch.arm.decoder; - -import org.binarytranslator.DBT; - -public class Utils { - - /** - * Checks if a bit is set within a word. - * @param word - * The word that is being examined. - * @param bit - * The number of the bit that is to be checked, starting from zero. - * @return - * True, if the given bit is set within the word, false otherwise. - */ - static final boolean getBit(int word, int bit) { - if (DBT.VerifyAssertions) - DBT._assert(bit >= 0 && bit <= 31); - return (word & (1 << bit)) != 0; - } - - /** - * Same functions as {@link #getBit(int, int)} for shorts. - */ - static final boolean getBit(short word, int bit) { - if (DBT.VerifyAssertions) - DBT._assert(bit >= 0 && bit <= 15); - return (word & (1 << bit)) != 0; - } - - /** - * Extracts a subsequence of bits from a word and shifts the beginning of that subsequence to - * a zero based-number. - * A call to <code>getBits(0xFF, 2, 3)</code> would return 0x3. - * @param word - * The word that is to be examined. - * @param from - * The first bit (starting from 0) that is to be extracted. - * @param to - * The last bit (starting from 0) that is to be extracted from the word. - * @return - * A zero-based version of the bit sequence. - */ - static final int getBits(int word, int from, int to) { - if (DBT.VerifyAssertions) - DBT._assert(from < to && from >= 0 && to < 31); - - return (word & ((1 << (to + 1)) - 1)) >> from; - } - - /** - * Same function as {@link #getBits(int, int, int)} for shorts. - */ - static final int getBits(short word, int from, int to) { - if (DBT.VerifyAssertions) - DBT._assert(from < to && from >= 0 && to <= 15); - - return (word & ((1 << (to + 1)) - 1)) >> from; - } - - /** - * Sign extends a given value. - * @param value - * The value to sign extends. - * @param bitsUsed - * The number bits used within this value. - * @return - * A sign extended value. - */ - static int signExtend(int value, int bitsUsed) { - return (value << (32 - bitsUsed)) >> (32 - bitsUsed); - } - - /** - * Returns true, if the addition of both operands as unsigned integers will cause an overflow. - * At the moment, this converts both values to longs and checks if the 33rd bit (which actually represents the carry) - * overflows. - */ - public static boolean unsignedAddOverflow(int operand1, int operand2) { - long value1 = (long)operand1 & 0xFFFFFFFFL; - long value2 = (long)operand2 & 0xFFFFFFFFL; - - return ((value1 + value2) & 0x100000000L) != 0; - } - - /** - * Returns true, if the subtraction of both operand1 - operand2 (both unsigned) will issue a borrow. - */ - public static boolean unsignedSubOverflow(int operand1, int operand2) { - operand1 += Integer.MIN_VALUE; - operand2 += Integer.MIN_VALUE; - - return operand1 < operand2; - } - - /** - * Returns true, if the addition of both operands as signed integers will cause an overflow. - * This basically checks <code>operand1 + operand2 > Integer.MAX_VALUE</code>. - */ - public static boolean signedAddOverflow(int operand1, int operand2) { - return operand1 > Integer.MAX_VALUE - operand2; - } - - /** - * Returns true, if the subtraction of operand1 from operand (as signed integers) - * will cause an overflow. - * This basically checks <code>operand1 - operand2 < Integer.MIN_VALUE</code>. - */ - public static boolean signedSubOverflow(int operand1, int operand2) { - // if the MSB is already set in any of the operands, then no overflow can - // occur - if (operand1 >= 0) { - return (operand2 < 0) && ((operand1-operand2) < 0); - } - else { - return (operand2 > 0) && ((operand1-operand2) > 0); - } - } - - /** - * Performs a number of sanity tests that make sure that the above functions are working the - * manner described before.*/ - public static void runSanityTests() { - if (!Utils.unsignedAddOverflow(1, -1)) { - throw new RuntimeException("Error"); - } - - if (!Utils.unsignedAddOverflow(-1, -1)) { - throw new RuntimeException("Error"); - } - - if (!Utils.unsignedAddOverflow(-1, 1)) { - throw new RuntimeException("Error"); - } - - if (Utils.unsignedAddOverflow(10000, 10000)) { - throw new RuntimeException("Error"); - } - - if (Utils.unsignedSubOverflow(-1, 1)) { - throw new RuntimeException("Error"); - } - - if (!Utils.unsignedSubOverflow(1, -1)) { - throw new RuntimeException("Error"); - } - - if (Utils.unsignedSubOverflow(-1, -1)) { - throw new RuntimeException("Error"); - } - - if (Utils.unsignedSubOverflow(10, 0)) { - throw new RuntimeException("Error"); - } - - if (!Utils.unsignedSubOverflow(0, 10)) { - throw new RuntimeException("Error"); - } - - if (!Utils.signedAddOverflow(0x70000000, 0x10000000)) { - throw new RuntimeException("Error"); - } - - if (Utils.signedAddOverflow(0x90000000, 0x10000000)) { - throw new RuntimeException("Error"); - } - - if (!Utils.signedAddOverflow(0x50000000, 0x50000000)) { - throw new RuntimeException("Error"); - } - - if (Utils.signedAddOverflow(0x60000000, 0x10000000)) { - throw new RuntimeException("Error"); - } - - if (Utils.signedAddOverflow(0x10000000, 0x60000000)) { - throw new RuntimeException("Error"); - } - - if (!Utils.signedSubOverflow(0x80000000, 0x30000000)) { - throw new RuntimeException("Error"); - } - - if (!Utils.signedSubOverflow(0x30000000, 0x80000000)) { - throw new RuntimeException("Error"); - } - - if (!Utils.signedSubOverflow(0, 0x80000000)) { - throw new RuntimeException("Error"); - } - - if (Utils.signedSubOverflow(0, 0x70000000)) { - throw new RuntimeException("Error"); - } - } -} Copied: src/org/binarytranslator/generic/decoder/Utils.java (from rev 133, src/org/binarytranslator/arch/arm/decoder/Utils.java) =================================================================== --- src/org/binarytranslator/generic/decoder/Utils.java (rev 0) +++ src/org/binarytranslator/generic/decoder/Utils.java 2007-06-19 09:10:03 UTC (rev 134) @@ -0,0 +1,196 @@ +package org.binarytranslator.generic.decoder; + +import org.binarytranslator.DBT; + +public class Utils { + + /** + * Checks if a bit is set within a word. + * @param word + * The word that is being examined. + * @param bit + * The number of the bit that is to be checked, starting from zero. + * @return + * True, if the given bit is set within the word, false otherwise. + */ + public static final boolean getBit(int word, int bit) { + if (DBT.VerifyAssertions) + DBT._assert(bit >= 0 && bit <= 31); + return (word & (1 << bit)) != 0; + } + + /** + * Same functions as {@link #getBit(int, int)} for shorts. + */ + public static final boolean getBit(short word, int bit) { + if (DBT.VerifyAssertions) + DBT._assert(bit >= 0 && bit <= 15); + return (word & (1 << bit)) != 0; + } + + /** + * Extracts a subsequence of bits from a word and shifts the beginning of that subsequence to + * a zero based-number. + * A call to <code>getBits(0xFF, 2, 3)</code> would return 0x3. + * @param word + * The word that is to be examined. + * @param from + * The first bit (starting from 0) that is to be extracted. + * @param to + * The last bit (starting from 0) that is to be extracted from the word. + * @return + * A zero-based version of the bit sequence. + */ + public static final int getBits(int word, int from, int to) { + if (DBT.VerifyAssertions) + DBT._assert(from < to && from >= 0 && to < 31); + + return (word & ((1 << (to + 1)) - 1)) >> from; + } + + /** + * Same function as {@link #getBits(int, int, int)} for shorts. + */ + public static final int getBits(short word, int from, int to) { + if (DBT.VerifyAssertions) + DBT._assert(from < to && from >= 0 && to <= 15); + + return (word & ((1 << (to + 1)) - 1)) >> from; + } + + /** + * Sign extends a given value. + * @param value + * The value to sign extends. + * @param bitsUsed + * The number bits used within this value. + * @return + * A sign extended value. + */ + public static int signExtend(int value, int bitsUsed) { + return (value << (32 - bitsUsed)) >> (32 - bitsUsed); + } + + /** + * Returns true, if the addition of both operands as unsigned integers will cause an overflow. + * At the moment, this converts both values to longs and checks if the 33rd bit (which actually represents the carry) + * overflows. + */ + public static boolean unsignedAddOverflow(int operand1, int operand2) { + long value1 = (long)operand1 & 0xFFFFFFFFL; + long value2 = (long)operand2 & 0xFFFFFFFFL; + + return ((value1 + value2) & 0x100000000L) != 0; + } + + /** + * Returns true, if the subtraction of both operand1 - operand2 (both unsigned) will issue a borrow. + */ + public static boolean unsignedSubOverflow(int operand1, int operand2) { + operand1 += Integer.MIN_VALUE; + operand2 += Integer.MIN_VALUE; + + return operand1 < operand2; + } + + /** + * Returns true, if the addition of both operands as signed integers will cause an overflow. + * This basically checks <code>operand1 + operand2 > Integer.MAX_VALUE</code>. + */ + public static boolean signedAddOverflow(int operand1, int operand2) { + return operand1 > Integer.MAX_VALUE - operand2; + } + + /** + * Returns true, if the subtraction of operand1 from operand (as signed integers) + * will cause an overflow. + * This basically checks <code>operand1 - operand2 < Integer.MIN_VALUE</code>. + */ + public static boolean signedSubOverflow(int operand1, int operand2) { + // if the MSB is already set in any of the operands, then no overflow can + // occur + if (operand1 >= 0) { + return (operand2 < 0) && ((operand1-operand2) < 0); + } + else { + return (operand2 > 0) && ((operand1-operand2) > 0); + } + } + + /** + * Performs a number of sanity tests that make sure that the above functions are working the + * manner described before.*/ + public static void runSanityTests() { + if (!Utils.unsignedAddOverflow(1, -1)) { + throw new RuntimeException("Error"); + } + + if (!Utils.unsignedAddOverflow(-1, -1)) { + throw new RuntimeException("Error"); + } + + if (!Utils.unsignedAddOverflow(-1, 1)) { + throw new RuntimeException("Error"); + } + + if (Utils.unsignedAddOverflow(10000, 10000)) { + throw new RuntimeException("Error"); + } + + if (Utils.unsignedSubOverflow(-1, 1)) { + throw new RuntimeException("Error"); + } + + if (!Utils.unsignedSubOverflow(1, -1)) { + throw new RuntimeException("Error"); + } + + if (Utils.unsignedSubOverflow(-1, -1)) { + throw new RuntimeException("Error"); + } + + if (Utils.unsignedSubOverflow(10, 0)) { + throw new RuntimeException("Error"); + } + + if (!Utils.unsignedSubOverflow(0, 10)) { + throw new RuntimeException("Error"); + } + + if (!Utils.signedAddOverflow(0x70000000, 0x10000000)) { + throw new RuntimeException("Error"); + } + + if (Utils.signedAddOverflow(0x90000000, 0x10000000)) { + throw new RuntimeException("Error"); + } + + if (!Utils.signedAddOverflow(0x50000000, 0x50000000)) { + throw new RuntimeException("Error"); + } + + if (Utils.signedAddOverflow(0x60000000, 0x10000000)) { + throw new RuntimeException("Error"); + } + + if (Utils.signedAddOverflow(0x10000000, 0x60000000)) { + throw new RuntimeException("Error"); + } + + if (!Utils.signedSubOverflow(0x80000000, 0x30000000)) { + throw new RuntimeException("Error"); + } + + if (!Utils.signedSubOverflow(0x30000000, 0x80000000)) { + throw new RuntimeException("Error"); + } + + if (!Utils.signedSubOverflow(0, 0x80000000)) { + throw new RuntimeException("Error"); + } + + if (Utils.signedSubOverflow(0, 0x70000000)) { + throw new RuntimeException("Error"); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |