Disabled static constructor calling in metal mode.

This commit is contained in:
mterwoord_cp 2007-11-20 18:16:04 +00:00
parent 5441c24858
commit 97f8349dd7
10 changed files with 119 additions and 112 deletions

View file

@ -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() {

View file

@ -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<AssemblyDefinition> xAssemblies = Engine.GetAllAssemblies();
SortedList<int, byte[]> xResources = new SortedList<int, byte[]>();
foreach (AssemblyDefinition xAssembly in xAssemblies) {
foreach (CustomAttribute xAttrib in xAssembly.CustomAttributes) {
if (!xAttrib.Resolved) {
xAttrib.Resolve();
}
}
IEnumerable<KeyValuePair<int, string>> xWantedResources = (from item in xAssembly.CustomAttributes.Cast<CustomAttribute>()
where item.Constructor.DeclaringType.FullName == typeof(KernelResourceAttribute).FullName
select new KeyValuePair<int, string>((int)item.ConstructorParameters[1],
(string)item.ConstructorParameters[0]));
foreach (KeyValuePair<int, string> 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<AssemblyDefinition> xAssemblies = Engine.GetAllAssemblies();
// SortedList<int, byte[]> xResources = new SortedList<int, byte[]>();
// foreach (AssemblyDefinition xAssembly in xAssemblies) {
// foreach (CustomAttribute xAttrib in xAssembly.CustomAttributes) {
// if (!xAttrib.Resolved) {
// xAttrib.Resolve();
// }
// }
// IEnumerable<KeyValuePair<int, string>> xWantedResources = (from item in xAssembly.CustomAttributes.Cast<CustomAttribute>()
// where item.Constructor.DeclaringType.FullName == typeof(KernelResourceAttribute).FullName
// select new KeyValuePair<int, string>((int)item.ConstructorParameters[1],
// (string)item.ConstructorParameters[0]));
// foreach (KeyValuePair<int, string> 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);
}
}
}

View file

@ -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,

View file

@ -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))]

View file

@ -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));

View file

@ -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");

View file

@ -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));
}

View file

@ -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<TypeDefinition>()
@ -120,8 +119,8 @@ namespace Indy.IL2CPU.IL {
}
TypeDefinition xReplaceTypeDef = aTypeResolver(xTypeRef);
foreach (MethodDefinition xMethod in (from item in xType.Methods.Cast<MethodDefinition>()
where item.IsPublic
select item)) {
select item).Union((from item in xType.Constructors.Cast<MethodDefinition>()
select item))) {
CustomAttribute xPlugMethodAttrib = (from item in xMethod.CustomAttributes.Cast<CustomAttribute>()
where item.Constructor.DeclaringType.FullName == typeof(PlugMethodAttribute).FullName
select item).FirstOrDefault();

View file

@ -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);
}
}
}
}

View file

@ -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();