This commit is contained in:
kudzu_cp 2012-06-12 22:10:33 +00:00
parent c5881ca05a
commit 8f52f80e64
4 changed files with 65 additions and 10 deletions

View file

@ -900,6 +900,7 @@ Global
{6882C74B-3ED2-4D76-9E7B-67B6A28808BC}.Builder|x86.ActiveCfg = Release|Any CPU
{6882C74B-3ED2-4D76-9E7B-67B6A28808BC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{6882C74B-3ED2-4D76-9E7B-67B6A28808BC}.Debug|x86.ActiveCfg = Debug|Any CPU
{6882C74B-3ED2-4D76-9E7B-67B6A28808BC}.Debug|x86.Build.0 = Debug|Any CPU
{6882C74B-3ED2-4D76-9E7B-67B6A28808BC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{6882C74B-3ED2-4D76-9E7B-67B6A28808BC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{6882C74B-3ED2-4D76-9E7B-67B6A28808BC}.Release|x86.ActiveCfg = Release|Any CPU
@ -1158,9 +1159,9 @@ Global
{C801F19C-A9D3-42D5-9A57-9FFDF9B4D05E} = {6A15C540-8278-4B9C-B890-FA57FB6AE6A6}
{239E33A7-F0C3-4801-85CA-4D8F89A31DC0} = {6A15C540-8278-4B9C-B890-FA57FB6AE6A6}
{F708C866-1C9B-4579-8C28-0728ECCFC1ED} = {6A15C540-8278-4B9C-B890-FA57FB6AE6A6}
{2A59517C-356E-4B55-B155-50335BF482FB} = {6A15C540-8278-4B9C-B890-FA57FB6AE6A6}
{A281A1B1-C718-4BCB-A7BE-ED840A70449A} = {6A15C540-8278-4B9C-B890-FA57FB6AE6A6}
{7B8499A7-0A8D-44FC-8181-9666CC198025} = {6A15C540-8278-4B9C-B890-FA57FB6AE6A6}
{2A59517C-356E-4B55-B155-50335BF482FB} = {6A15C540-8278-4B9C-B890-FA57FB6AE6A6}
{6658FCE0-7032-4B7B-BD95-F2765C393442} = {2DF5F17F-4890-4856-ADFD-4DE23282C3B7}
{6882C74B-3ED2-4D76-9E7B-67B6A28808BC} = {0CF14D0F-6054-4D3D-9062-E3D2EB064A4E}
{23476FAD-3712-4A4B-90C0-CCCC9AC8D953} = {0CF14D0F-6054-4D3D-9062-E3D2EB064A4E}

View file

@ -20,14 +20,14 @@ namespace Cosmos.Compiler.XSharp {
"new Comment(\"{0}\");");
mPatterns.Add("REG = 123"
, "new Move{{ DestinationReg = RegistersEnum.{0}, SourceValue = {2} }};");
, "new Mov{{ DestinationReg = RegistersEnum.{0}, SourceValue = {2} }};");
mPatterns.Add("REG = REG"
, "new Move{{ DestinationReg = RegistersEnum.{0}, SourceReg = {2} }};");
, "new Mov{{ DestinationReg = RegistersEnum.{0}, SourceReg = RegistersEnum.{2} }};");
mPatterns.Add("REG = REG[0]"
, "new ;");
, "//new ;");
mPatterns.Add("ABC = REG"
, "new ;");
, "//new ;");
// TODO: Allow asm to optimize these to Inc/Dec
mPatterns.Add("REG + 1"
@ -36,7 +36,7 @@ namespace Cosmos.Compiler.XSharp {
, "new Sub {{ DestinationReg = RegistersEnum.{0}, SourceValue = {2} }};");
mPatterns.Add(new TokenType[] { TokenType.OpCode },
"new ;");
"//new ;");
}
public static void Execute(TextReader input, string inputFilename, TextWriter output, string defaultNamespace) {
@ -71,10 +71,8 @@ namespace Cosmos.Compiler.XSharp {
mOutput.WriteLine();
mOutput.WriteLine("namespace {0}", Namespace);
mOutput.WriteLine("{");
mOutput.WriteLine("\tpublic class {0}: Cosmos.IL2CPU.Plugs.AssemblerMethod", Name);
mOutput.WriteLine("\t{");
mOutput.WriteLine("\t\tpublic override void AssembleNew(object aAssembler, object aMethodInfo)");
mOutput.WriteLine("\t\t{");
mOutput.WriteLine("\tpublic class {0} {{", Name);
mOutput.WriteLine("\t\tpublic void Assemble() {");
}
private void EmitFooter() {

View file

@ -42,8 +42,21 @@
<ItemGroup>
<Compile Include="Kernel.cs" />
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Test.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Test.xs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Cosmos.Assembler.X86\Cosmos.Assembler.x86.csproj">
<Project>{94D079E4-3C66-486A-8407-EA6EC049FF53}</Project>
<Name>Cosmos.Assembler.x86</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Cosmos.Assembler\Cosmos.Assembler.csproj">
<Project>{1116130E-28E0-428A-A597-F4B3B676C0CA}</Project>
<Name>Cosmos.Assembler</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\Kernel\Common\Cosmos.Common.Extensions\Cosmos.Common.Extensions.csproj">
<Project>{1FAC100C-D732-4EA4-B518-5AF4BAF64F2E}</Project>
<Name>Cosmos.Common.Extensions</Name>
@ -68,6 +81,7 @@
<ItemGroup>
<None Include="Test.xs">
<Generator>CosmosXSharpGenerator</Generator>
<LastGenOutput>Test.cs</LastGenOutput>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View file

@ -0,0 +1,42 @@
using System;
using System.Linq;
using Cosmos.Assembler;
using Cosmos.Assembler.x86;
namespace MatthijsPlayground
{
public class Test {
public void Assemble() {
new Comment("From Entry.CS");
new Comment("EBP is restored by PopAll, but SendFrame uses it. Could");
new Comment("get it from the PushAll data, but this is easier.");
//new ;
new Comment("Could get ESP from PushAll but this is easier.");
new Comment("Also allows us to use the stack before PushAll if we ever need it.");
new Comment("We cant modify any registers since we havent done PushAll yet");
new Comment("Maybe we could do a sub(4) on memory direct..");
new Comment("But for now we remove from ESP which the Int3 produces,");
new Comment("store ESP, then restore ESP so we don't cause stack corruption.");
new Comment("12 bytes for EFLAGS, CS, EIP");
new Add { DestinationReg = RegistersEnum.ESP, SourceValue = 12 };
//new ;
new Sub { DestinationReg = RegistersEnum.ESP, SourceValue = 12 };
//new ;
new Comment("Save current ESP so we can look at the results of PushAll later");
//new ;
new Comment("Get current ESP and add 32. This will skip over the PushAll and point");
new Comment("us at the call data from Int3.");
new Mov{ DestinationReg = RegistersEnum.EBP, SourceReg = RegistersEnum.ESP };
new Add { DestinationReg = RegistersEnum.EBP, SourceValue = 32 };
new Comment("Caller EIP");
//new ;
new Comment("EIP is pointer to op after our call. Int3 is 1 byte so we subtract 1.");
new Comment("Note - when we used call it was 5 (the size of our call + address)");
new Comment("so we get the EIP as IL2CPU records it. Its also useful for when we");
new Comment("wil be changing ops that call this stub.");
new Sub { DestinationReg = RegistersEnum.EAX, SourceValue = 1 };
new Comment("Store it for later use.");
//new ;
}
}
}