From 8f52f80e6461217a28128efcb577ec606ceaf2d3 Mon Sep 17 00:00:00 2001
From: kudzu_cp <6d05c8c8ef5431987001abfdb2eadc9593ac9498>
Date: Tue, 12 Jun 2012 22:10:33 +0000
Subject: [PATCH] X#
---
source/Cosmos.sln | 3 +-
source2/Compiler/Cosmos.XSharp/Generator.cs | 16 ++++---
.../Playground.Matthijs.Test.csproj | 14 +++++++
.../Users/Matthijs/MatthijsPlayground/Test.cs | 42 +++++++++++++++++++
4 files changed, 65 insertions(+), 10 deletions(-)
create mode 100644 source2/Users/Matthijs/MatthijsPlayground/Test.cs
diff --git a/source/Cosmos.sln b/source/Cosmos.sln
index 83e18fac3..9dcac5b82 100644
--- a/source/Cosmos.sln
+++ b/source/Cosmos.sln
@@ -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}
diff --git a/source2/Compiler/Cosmos.XSharp/Generator.cs b/source2/Compiler/Cosmos.XSharp/Generator.cs
index 8381125b7..52dcb26a0 100644
--- a/source2/Compiler/Cosmos.XSharp/Generator.cs
+++ b/source2/Compiler/Cosmos.XSharp/Generator.cs
@@ -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() {
diff --git a/source2/Users/Matthijs/MatthijsPlayground/Playground.Matthijs.Test.csproj b/source2/Users/Matthijs/MatthijsPlayground/Playground.Matthijs.Test.csproj
index c7c6ce3da..7c28ea669 100644
--- a/source2/Users/Matthijs/MatthijsPlayground/Playground.Matthijs.Test.csproj
+++ b/source2/Users/Matthijs/MatthijsPlayground/Playground.Matthijs.Test.csproj
@@ -42,8 +42,21 @@
+
+ True
+ True
+ Test.xs
+
+
+ {94D079E4-3C66-486A-8407-EA6EC049FF53}
+ Cosmos.Assembler.x86
+
+
+ {1116130E-28E0-428A-A597-F4B3B676C0CA}
+ Cosmos.Assembler
+
{1FAC100C-D732-4EA4-B518-5AF4BAF64F2E}
Cosmos.Common.Extensions
@@ -68,6 +81,7 @@
CosmosXSharpGenerator
+ Test.cs
diff --git a/source2/Users/Matthijs/MatthijsPlayground/Test.cs b/source2/Users/Matthijs/MatthijsPlayground/Test.cs
new file mode 100644
index 000000000..2a995c031
--- /dev/null
+++ b/source2/Users/Matthijs/MatthijsPlayground/Test.cs
@@ -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 ;
+ }
+ }
+}