Permalink
Browse files

- Initial Commit

  • Loading branch information...
0 parents commit 7c5c29c1281f12e4d597c9ee8db52cd8a140da44 @soywiz committed Mar 30, 2012
@@ -0,0 +1,5 @@
+
+bin
+obj
+TestResults
+*.suo
@@ -0,0 +1,21 @@
+using System;
+using System.IO;
+using DotX86.Core.Cpu.Assembler;
+using DotX86.Core.Cpu.Tables;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace DotX86.Tests
+{
+ [TestClass]
+ public class DisassemblerTest
+ {
+ [TestMethod]
+ public void TestDisassemble()
+ {
+ var Stream = new MemoryStream(new byte[] { 0x50 });
+ var Reader = new BinaryReader(Stream);
+ var Disassembler = new Disassembler();
+ Assert.AreEqual("PUSH AX", Disassembler.Disassemble(InstructionDecoder.DecodeInstruction(Reader)));
+ }
+ }
+}
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <PropertyGroup>
+ <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+ <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+ <ProjectGuid>{FAF8F26E-CB1B-42AE-B725-735FFDB22F5D}</ProjectGuid>
+ <OutputType>Library</OutputType>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <RootNamespace>DotX86.Tests</RootNamespace>
+ <AssemblyName>DotX86.Tests</AssemblyName>
+ <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+ <FileAlignment>512</FileAlignment>
+ <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
+ <TestProjectType>UnitTest</TestProjectType>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>full</DebugType>
+ <Optimize>false</Optimize>
+ <OutputPath>bin\Debug\</OutputPath>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+ <DebugType>pdbonly</DebugType>
+ <Optimize>true</Optimize>
+ <OutputPath>bin\Release\</OutputPath>
+ <DefineConstants>TRACE</DefineConstants>
+ <ErrorReport>prompt</ErrorReport>
+ <WarningLevel>4</WarningLevel>
+ </PropertyGroup>
+ <ItemGroup>
+ <Reference Include="System" />
+ </ItemGroup>
+ <Choose>
+ <When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
+ <ItemGroup>
+ <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
+ </ItemGroup>
+ </When>
+ <Otherwise>
+ <ItemGroup>
+ <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
+ </ItemGroup>
+ </Otherwise>
+ </Choose>
+ <ItemGroup>
+ <Compile Include="DisassemblerTest.cs" />
+ <Compile Include="DynarecTest.cs" />
+ <Compile Include="Properties\AssemblyInfo.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\DotX86\DotX86.csproj">
+ <Project>{5c9f3015-2053-4cf9-8033-ecd1832e7561}</Project>
+ <Name>DotX86</Name>
+ </ProjectReference>
+ </ItemGroup>
+ <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+ <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
+ Other similar extension points exist, see Microsoft.Common.targets.
+ <Target Name="BeforeBuild">
+ </Target>
+ <Target Name="AfterBuild">
+ </Target>
+ -->
+</Project>
@@ -0,0 +1,23 @@
+using System;
+using System.IO;
+using DotX86.Core;
+using DotX86.Core.Cpu;
+using DotX86.Core.Cpu.Dynarec;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace DotX86.Tests
+{
+ [TestClass]
+ public class DynarecTest
+ {
+ [TestMethod]
+ public void TestMethod1()
+ {
+ var CpuContext = new CpuContext();
+ var ThreadContext = new ThreadContext(CpuContext);
+ var MethodGenerator = new MethodGenerator();
+ var Method = MethodGenerator.GenerateMethod(CpuContext, new MemoryStream(new byte[] { 0x50 }));
+ Method(ThreadContext);
+ }
+ }
+}
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("DotX86.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("DotX86.Tests")]
+[assembly: AssemblyCopyright("Copyright © 2012")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("eb8837b6-9dfc-4b90-99dc-8a45740c3ade")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 11
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotX86", "DotX86\DotX86.csproj", "{5C9F3015-2053-4CF9-8033-ECD1832E7561}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DotX86.Tests", "DotX86.Tests\DotX86.Tests.csproj", "{FAF8F26E-CB1B-42AE-B725-735FFDB22F5D}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Any CPU = Debug|Any CPU
+ Release|Any CPU = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {5C9F3015-2053-4CF9-8033-ECD1832E7561}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {5C9F3015-2053-4CF9-8033-ECD1832E7561}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {5C9F3015-2053-4CF9-8033-ECD1832E7561}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {5C9F3015-2053-4CF9-8033-ECD1832E7561}.Release|Any CPU.Build.0 = Release|Any CPU
+ {FAF8F26E-CB1B-42AE-B725-735FFDB22F5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {FAF8F26E-CB1B-42AE-B725-735FFDB22F5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {FAF8F26E-CB1B-42AE-B725-735FFDB22F5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {FAF8F26E-CB1B-42AE-B725-735FFDB22F5D}.Release|Any CPU.Build.0 = Release|Any CPU
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8" ?>
+<configuration>
+ <startup>
+ <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
+ </startup>
+</configuration>
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using DotX86.Core.Cpu.Tables;
+
+namespace DotX86.Core.Cpu.Assembler
+{
+ public enum DisassemblerMode
+ {
+ i386,
+ }
+
+ public class Disassembler
+ {
+ DisassemblerMode Mode;
+
+ public Disassembler(DisassemblerMode Mode = DisassemblerMode.i386)
+ {
+ this.Mode = Mode;
+ }
+
+ public string Disassemble(Instruction Instruction)
+ {
+ switch (Instruction.Type)
+ {
+ case InstructionType.Empty: return String.Format("{0}", Instruction.Opcode);
+ case InstructionType.Register1: return String.Format("{0} {1}", Instruction.Opcode, (ERegister)Instruction.Register1);
+ case InstructionType.Value1: return String.Format("{0} {1}", Instruction.Opcode, Instruction.Value);
+ case InstructionType.Register2: return String.Format("{0} {1}, {2}", Instruction.Opcode, (ERegister)Instruction.Register1, (ERegister)Instruction.Register2);
+ case InstructionType.Register1Value1: return String.Format("{0} {1}, {2}", Instruction.Opcode, (ERegister)Instruction.Register1, Instruction.Value);
+ case InstructionType.Register2Offset: return String.Format("{0} [{1}+{2}], {3}", Instruction.Opcode, (ERegister)Instruction.Register1, (int)Instruction.Value, (ERegister)Instruction.Register2);
+ default: throw(new Exception("Not implemented " + Instruction.Type));
+ }
+ }
+ }
+}
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using DotX86.Core.Cpu.Dynarec;
+
+namespace DotX86.Core.Cpu
+{
+ public class CpuContext
+ {
+ public Memory Memory = new Memory();
+
+ public MethodGenerator MethodGenerator = new MethodGenerator();
+
+ public Action<ThreadContext>[] MethodCache = new Action<ThreadContext>[16 * 1024];
+
+ public Action<ThreadContext> GenerateMethod(uint PC)
+ {
+ return MethodGenerator.GenerateMethod(this, Memory.GetStreamAt(PC));
+ }
+ }
+}
Oops, something went wrong.

0 comments on commit 7c5c29c

Please sign in to comment.