diff --git a/source/Cosmos/Cosmos.Kernel/CPU.cs b/source/Cosmos/Cosmos.Kernel/CPU.cs index d47c29190..5f1a1784c 100644 --- a/source/Cosmos/Cosmos.Kernel/CPU.cs +++ b/source/Cosmos/Cosmos.Kernel/CPU.cs @@ -1,11 +1,11 @@ using System; using System.Collections.Generic; using System.Text; +using System.Diagnostics; namespace Cosmos.Kernel { public class CPU { public static unsafe void Init() { - System.Diagnostics.Debugger.Break(); Heap.CheckInit(); Console.Write("Creating GDT..."); Hardware.CPU.CreateGDT(); @@ -84,6 +84,7 @@ namespace Cosmos.Kernel { static unsafe void TestATA() { Hardware.Storage.ATA.Initialize(Sleep); + Debugger.Break(); Hardware.Storage.ATA xDrive = new Cosmos.Hardware.Storage.ATA(0, 0); byte* xBuffer = (byte*)Heap.MemAlloc(512); if (xDrive.ReadBlock(1, xBuffer)) { @@ -95,16 +96,16 @@ namespace Cosmos.Kernel { if (xExt2.Initialize()) { Console.WriteLine("Ext2 Initialized"); } else { - Console.WriteLine("Ext2 Initialization failed!"); + Console.WriteLine("Ext2 Initialization failed!"); } byte[] xItem = xExt2.ReadFile(new string[] { "readme.txt" }); - //if (xItem == null) { - // Console.WriteLine("Couldn't read file!"); - // return; - //} - //Console.Write("File length = "); - //Hardware.Storage.ATAOld.WriteNumber((uint)xItem.Length, 32); - //Console.WriteLine(" bytes"); + if (xItem == null) { + Console.WriteLine("Couldn't read file!"); + return; + } + Console.Write("File length = "); + Hardware.Storage.ATAOld.WriteNumber((uint)xItem.Length, 32); + Console.WriteLine(" bytes"); } } } \ No newline at end of file diff --git a/source/IL2CPU/Program.cs b/source/IL2CPU/Program.cs index 270e020b9..7672b6e44 100644 --- a/source/IL2CPU/Program.cs +++ b/source/IL2CPU/Program.cs @@ -18,7 +18,7 @@ namespace IL2CPU { public static bool MetalMode; public static bool DebugMode = true; public static TargetPlatformEnum TargetPlatform = TargetPlatformEnum.Win32; - public const string LDParamsTemplate_NativeX86 = "-Ttext 0x2000000 -Tdata 0x200000 -e Kernel_Start -o \"{0}\" \"{1}\""; + public const string LDParamsTemplate_NativeX86 = "-Ttext 0x400000 -Tdata 0x200000 -e Kernel_Start -o \"{0}\" \"{1}\""; public const string NAsmParamsTemplate_NativeX86 = "-g -f elf -F stabs -o \"{0}\" \"{1}\""; public const string FAsmParamsTemplate_Win32 = "\"{1}\" \"{0}\""; @@ -30,7 +30,8 @@ namespace IL2CPU { Console.WriteLine("Indy IL2CPU"); Console.WriteLine(); foreach (string x in aArgs) { - if (x[0] != '-') { + // MtW: Slash added for powershell compatibility + if (x[0] != '-' && x[0] != '/') { Console.WriteLine("Error parsing arguments. Arguments should start with a dash ('{0}')", x); return false; } diff --git a/source/Indy.IL2CPU.IL.X86/Ldelem_Any.cs b/source/Indy.IL2CPU.IL.X86/Ldelem_Any.cs index e6add0407..002956b78 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldelem_Any.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldelem_Any.cs @@ -21,7 +21,7 @@ namespace Indy.IL2CPU.IL.X86 { new CPUx86.Pop(CPUx86.Registers.EAX); new CPUx86.Move(CPUx86.Registers.EDX, "0" + aElementSize.ToString("X") + "h"); new CPUx86.Multiply(CPUx86.Registers.EDX); - new CPUx86.Add(CPUx86.Registers.EAX, "0" + (ObjectImpl.FieldDataOffset + 8).ToString("X") + "h"); + new CPUx86.Add(CPUx86.Registers.EAX, "0" + (ObjectImpl.FieldDataOffset + 4).ToString("X") + "h"); new CPUx86.Pop(CPUx86.Registers.EDX); new CPUx86.Add(CPUx86.Registers.EDX, CPUx86.Registers.EAX); new CPUx86.Move(CPUx86.Registers.EAX, CPUx86.Registers.EDX); diff --git a/source/Indy.IL2CPU.IL.X86/Ldelema.cs b/source/Indy.IL2CPU.IL.X86/Ldelema.cs index 300de1f7c..d454a5186 100644 --- a/source/Indy.IL2CPU.IL.X86/Ldelema.cs +++ b/source/Indy.IL2CPU.IL.X86/Ldelema.cs @@ -27,7 +27,7 @@ namespace Indy.IL2CPU.IL.X86 { new CPUx86.Pop(CPUx86.Registers.EAX); new CPUx86.Move(CPUx86.Registers.EDX, "0" + aElementSize.ToString("X") + "h"); new CPUx86.Multiply(CPUx86.Registers.EDX); - new CPUx86.Add(CPUx86.Registers.EAX, "0" + (ObjectImpl.FieldDataOffset + 8).ToString("X") + "h"); + new CPUx86.Add(CPUx86.Registers.EAX, "0" + (ObjectImpl.FieldDataOffset + 4).ToString("X") + "h"); new CPUx86.Pop(CPUx86.Registers.EDX); new CPUx86.Add(CPUx86.Registers.EDX, CPUx86.Registers.EAX); new CPUx86.Pushd(CPUx86.Registers.EDX); diff --git a/source/Indy.IL2CPU.IL.X86/Newarr.cs b/source/Indy.IL2CPU.IL.X86/Newarr.cs index 6b6b095dd..8ddc06bc6 100644 --- a/source/Indy.IL2CPU.IL.X86/Newarr.cs +++ b/source/Indy.IL2CPU.IL.X86/Newarr.cs @@ -45,7 +45,7 @@ namespace Indy.IL2CPU.IL.X86 { Assembler.StackSizes.Push(4); Multiply(Assembler); // the total items size is now on the stack - new CPUx86.Pushd("0x" + (ObjectImpl.FieldDataOffset + 8).ToString("X")); + new CPUx86.Pushd("0x" + (ObjectImpl.FieldDataOffset + 4).ToString("X")); Assembler.StackSizes.Push(4); Add(Assembler); // the total array size is now on the stack. diff --git a/source/Indy.IL2CPU.IL.X86/Newobj.cs b/source/Indy.IL2CPU.IL.X86/Newobj.cs index f267d0f1a..8a2e32a3f 100644 --- a/source/Indy.IL2CPU.IL.X86/Newobj.cs +++ b/source/Indy.IL2CPU.IL.X86/Newobj.cs @@ -6,6 +6,7 @@ using Mono.Cecil.Cil; using CPU = Indy.IL2CPU.Assembler; using CPUx86 = Indy.IL2CPU.Assembler.X86; using Asm = Indy.IL2CPU.Assembler; +using Indy.IL2CPU.Assembler; namespace Indy.IL2CPU.IL.X86 { [OpCode(Code.Newobj, false)] @@ -52,12 +53,15 @@ namespace Indy.IL2CPU.IL.X86 { new Move("dword", "[eax + 4]", "0" + InstanceTypeEnum.NormalObject.ToString("X") + "h"); new Move("dword", "[eax + 8]", "0x" + xGCFieldCount.ToString("X")); if (aCtorDef != null) { + MethodInformation xCtorInfo = Engine.GetMethodInfo(aCtorDef, aCtorDef, Label.GenerateLabelName(aCtorDef), Engine.GetTypeInfo(Engine.GetDefinitionFromTypeReference(aCtorDef.DeclaringType))); + int xSize = (from item in xCtorInfo.Arguments + select item.Size + (item.Size % 4 == 0 ? 0 : (4 - (item.Size % 4)))).Take(xCtorInfo.Arguments.Length - 1).Sum(); for (int i = 0; i < aCtorDef.Parameters.Count; i++) { - new CPUx86.Pushd("[esp + 0x8]"); + new CPUx86.Pushd("[esp + 0x" + (xSize + 4).ToString("X") + "]"); } new CPUx86.Call(CPU.Label.GenerateLabelName(aCtorDef)); new CPUx86.Pop(CPUx86.Registers.EAX); -// aAssembler.StackSizes.Pop(); + // aAssembler.StackSizes.Pop(); for (int i = 0; i < aCtorDef.Parameters.Count; i++) { new CPUx86.Add(CPUx86.Registers.ESP, "4"); aAssembler.StackSizes.Pop(); diff --git a/source/Indy.IL2CPU.IL.X86/Stelem_Any.cs b/source/Indy.IL2CPU.IL.X86/Stelem_Any.cs index 1338d24b7..22488a1f0 100644 --- a/source/Indy.IL2CPU.IL.X86/Stelem_Any.cs +++ b/source/Indy.IL2CPU.IL.X86/Stelem_Any.cs @@ -36,7 +36,7 @@ namespace Indy.IL2CPU.IL.X86 { } new CPUx86.Move(CPUx86.Registers.EBX, "[esp + " + xStackSize + "]"); // the index new CPUx86.Move(CPUx86.Registers.ECX, "[esp + " + (xStackSize + 4) + "]"); // the array - new CPUx86.Add(CPUx86.Registers.ECX, (ObjectImpl.FieldDataOffset + 8).ToString()); + new CPUx86.Add(CPUx86.Registers.ECX, (ObjectImpl.FieldDataOffset + 4).ToString()); new CPUx86.Push("0x" + aElementSize.ToString("X")); aAssembler.StackSizes.Push(4); new CPUx86.Push(CPUx86.Registers.EBX); diff --git a/source/Indy.IL2CPU/CustomImplementation/System/ObjectImpl.cs b/source/Indy.IL2CPU/CustomImplementation/System/ObjectImpl.cs index b872d614d..a7f95dc93 100644 --- a/source/Indy.IL2CPU/CustomImplementation/System/ObjectImpl.cs +++ b/source/Indy.IL2CPU/CustomImplementation/System/ObjectImpl.cs @@ -19,11 +19,11 @@ namespace Indy.IL2CPU { /// /// /// The first 4 bytes are the reference to the type information of the instance, the second 4 bytes - /// are the value. For arrays, there are 4 following bytes containing the element count. - /// and 4 bytes containing the element size. + /// are the value. For arrays, there are 4 following bytes containing the element count, for objects, the amount of reference fields. + /// For arrays, next 4 bytes containing the element size. /// /// - public const int FieldDataOffset = 8; + public const int FieldDataOffset = 12; //[MethodAlias(Name = "System_Void___System_Object__ctor____")] public static void Ctor(IntPtr aThis) { }