From: <cap...@us...> - 2007-04-19 15:35:54
|
Revision: 72 http://svn.sourceforge.net/pearcolator/?rev=72&view=rev Author: captain5050 Date: 2007-04-19 08:35:38 -0700 (Thu, 19 Apr 2007) Log Message: ----------- Support to disassemble instructions as they are ran (rather than just at translate time). Fixes for x86 sysinfo (vdso) page support - disabling vdso for now. Modified Paths: -------------- src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java src/org/binarytranslator/arch/x86/decoder/X862IR.java src/org/binarytranslator/arch/x86/decoder/X86_DecodedOperand.java src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java src/org/binarytranslator/generic/decoder/DecoderUtils.java src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java src/org/binarytranslator/generic/os/process/ProcessSpace.java src/org/binarytranslator/vmInterface/DynamicCodeRunner.java Modified: src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java 2007-04-18 22:26:30 UTC (rev 71) +++ src/org/binarytranslator/arch/arm/os/process/ARM_ProcessSpace.java 2007-04-19 15:35:38 UTC (rev 72) @@ -5,6 +5,7 @@ import org.binarytranslator.arch.arm.decoder.ARM_Interpreter; import org.binarytranslator.arch.arm.os.process.image.ARM_ImageProcessSpace; import org.binarytranslator.arch.arm.os.process.linux.ARM_LinuxProcessSpace; +import org.binarytranslator.arch.x86.decoder.X86_InstructionDecoder; import org.binarytranslator.generic.decoder.Interpreter; import org.binarytranslator.generic.memory.DebugMemory; import org.binarytranslator.generic.os.loader.Loader; @@ -90,6 +91,14 @@ } /** + * Return a string disassembly of the instuction at the given address + */ + @Uninterruptible + public String disassembleInstruction(int pc) { + return "TODO"; + } + + /** * Return as an integer the current instruction's address */ public int getCurrentStackAddress() { Modified: src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java 2007-04-18 22:26:30 UTC (rev 71) +++ src/org/binarytranslator/arch/ppc/os/process/PPC_ProcessSpace.java 2007-04-19 15:35:38 UTC (rev 72) @@ -22,6 +22,7 @@ import org.binarytranslator.vmInterface.DBT_OptimizingCompilerException; import org.jikesrvm.compilers.opt.ir.OPT_GenerationContext; import org.jikesrvm.compilers.opt.ir.OPT_HIRGenerator; +import org.jikesrvm.ppc.PPC_Disassembler; import org.vmmagic.pragma.Uninterruptible; /** @@ -176,6 +177,15 @@ } /** + * Return a string disassembly of the instuction at the given address + */ + @Uninterruptible + public String disassembleInstruction(int pc) { + int instr = memory.load32(pc); + return PPC_Disassembler.disasm(instr, pc); + } + + /** * Return as an integer the current instruction's address */ public int getCurrentStackAddress() { Modified: src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java 2007-04-18 22:26:30 UTC (rev 71) +++ src/org/binarytranslator/arch/ppc/os/process/linux/PPC_LinuxProcessSpace.java 2007-04-19 15:35:38 UTC (rev 72) @@ -16,6 +16,7 @@ import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; import org.binarytranslator.generic.os.abi.linux.LinuxSystemCalls; import org.binarytranslator.generic.os.loader.Loader; +import org.binarytranslator.generic.os.loader.elf.ELF_Loader; import org.binarytranslator.generic.os.process.ProcessSpace; /** @@ -99,12 +100,13 @@ 0x64, LinuxStackInitializer.AuxiliaryVectorType.AT_PHDR, - 0xBADADD8E, // todo + ((ELF_Loader)loader).getProgramHeaderAddress(), + LinuxStackInitializer.AuxiliaryVectorType.AT_PHNUM, + ((ELF_Loader)loader).elfHeader.getNumberOfProgramSegmentHeaders(), LinuxStackInitializer.AuxiliaryVectorType.AT_PHENT, - 0xBAD1BAD1, // todo - LinuxStackInitializer.AuxiliaryVectorType.AT_PHNUM, - 0xBAD2BAD2, // todo - LinuxStackInitializer.AuxiliaryVectorType.AT_BASE, 0x0, + ((ELF_Loader)loader).elfHeader.getProgramSegmentHeaderSize(), + + //LinuxStackInitializer.AuxiliaryVectorType.AT_BASE, 0x0, LinuxStackInitializer.AuxiliaryVectorType.AT_FLAGS, 0x0, LinuxStackInitializer.AuxiliaryVectorType.AT_ENTRY, pc, LinuxStackInitializer.AuxiliaryVectorType.AT_UID, DBT_Options.UID, Modified: src/org/binarytranslator/arch/x86/decoder/X862IR.java =================================================================== --- src/org/binarytranslator/arch/x86/decoder/X862IR.java 2007-04-18 22:26:30 UTC (rev 71) +++ src/org/binarytranslator/arch/x86/decoder/X862IR.java 2007-04-19 15:35:38 UTC (rev 72) @@ -54,12 +54,8 @@ * @return the next instruction address or -1 */ protected int translateInstruction(Laziness lazy, int pc) { - if (pc != 0xffffe400) { - return X86_InstructionDecoder.translateInstruction((X862IR) this, - (X86_ProcessSpace) ps, (X86_Laziness) lazy, pc); - } else { - return plantSystemCallGateEntry((X86_Laziness) lazy, pc); - } + return X86_InstructionDecoder.translateInstruction((X862IR) this, + (X86_ProcessSpace) ps, (X86_Laziness) lazy, pc); } /** Modified: src/org/binarytranslator/arch/x86/decoder/X86_DecodedOperand.java =================================================================== --- src/org/binarytranslator/arch/x86/decoder/X86_DecodedOperand.java 2007-04-18 22:26:30 UTC (rev 71) +++ src/org/binarytranslator/arch/x86/decoder/X86_DecodedOperand.java 2007-04-19 15:35:38 UTC (rev 72) @@ -220,7 +220,11 @@ this.base = base; this.scale = scale; this.index = index; - this.displacement = displacement; + if (segment == X86_Registers.GS){ + this.displacement = displacement + 0xffffe000; + } else { + this.displacement = displacement; + } this.addressSize = addressSize; this.operandSize = operandSize; } Modified: src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java =================================================================== --- src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java 2007-04-18 22:26:30 UTC (rev 71) +++ src/org/binarytranslator/arch/x86/decoder/X86_InstructionDecoder.java 2007-04-19 15:35:38 UTC (rev 72) @@ -21,7 +21,7 @@ /** * Decoder for X86 instructions */ -class X86_InstructionDecoder extends InstructionDecoder { +public class X86_InstructionDecoder extends InstructionDecoder { /* * Process defaults @@ -714,7 +714,7 @@ /** * Get the decoder */ - static X86_InstructionDecoder getDecoder(ProcessSpace ps, int pc) { + public static X86_InstructionDecoder getDecoder(ProcessSpace ps, int pc) { int opcode = ps.memory.loadInstruction8(pc); return primaryOpcodeLookup(opcode).getDecoder(ps, pc, 1, null, null, null, null, null); Modified: src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java 2007-04-18 22:26:30 UTC (rev 71) +++ src/org/binarytranslator/arch/x86/os/process/X86_ProcessSpace.java 2007-04-19 15:35:38 UTC (rev 72) @@ -20,6 +20,7 @@ import org.binarytranslator.generic.fault.BadInstructionException; import org.binarytranslator.arch.x86.os.process.linux.X86_LinuxProcessSpace; import org.binarytranslator.arch.x86.decoder.X862IR; +import org.binarytranslator.arch.x86.decoder.X86_InstructionDecoder; import org.binarytranslator.generic.os.loader.Loader; import org.vmmagic.pragma.Uninterruptible; @@ -183,7 +184,16 @@ public void setCurrentInstructionAddress(int pc) { registers.eip = pc; } + /** + * Return a string disassembly of the instuction at the given address + */ + @Uninterruptible + public String disassembleInstruction(int pc) { + return X86_InstructionDecoder.getDecoder(this,pc).disassemble(this, pc); + } + + /** * Return as an integer the current instruction's address */ public int getCurrentStackAddress() { Modified: src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java =================================================================== --- src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-04-18 22:26:30 UTC (rev 71) +++ src/org/binarytranslator/arch/x86/os/process/linux/X86_LinuxProcessSpace.java 2007-04-19 15:35:38 UTC (rev 72) @@ -16,7 +16,9 @@ import org.binarytranslator.generic.os.abi.linux.LinuxSystemCallGenerator; import org.binarytranslator.generic.os.abi.linux.LinuxSystemCalls; import org.binarytranslator.generic.os.loader.Loader; +import org.binarytranslator.generic.os.loader.elf.ELF_Loader; import org.binarytranslator.generic.os.process.ProcessSpace; +import org.binarytranslator.generic.memory.MemoryMapException; /** * Linux specific parts of the process @@ -61,19 +63,27 @@ registers.eip = pc; this.brk = brk; registers.writeGP32(X86_Registers.ESP, initialiseStack(loader, pc)); + try { + memory.map(0xffffe000, 8192, true, true, true); + } catch (MemoryMapException e) { + throw new Error ("Error creating VDSO page"); + } + memory.store8(0xffffe400, 0xCD); // INT + memory.store8(0xffffe400, 0x80); // 80h + memory.store8(0xffffe400, 0xC3); // RET } /** * Initialise the stack */ private int initialiseStack(Loader loader, int pc) { - int[] auxVector = {LinuxStackInitializer.AuxiliaryVectorType.AT_SYSINFO, 0xffffe400, - LinuxStackInitializer.AuxiliaryVectorType.AT_SYSINFO_EHDR, 0xffffe000, + int[] auxVector = {//LinuxStackInitializer.AuxiliaryVectorType.AT_SYSINFO, 0xffffe400, + //LinuxStackInitializer.AuxiliaryVectorType.AT_SYSINFO_EHDR, 0xffffe000, LinuxStackInitializer.AuxiliaryVectorType.AT_HWCAP, 0x78bfbff, LinuxStackInitializer.AuxiliaryVectorType.AT_PAGESZ, 0x1000, LinuxStackInitializer.AuxiliaryVectorType.AT_CLKTCK, 0x64, - LinuxStackInitializer.AuxiliaryVectorType.AT_PHDR, 0xBADADD8E, - LinuxStackInitializer.AuxiliaryVectorType.AT_PHNUM, 0xBAD2BAD2, + LinuxStackInitializer.AuxiliaryVectorType.AT_PHDR, ((ELF_Loader)loader).getProgramHeaderAddress(), + LinuxStackInitializer.AuxiliaryVectorType.AT_PHNUM, ((ELF_Loader)loader).elfHeader.getNumberOfProgramSegmentHeaders(), LinuxStackInitializer.AuxiliaryVectorType.AT_BASE, 0x0, LinuxStackInitializer.AuxiliaryVectorType.AT_FLAGS, 0x0, LinuxStackInitializer.AuxiliaryVectorType.AT_ENTRY, pc, Modified: src/org/binarytranslator/generic/decoder/DecoderUtils.java =================================================================== --- src/org/binarytranslator/generic/decoder/DecoderUtils.java 2007-04-18 22:26:30 UTC (rev 71) +++ src/org/binarytranslator/generic/decoder/DecoderUtils.java 2007-04-19 15:35:38 UTC (rev 72) @@ -1046,13 +1046,17 @@ * @return true => try to stop the trace */ protected boolean suitableToStop() { - switch (gc.options.getOptLevel()) { - case 0: - return numberOfInstructions > DBT_Options.instrOpt0; - case 1: - return numberOfInstructions > DBT_Options.instrOpt1; - default: - return numberOfInstructions > DBT_Options.instrOpt2; + if (DBT_Options.singleInstrTranslation && (numberOfInstructions >= 1)) { + return true; + } else { + switch (gc.options.getOptLevel()) { + case 0: + return numberOfInstructions > DBT_Options.instrOpt0; + case 1: + return numberOfInstructions > DBT_Options.instrOpt1; + default: + return numberOfInstructions > DBT_Options.instrOpt2; + } } } Modified: src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java =================================================================== --- src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java 2007-04-18 22:26:30 UTC (rev 71) +++ src/org/binarytranslator/generic/os/loader/elf/ELF_Loader.java 2007-04-19 15:35:38 UTC (rev 72) @@ -29,7 +29,7 @@ /** * Header of ELF file */ - private ELF_Header elfHeader; + public ELF_Header elfHeader; /** * Program segment headers @@ -259,6 +259,13 @@ return elfHeader.isARM_ABI(); } + /** + * Where did the program header get loaded in memory? + */ + public int getProgramHeaderAddress() { + return elfHeader.e_phoff - segmentHeaders[0].p_offset + segmentHeaders[0].p_vaddr; + } + /* * Local classes holding structures from the ELF file */ @@ -267,7 +274,7 @@ * Class to read and hold ELF header information */ @SuppressWarnings("unused") - class ELF_Header { + public class ELF_Header { /** * Class to read and hold ELF header indentity information */ @@ -744,7 +751,7 @@ int getEntryPoint() { return e_entry; } - + /** * Program header table file offset */ @@ -760,56 +767,56 @@ /** * Section header table file offset */ - private int e_shoff; + private final int e_shoff; /** * Processor-specific flags */ - private int e_flags; + private final int e_flags; /** * ELF header size in bytes */ - private short e_ehsize; + private final short e_ehsize; /** * Program header table entry size */ - private short e_phentsize; + private final short e_phentsize; /** * What's the size of a program segment header? */ - int getProgramSegmentHeaderSize() { + public int getProgramSegmentHeaderSize() { return e_phentsize; } /** * Program header table entry count */ - private short e_phnum; + private final short e_phnum; /** * How many program segments are in this ELF binary? */ - int getNumberOfProgramSegmentHeaders() { + public int getNumberOfProgramSegmentHeaders() { return e_phnum; } /** * Section header table entry size */ - private short e_shentsize; + private final short e_shentsize; /** * Section header table entry count */ - private short e_shnum; + private final short e_shnum; /** * Section header table index */ - private short e_shstrndx; + private final short e_shstrndx; /** * Construct/read ELF header Modified: src/org/binarytranslator/generic/os/process/ProcessSpace.java =================================================================== --- src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-04-18 22:26:30 UTC (rev 71) +++ src/org/binarytranslator/generic/os/process/ProcessSpace.java 2007-04-19 15:35:38 UTC (rev 72) @@ -138,6 +138,12 @@ public abstract void setCurrentInstructionAddress(int pc); /** + * Return a string disassembly of the instuction at the given address + */ + @Uninterruptible + public abstract String disassembleInstruction(int pc); + + /** * Return as an integer the current instruction's address */ public abstract int getCurrentStackAddress(); Modified: src/org/binarytranslator/vmInterface/DynamicCodeRunner.java =================================================================== --- src/org/binarytranslator/vmInterface/DynamicCodeRunner.java 2007-04-18 22:26:30 UTC (rev 71) +++ src/org/binarytranslator/vmInterface/DynamicCodeRunner.java 2007-04-19 15:35:38 UTC (rev 72) @@ -40,11 +40,12 @@ throws BadInstructionException { // Useful when debugging in GDB: if (DBT_Options.debugRuntime) { + VM.sysWriteln(ps.toString()); + ps.dumpStack(20); VM.sysWrite("Running PC="); VM.sysWriteHex(ps.getCurrentInstructionAddress()); - VM.sysWriteln(); - VM.sysWriteln(ps.toString()); - ps.dumpStack(20); + VM.sysWrite(" "); + VM.sysWriteln(ps.disassembleInstruction(ps.getCurrentInstructionAddress())); VM.sysWrite("About to bridge to "); VM.sysWriteHex(VM_Magic.objectAsAddress(code).toInt()); VM.sysWriteln(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |