diff --git a/source/Indy.IL2CPU.IL.X86.Native/NativeMainEntryMethodOp.cs b/source/Indy.IL2CPU.IL.X86.Native/NativeMainEntryMethodOp.cs index 9607cd8f3..fe25f7f9c 100644 --- a/source/Indy.IL2CPU.IL.X86.Native/NativeMainEntryMethodOp.cs +++ b/source/Indy.IL2CPU.IL.X86.Native/NativeMainEntryMethodOp.cs @@ -12,7 +12,7 @@ namespace Indy.IL2CPU.IL.X86.Native { public override void Enter(string aName) { base.Enter(aName); Pushd("[ebp + 8]"); - Call(NativeOpCodeMap.Instance.GetGlueMethod(Cosmos.Kernel.Boot.Glue.GlueMethodTypeEnum.SaveBootInfoStruct)); + //Call(NativeOpCodeMap.Instance.GetGlueMethod(Cosmos.Kernel.Boot.Glue.GlueMethodTypeEnum.SaveBootInfoStruct)); } public override void Exit() { diff --git a/source/Indy.IL2CPU.IL.X86.Native/NativeOpCodeMap.cs b/source/Indy.IL2CPU.IL.X86.Native/NativeOpCodeMap.cs index bc4184f91..82cb4f7da 100644 --- a/source/Indy.IL2CPU.IL.X86.Native/NativeOpCodeMap.cs +++ b/source/Indy.IL2CPU.IL.X86.Native/NativeOpCodeMap.cs @@ -387,94 +387,94 @@ namespace Indy.IL2CPU.IL.X86.Native { public override void PostProcess(Indy.IL2CPU.Assembler.Assembler aAssembler) { base.PostProcess(aAssembler); - TypeDefinition xRuntimeEngineTypeDef = Engine.GetTypeDefinition(typeof(RuntimeEngineImpl).Assembly.GetName().Name, typeof(RuntimeEngineImpl).FullName); - MethodDefinition xTheMethod = GetGlueMethod(GlueMethodTypeEnum.IDT_SetHandler); - Engine.QueueMethod(xTheMethod); - mIDTSetHandlerMethodName = Label.GenerateLabelName(xTheMethod); - Console.WriteLine("IDTEntry size = {0}", Engine.GetFieldStorageSize(Engine.GetTypeDefinition(typeof(Cosmos.Kernel.Boot.Glue.IDTEntryStruct).Assembly.GetName().Name, typeof(Cosmos.Kernel.Boot.Glue.IDTEntryStruct).FullName))); - X86.X86MethodHeaderOp.AssembleHeader(aAssembler, "___________REGISTER___ISRS_____", new int[0], new MethodInformation.Argument[0]); - string xInterruptHandlerLabel = Label.GenerateLabelName(GetGlueMethod(GlueMethodTypeEnum.IDT_InterruptHandler)); - int[] xInterruptsWithParam = new int[] { 8, 10, 11, 12, 13, 14 }; - for (int i = 0; i < 256; i++) { - new CPU.Pushd("0x" + i.ToString("X")); - new CPU.Pushd("____INTERRUPT_HANDLER___" + i); - new CPU.Pushd("0x08"); - new CPU.Pushd("0x8E"); - new CPU.Call(mIDTSetHandlerMethodName); - } - X86.X86MethodFooterOp.AssembleFooter(0, aAssembler, new MethodInformation.Variable[0], new MethodInformation.Argument[0], 0); - for (int j = 0; j < 256; j++) { - new Label("____INTERRUPT_HANDLER___" + j); - new CPUNative.Cli(); - new CPUNative.Break(); - new CPUNative.Pushad(); - new CPU.Pushd(j.ToString()); - if (!xInterruptsWithParam.Contains(j)/* && !(j >= 0x20 && j <= 0x2F)*/) { - new CPU.Pushd("0"); - } - new CPU.Call(xInterruptHandlerLabel); - new CPUNative.Popad(); - new CPUNative.Break(); - new CPUNative.Sti(); - new CPUNative.IRet(); - } - IEnumerable xAssemblies = Engine.GetAllAssemblies(); - SortedList xResources = new SortedList(); - foreach (AssemblyDefinition xAssembly in xAssemblies) { - foreach (CustomAttribute xAttrib in xAssembly.CustomAttributes) { - if (!xAttrib.Resolved) { - xAttrib.Resolve(); - } - } - IEnumerable> xWantedResources = (from item in xAssembly.CustomAttributes.Cast() - where item.Constructor.DeclaringType.FullName == typeof(KernelResourceAttribute).FullName - select new KeyValuePair((int)item.ConstructorParameters[1], - (string)item.ConstructorParameters[0])); - foreach (KeyValuePair xWantedResource in xWantedResources) { - foreach (ModuleDefinition xModule in xAssembly.Modules) { - foreach (Resource xResource in xModule.Resources) { - if (xResource.Name == xWantedResource.Value) { - EmbeddedResource xEmbedded = xResource as EmbeddedResource; - if (xEmbedded == null) { - throw new Exception("Resource found but was not an embedded resource (Resource Name = '" + xWantedResource.Value + "')"); - } - xResources.Add(xWantedResource.Key, xEmbedded.Data); - } - } - } - } - } - StringBuilder xValue = new StringBuilder(); - DataMember xDataMember; - for (int i = 0; i < xResources.Count; i++) { - xValue.Remove(0, xValue.Length); - xValue.Append("0,0,0,0,2,0,0,0,"); - xValue.Append(BitConverter.GetBytes(xResources.Values[i].Length).Aggregate("", (r, v) => r + v + ",")); - xValue.Append(xResources.Values[i].Aggregate("", (r, v) => r + v + ",")); - xDataMember = new DataMember("embedded_resource_" + xResources.Keys[i] + "_contents", "db", xValue.ToString().TrimEnd(',')); - aAssembler.DataMembers.Add(xDataMember); - } - MethodDefinition xGetResourceMethod = GetGluePlaceholderMethod(GluePlaceholderMethodTypeEnum.GetKernelResource); - MethodInformation xGetResourceMethodInfo = Engine.GetMethodInfo(xGetResourceMethod, xGetResourceMethod, xGetResourceMethod.Name, null); - string xGetResourceLabelName = Label.GenerateLabelName(xGetResourceMethod); - for (int i = 0; i < aAssembler.Instructions.Count; i++) { - if ((aAssembler.Instructions[i] is Label) && ((Label)aAssembler.Instructions[i]).Name == xGetResourceLabelName) { - aAssembler.Instructions.RemoveRange(i, 10); - break; - } - } - NativeMethodHeaderOp.AssembleHeader(aAssembler, xGetResourceLabelName, new int[0], new MethodInformation.Argument[0]); - Op.Ldarg(aAssembler, xGetResourceMethodInfo.Arguments[0]); - new CPU.Pop("eax"); - foreach (int xId in xResources.Keys) { - new CPU.Move("ecx", "0x" + xId.ToString("X")); - new CPU.Compare("eax", "ecx"); - new CPU.JumpIfNotEquals(".__after__" + xId); - new CPU.Push("embedded_resource_" + xId + "_contents"); - new CPU.JumpAlways(".END__OF__METHOD"); - new Label(".__after__" + xId); - } - NativeMethodFooterOp.AssembleFooter(4, aAssembler, new MethodInformation.Variable[0], new MethodInformation.Argument[0], 4); +// TypeDefinition xRuntimeEngineTypeDef = Engine.GetTypeDefinition(typeof(RuntimeEngineImpl).Assembly.GetName().Name, typeof(RuntimeEngineImpl).FullName); +// MethodDefinition xTheMethod = GetGlueMethod(GlueMethodTypeEnum.IDT_SetHandler); +// Engine.QueueMethod(xTheMethod); +// mIDTSetHandlerMethodName = Label.GenerateLabelName(xTheMethod); +// Console.WriteLine("IDTEntry size = {0}", Engine.GetFieldStorageSize(Engine.GetTypeDefinition(typeof(Cosmos.Kernel.Boot.Glue.IDTEntryStruct).Assembly.GetName().Name, typeof(Cosmos.Kernel.Boot.Glue.IDTEntryStruct).FullName))); +// X86.X86MethodHeaderOp.AssembleHeader(aAssembler, "___________REGISTER___ISRS_____", new int[0], new MethodInformation.Argument[0]); +// string xInterruptHandlerLabel = Label.GenerateLabelName(GetGlueMethod(GlueMethodTypeEnum.IDT_InterruptHandler)); +// int[] xInterruptsWithParam = new int[] { 8, 10, 11, 12, 13, 14 }; +// for (int i = 0; i < 256; i++) { +// new CPU.Pushd("0x" + i.ToString("X")); +// new CPU.Pushd("____INTERRUPT_HANDLER___" + i); +// new CPU.Pushd("0x08"); +// new CPU.Pushd("0x8E"); +// new CPU.Call(mIDTSetHandlerMethodName); +// } +// X86.X86MethodFooterOp.AssembleFooter(0, aAssembler, new MethodInformation.Variable[0], new MethodInformation.Argument[0], 0); +// for (int j = 0; j < 256; j++) { +// new Label("____INTERRUPT_HANDLER___" + j); +// new CPUNative.Cli(); +// new CPUNative.Break(); +// new CPUNative.Pushad(); +// new CPU.Pushd(j.ToString()); +// if (!xInterruptsWithParam.Contains(j)/* && !(j >= 0x20 && j <= 0x2F)*/) { +// new CPU.Pushd("0"); +// } +// new CPU.Call(xInterruptHandlerLabel); +// new CPUNative.Popad(); +// new CPUNative.Break(); +// new CPUNative.Sti(); +// new CPUNative.IRet(); +// } +// IEnumerable xAssemblies = Engine.GetAllAssemblies(); +// SortedList xResources = new SortedList(); +// foreach (AssemblyDefinition xAssembly in xAssemblies) { +// foreach (CustomAttribute xAttrib in xAssembly.CustomAttributes) { +// if (!xAttrib.Resolved) { +// xAttrib.Resolve(); +// } +// } +// IEnumerable> xWantedResources = (from item in xAssembly.CustomAttributes.Cast() +// where item.Constructor.DeclaringType.FullName == typeof(KernelResourceAttribute).FullName +// select new KeyValuePair((int)item.ConstructorParameters[1], +// (string)item.ConstructorParameters[0])); +// foreach (KeyValuePair xWantedResource in xWantedResources) { +// foreach (ModuleDefinition xModule in xAssembly.Modules) { +// foreach (Resource xResource in xModule.Resources) { +// if (xResource.Name == xWantedResource.Value) { +// EmbeddedResource xEmbedded = xResource as EmbeddedResource; +// if (xEmbedded == null) { +// throw new Exception("Resource found but was not an embedded resource (Resource Name = '" + xWantedResource.Value + "')"); +// } +// xResources.Add(xWantedResource.Key, xEmbedded.Data); +// } +// } +// } +// } +// } +// StringBuilder xValue = new StringBuilder(); +// DataMember xDataMember; +// for (int i = 0; i < xResources.Count; i++) { +// xValue.Remove(0, xValue.Length); +// xValue.Append("0,0,0,0,2,0,0,0,"); +// xValue.Append(BitConverter.GetBytes(xResources.Values[i].Length).Aggregate("", (r, v) => r + v + ",")); +// xValue.Append(xResources.Values[i].Aggregate("", (r, v) => r + v + ",")); +// xDataMember = new DataMember("embedded_resource_" + xResources.Keys[i] + "_contents", "db", xValue.ToString().TrimEnd(',')); +// aAssembler.DataMembers.Add(xDataMember); +// } +// MethodDefinition xGetResourceMethod = GetGluePlaceholderMethod(GluePlaceholderMethodTypeEnum.GetKernelResource); +// MethodInformation xGetResourceMethodInfo = Engine.GetMethodInfo(xGetResourceMethod, xGetResourceMethod, xGetResourceMethod.Name, null); +// string xGetResourceLabelName = Label.GenerateLabelName(xGetResourceMethod); +// for (int i = 0; i < aAssembler.Instructions.Count; i++) { +// if ((aAssembler.Instructions[i] is Label) && ((Label)aAssembler.Instructions[i]).Name == xGetResourceLabelName) { +// aAssembler.Instructions.RemoveRange(i, 10); +// break; +// } +// } +// NativeMethodHeaderOp.AssembleHeader(aAssembler, xGetResourceLabelName, new int[0], new MethodInformation.Argument[0]); +// Op.Ldarg(aAssembler, xGetResourceMethodInfo.Arguments[0]); +// new CPU.Pop("eax"); +// foreach (int xId in xResources.Keys) { +// new CPU.Move("ecx", "0x" + xId.ToString("X")); +// new CPU.Compare("eax", "ecx"); +// new CPU.JumpIfNotEquals(".__after__" + xId); +// new CPU.Push("embedded_resource_" + xId + "_contents"); +// new CPU.JumpAlways(".END__OF__METHOD"); +// new Label(".__after__" + xId); +// } +// NativeMethodFooterOp.AssembleFooter(4, aAssembler, new MethodInformation.Variable[0], new MethodInformation.Argument[0], 4); } } } \ No newline at end of file diff --git a/source/Indy.IL2CPU.IL.X86.Win32/CustomImplementations/System/ConsoleImpl.cs b/source/Indy.IL2CPU.IL.X86.Win32/CustomImplementations/System/ConsoleImpl.cs index 676b1da72..ff01700a4 100644 --- a/source/Indy.IL2CPU.IL.X86.Win32/CustomImplementations/System/ConsoleImpl.cs +++ b/source/Indy.IL2CPU.IL.X86.Win32/CustomImplementations/System/ConsoleImpl.cs @@ -6,7 +6,7 @@ using System.Text; using Indy.IL2CPU.Plugs; namespace Indy.IL2CPU.IL.X86.Win32.CustomImplementations.System { - //[Plug(Target = typeof(Console))] + [Plug(Target = typeof(Console))] public static class ConsoleImpl { [DllImport("kernel32.dll", CharSet = CharSet.Auto)] static extern unsafe bool WriteConsole(IntPtr hConsoleOutput, uint lpBuffer, diff --git a/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/StringImpl.cs b/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/StringImpl.cs index ca9d30fb0..8ec4dd6b9 100644 --- a/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/StringImpl.cs +++ b/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/StringImpl.cs @@ -24,6 +24,10 @@ namespace Indy.IL2CPU.IL.X86.CustomImplementations.System { aBytes += aIndex; return *aBytes; } + + [PlugMethod(Signature = "System_Void___System_String__cctor____", Scope = PlugScopeEnum.NonMetalOnly)] + public static void CCtor() { + } } [Plug(Target = typeof(Indy.IL2CPU.CustomImplementation.System.StringImpl))] diff --git a/source/Indy.IL2CPU.IL.X86/Op.cs b/source/Indy.IL2CPU.IL.X86/Op.cs index 899695351..267b6e6ad 100644 --- a/source/Indy.IL2CPU.IL.X86/Op.cs +++ b/source/Indy.IL2CPU.IL.X86/Op.cs @@ -21,7 +21,7 @@ namespace Indy.IL2CPU.IL.X86 { new Push(CPUx86.Registers.EAX); } aAssembler.StackSizes.Push(aArg.Size); - if (aAddGCCode && aArg.IsReferenceType && aArg.ArgumentType.FullName != "System.String") { + if (aAddGCCode && aArg.IsReferenceType) { new CPUx86.Push(CPUx86.Registers.EAX); Engine.QueueMethodRef(GCImplementationRefs.IncRefCountRef); new CPUx86.Call(Label.GenerateLabelName(GCImplementationRefs.IncRefCountRef)); @@ -147,7 +147,7 @@ namespace Indy.IL2CPU.IL.X86 { new CPUx86.Push("eax"); } aAssembler.StackSizes.Push(aLocal.Size); - if (aAddGCCode && aLocal.IsReferenceType && aLocal.VariableType.FullName != "System.String") { + if (aAddGCCode && aLocal.IsReferenceType) { new CPUx86.Push("eax"); Engine.QueueMethodRef(GCImplementationRefs.IncRefCountRef); new CPUx86.Call(Label.GenerateLabelName(GCImplementationRefs.IncRefCountRef)); diff --git a/source/Indy.IL2CPU.IL.X86/X86CustomMethodImplementationOp.cs b/source/Indy.IL2CPU.IL.X86/X86CustomMethodImplementationOp.cs index cf82ff42a..2b99a9574 100644 --- a/source/Indy.IL2CPU.IL.X86/X86CustomMethodImplementationOp.cs +++ b/source/Indy.IL2CPU.IL.X86/X86CustomMethodImplementationOp.cs @@ -31,17 +31,17 @@ namespace Indy.IL2CPU.IL.X86 { new Assembler.X86.Move(CPUx86.Registers.EAX, "0"); new Assembler.X86.Move(CPUx86.Registers.EDI, "[" + MethodInfo.Arguments[0].VirtualAddresses[0] + "]"); new Assembler.X86.Move(CPUx86.Registers.ESI, "[" + MethodInfo.Arguments[1].VirtualAddresses[0] + "]"); - new Assembler.X86.Add(CPUx86.Registers.ESI, "8"); - new Assembler.X86.Move(CPUx86.Registers.ECX, CPUx86.Registers.AtESI); - new Assembler.X86.Add(CPUx86.Registers.ESI, "4"); - new Assembler.X86.Add(CPUx86.Registers.EDI, "12"); + new Assembler.X86.Add(CPUx86.Registers.EDI, "8"); + new Assembler.X86.Move(CPUx86.Registers.ECX, CPUx86.Registers.AtEDI); + new Assembler.X86.Add(CPUx86.Registers.EDI, "4"); + new Assembler.X86.Add(CPUx86.Registers.ESI, "12"); new Assembler.Label(".StartLoop"); - new Assembler.X86.Move(CPUx86.Registers.EDX, CPUx86.Registers.AtESI); - new Assembler.X86.Move(CPUx86.Registers.AtEDI, CPUx86.Registers.EDX); - new Assembler.X86.Add(CPUx86.Registers.EAX, "4"); - new Assembler.X86.Add(CPUx86.Registers.ESI, "4"); - new Assembler.X86.Add(CPUx86.Registers.EDI, "4"); + new Assembler.X86.Move("byte", CPUx86.Registers.DL, CPUx86.Registers.AtESI); + new Assembler.X86.Move("byte", CPUx86.Registers.AtEDI, CPUx86.Registers.DL); + new Assembler.X86.Add(CPUx86.Registers.EAX, "1"); + new Assembler.X86.Add(CPUx86.Registers.ESI, "1"); + new Assembler.X86.Add(CPUx86.Registers.EDI, "1"); new Assembler.X86.Compare(CPUx86.Registers.EAX, CPUx86.Registers.ECX); new Assembler.X86.JumpIfEquals(".EndLoop"); new Assembler.X86.JumpAlways(".StartLoop"); diff --git a/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs b/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs index 5bf2721b4..08179b2f0 100644 --- a/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs +++ b/source/Indy.IL2CPU.IL.X86/X86MethodFooterOp.cs @@ -34,12 +34,12 @@ namespace Indy.IL2CPU.IL.X86 { if (!aAssembler.InMetalMode) { Engine.QueueMethodRef(GCImplementationRefs.DecRefCountRef); foreach (MethodInformation.Variable xLocal in aLocals) { - if (xLocal.IsReferenceType && xLocal.VariableType.FullName != "System.String") { + if (xLocal.IsReferenceType) { // System.Diagnostics.Debugger.Break(); TypeSpecification xTypeSpec = xLocal.VariableType as TypeSpecification; if (xTypeSpec != null) { TypeDefinition xElementDef = Engine.GetDefinitionFromTypeReference(xTypeSpec.ElementType); - if ((!xElementDef.IsValueType) && xElementDef.FullName != "System.String") { + if (!xElementDef.IsValueType) { Op.Ldloc(aAssembler, xLocal, false); new CPUx86.Push("8"); Op.Add(aAssembler); @@ -74,7 +74,7 @@ namespace Indy.IL2CPU.IL.X86 { } } foreach (MethodInformation.Argument xArg in aArgs) { - if (xArg.IsReferenceType && xArg.ArgumentType.FullName != "System.String") { + if (xArg.IsReferenceType) { Op.Ldarg(aAssembler, xArg, false); new CPUx86.Call(Label.GenerateLabelName(GCImplementationRefs.DecRefCountRef)); } diff --git a/source/Indy.IL2CPU.IL/OpCodeMap.cs b/source/Indy.IL2CPU.IL/OpCodeMap.cs index 6e60459cf..c57671ea7 100644 --- a/source/Indy.IL2CPU.IL/OpCodeMap.cs +++ b/source/Indy.IL2CPU.IL/OpCodeMap.cs @@ -93,7 +93,6 @@ namespace Indy.IL2CPU.IL { } else { xNotWantedScope = PlugScopeEnum.MetalOnly; } - System.Diagnostics.Debugger.Break(); foreach (AssemblyDefinition xAssemblyDef in GetPlugAssemblies().Union(aPlugs)) { foreach (ModuleDefinition xModuleDef in xAssemblyDef.Modules) { foreach (TypeDefinition xType in (from item in xModuleDef.Types.Cast() @@ -120,8 +119,8 @@ namespace Indy.IL2CPU.IL { } TypeDefinition xReplaceTypeDef = aTypeResolver(xTypeRef); foreach (MethodDefinition xMethod in (from item in xType.Methods.Cast() - where item.IsPublic - select item)) { + select item).Union((from item in xType.Constructors.Cast() + select item))) { CustomAttribute xPlugMethodAttrib = (from item in xMethod.CustomAttributes.Cast() where item.Constructor.DeclaringType.FullName == typeof(PlugMethodAttribute).FullName select item).FirstOrDefault(); diff --git a/source/Indy.IL2CPU/Engine.cs b/source/Indy.IL2CPU/Engine.cs index d4cc627c7..bb16aa8a5 100644 --- a/source/Indy.IL2CPU/Engine.cs +++ b/source/Indy.IL2CPU/Engine.cs @@ -207,11 +207,12 @@ namespace Indy.IL2CPU { xEntryPointOp.Call(RuntimeEngineRefs.InitializeApplicationRef); if (!aInMetalMode) { xEntryPointOp.Call("____INIT__VMT____"); - } - foreach (TypeDefinition xType in mTypes) { - foreach (MethodDefinition xMethod in xType.Constructors) { - if (xMethod.IsStatic) { - xEntryPointOp.Call(xMethod); + + foreach (TypeDefinition xType in mTypes) { + foreach (MethodDefinition xMethod in xType.Constructors) { + if (xMethod.IsStatic) { + xEntryPointOp.Call(xMethod); + } } } } diff --git a/source/Indy.IL2CPU/GCImplementation.cs b/source/Indy.IL2CPU/GCImplementation.cs index 6e91cc4a6..8c5d090c1 100644 --- a/source/Indy.IL2CPU/GCImplementation.cs +++ b/source/Indy.IL2CPU/GCImplementation.cs @@ -30,6 +30,9 @@ namespace Indy.IL2CPU { uint* xTheObject = (uint*)aObject; xTheObject -= 1; if ((*xTheObject & 0x80000000) != 0) { + return; + } + if ((*xTheObject & 0x88888888) != 0) { Console.Write("StaleObject: "); WriteNumber(aObject, false); Console.WriteLine();