From 0ef92f6d22b06baaf0a70d5511ea40e9cf6540f2 Mon Sep 17 00:00:00 2001
From: mterwoord_cp <7cd3fd84a0151ea055c2f79e4d2eef9576fe9afesxUZAwxD>
Date: Thu, 25 Feb 2010 07:44:06 +0000
Subject: [PATCH]
---
source/Cosmos.Kernel.FileSystems/ext2/Ext2.cs | 10 +--
source/Cosmos.sln | 15 +++-
source/Cosmos/Cosmos.Hardware/DebugUtil.cs | 2 +-
source/Cosmos/Cosmos.Hardware/Global.cs | 6 +-
.../Cosmos/Cosmos.Hardware/Storage/ATA/ATA.cs | 4 +-
.../Cosmos/Cosmos.Kernel/Cosmos.Kernel.csproj | 2 +
source/Cosmos/Cosmos.System/VFSManager.cs | 7 +-
source/MatthijsTest/Program.cs | 36 ++++++---
.../AssemblerNasmTests.cs | 31 ++++++++
.../Cosmos.IL2CPU.X86.Tests.csproj | 77 +++++++++++++++++++
.../Cosmos.IL2CPU.X86.Tests.csproj.vspscc | 10 +++
.../Properties/AssemblyInfo.cs | 36 +++++++++
.../IL2PCU/Cosmos.IL2CPU.X86/AssemblerNasm.cs | 48 +++++++++---
.../Cosmos.IL2CPU.X86/CosmosAssembler.cs | 2 +-
.../IL2PCU/Cosmos.IL2CPU.X86/IL/Callvirt.cs | 11 ++-
source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldarg.cs | 8 ++
source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldfld.cs | 15 ++--
source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldflda.cs | 15 ++--
source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldloca.cs | 6 +-
source2/IL2PCU/Cosmos.IL2CPU.X86/ILOp.cs | 9 ++-
.../Cosmos.IL2CPU/Assembler/Assembler.cs | 8 +-
.../CustomImplementation/System/Int64Impl.cs | 15 ++--
.../CustomImplementation/System/UInt64Impl.cs | 2 +-
source2/IL2PCU/Cosmos.IL2CPU/ILOp.cs | 4 +
source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs | 6 ++
25 files changed, 312 insertions(+), 73 deletions(-)
create mode 100644 source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/AssemblerNasmTests.cs
create mode 100644 source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/Cosmos.IL2CPU.X86.Tests.csproj
create mode 100644 source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/Cosmos.IL2CPU.X86.Tests.csproj.vspscc
create mode 100644 source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/Properties/AssemblyInfo.cs
diff --git a/source/Cosmos.Kernel.FileSystems/ext2/Ext2.cs b/source/Cosmos.Kernel.FileSystems/ext2/Ext2.cs
index 9d8ca6128..4a662aa58 100644
--- a/source/Cosmos.Kernel.FileSystems/ext2/Ext2.cs
+++ b/source/Cosmos.Kernel.FileSystems/ext2/Ext2.cs
@@ -295,10 +295,10 @@ namespace Cosmos.Sys.FileSystem.Ext2 {
}
public static bool BlockDeviceContainsExt2(BlockDevice aDevice) {
- byte[] xBuffer = new byte[aDevice.BlockSize];
- // todo: implement better detection
- try
+ if (aDevice.BlockCount > 3)
{
+ byte[] xBuffer = new byte[aDevice.BlockSize];
+ // todo: implement better detection
aDevice.ReadBlock(2,
xBuffer);
Hardware.DebugUtil.WriteBinary("Ext2",
@@ -308,9 +308,7 @@ namespace Cosmos.Sys.FileSystem.Ext2 {
4);
return xBuffer[56] == 0x53 && xBuffer[57] == 0xEF;
}
- catch {
- return false;
- }
+ return false;
}
}
}
\ No newline at end of file
diff --git a/source/Cosmos.sln b/source/Cosmos.sln
index 129d0c8b3..a229dfd86 100644
--- a/source/Cosmos.sln
+++ b/source/Cosmos.sln
@@ -239,6 +239,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TempVSIP", "..\source2\VSIP
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Reynaldo", "Reynaldo", "{B8406314-B724-410E-8C79-E2C187ACDC65}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.IL2CPU.X86.Tests", "..\source2\IL2PCU\Cosmos.IL2CPU.X86.Tests\Cosmos.IL2CPU.X86.Tests.csproj", "{52BF0A64-EBEF-420A-9F27-6C5226A4B77B}"
+EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "KebinuChiousu", "KebinuChiousu", "{22BCACD7-7E12-47D3-B3F2-77B8C0D0CB6F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.UnitTests.Kernel", "Cosmos.UnitTests.Kernel\Cosmos.UnitTests.Kernel.csproj", "{75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C}"
@@ -247,7 +249,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.UnitTests", "Cosmos.
EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
- SccNumberOfProjects = 74
+ SccNumberOfProjects = 75
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://tfs04.codeplex.com/
SccLocalPath0 = .
@@ -543,6 +545,10 @@ Global
SccProjectTopLevelParentUniqueName73 = Cosmos.sln
SccProjectName73 = ../source2/VSIP/TempVSIP
SccLocalPath73 = ..\\source2\\VSIP\\TempVSIP
+ SccProjectUniqueName74 = ..\\source2\\IL2PCU\\Cosmos.IL2CPU.X86.Tests\\Cosmos.IL2CPU.X86.Tests.csproj
+ SccProjectTopLevelParentUniqueName74 = Cosmos.sln
+ SccProjectName74 = ../source2/IL2PCU/Cosmos.IL2CPU.X86.Tests
+ SccLocalPath74 = ..\\source2\\IL2PCU\\Cosmos.IL2CPU.X86.Tests
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -1119,6 +1125,12 @@ Global
{54C786E5-FD14-4036-92AE-E9F25B71534B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{54C786E5-FD14-4036-92AE-E9F25B71534B}.Release|Any CPU.Build.0 = Release|Any CPU
{54C786E5-FD14-4036-92AE-E9F25B71534B}.Release|x86.ActiveCfg = Release|Any CPU
+ {52BF0A64-EBEF-420A-9F27-6C5226A4B77B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {52BF0A64-EBEF-420A-9F27-6C5226A4B77B}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {52BF0A64-EBEF-420A-9F27-6C5226A4B77B}.Debug|x86.ActiveCfg = Debug|Any CPU
+ {52BF0A64-EBEF-420A-9F27-6C5226A4B77B}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {52BF0A64-EBEF-420A-9F27-6C5226A4B77B}.Release|Any CPU.Build.0 = Release|Any CPU
+ {52BF0A64-EBEF-420A-9F27-6C5226A4B77B}.Release|x86.ActiveCfg = Release|Any CPU
{75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{75CEC24E-04AB-4CF4-A0CE-1400E78CDE8C}.Debug|x86.ActiveCfg = Debug|Any CPU
@@ -1240,6 +1252,7 @@ Global
{239E33A7-F0C3-4801-85CA-4D8F89A31DC0} = {35CABD9D-5C85-419A-B6C9-561EAD97A553}
{F708C866-1C9B-4579-8C28-0728ECCFC1ED} = {35CABD9D-5C85-419A-B6C9-561EAD97A553}
{63F7BFB9-419E-4965-B580-304B9C9FA7D8} = {35CABD9D-5C85-419A-B6C9-561EAD97A553}
+ {52BF0A64-EBEF-420A-9F27-6C5226A4B77B} = {35CABD9D-5C85-419A-B6C9-561EAD97A553}
{6658FCE0-7032-4B7B-BD95-F2765C393442} = {2DF5F17F-4890-4856-ADFD-4DE23282C3B7}
{0F641748-FF03-4DA7-981B-1E9268330EE5} = {856EAFB8-D13E-4690-9ED8-6B5622D6AA41}
{D89DE0D3-FF3E-4F63-B15F-7302D998845E} = {856EAFB8-D13E-4690-9ED8-6B5622D6AA41}
diff --git a/source/Cosmos/Cosmos.Hardware/DebugUtil.cs b/source/Cosmos/Cosmos.Hardware/DebugUtil.cs
index ab1b712c2..d3aea0917 100644
--- a/source/Cosmos/Cosmos.Hardware/DebugUtil.cs
+++ b/source/Cosmos/Cosmos.Hardware/DebugUtil.cs
@@ -1,4 +1,4 @@
-//#define WRITE_TO_DEBUG
+#define WRITE_TO_DEBUG
using System;
using System.Collections.Generic;
using System.Text;
diff --git a/source/Cosmos/Cosmos.Hardware/Global.cs b/source/Cosmos/Cosmos.Hardware/Global.cs
index 5d7575e6a..f783fef18 100644
--- a/source/Cosmos/Cosmos.Hardware/Global.cs
+++ b/source/Cosmos/Cosmos.Hardware/Global.cs
@@ -20,12 +20,12 @@ namespace Cosmos.Hardware {
//HW.Interrupts.IRQ01 += new Interrupts.InterruptDelegate(Cosmos.Hardware.Keyboard.HandleKeyboardInterrupt);
Console.WriteLine(" Init IRQ");
Interrupts.Init();
- Kernel.CPU.CreateIDT(true);
+ Kernel.CPU.CreateIDT(false);
//Doku: See ACPIManager class
//Console.WriteLine(" Init ACPI");
//ACPIManager.Init();
-
+
Console.WriteLine(" Init PCIBus");
PCIBus.Init();
@@ -40,7 +40,7 @@ namespace Cosmos.Hardware {
Mouse.Initialize();
// New
Console.WriteLine(" Init ATA");
- //Storage.ATA.ATA.Initialize();
+ Storage.ATA.ATA.Initialize();
//Device.Add(new PC.Bus.CPU.Keyboard());
Network.Devices.RTL8139.RTL8139.InitDriver();
diff --git a/source/Cosmos/Cosmos.Hardware/Storage/ATA/ATA.cs b/source/Cosmos/Cosmos.Hardware/Storage/ATA/ATA.cs
index a288d1f64..7b6dfe2de 100644
--- a/source/Cosmos/Cosmos.Hardware/Storage/ATA/ATA.cs
+++ b/source/Cosmos/Cosmos.Hardware/Storage/ATA/ATA.cs
@@ -274,8 +274,8 @@ namespace Cosmos.Hardware.Storage.ATA
// end wait 400ns
if (IOReadByte((ushort)(GetControllerAddress1(xControllerBaseAIdx) + ATA_STATUS)) == 0x50)
{
- ATA xATA;
- Device.Add(xATA = new ATA(String.Concat(mControllerNumbers[xControllerBaseAIdx], " ", mDriveNames[xDrive]), xControllerBaseAIdx, xDrive));
+ ATA xATA = xATA = new ATA(String.Concat(mControllerNumbers[xControllerBaseAIdx], " ", mDriveNames[xDrive]), xControllerBaseAIdx, xDrive);
+ Device.Add(xATA);
DebugUtil.SendNumber("ATA", "Device Size", (uint)xATA.BlockCount, 32);
Console.WriteLine(" Found");
diff --git a/source/Cosmos/Cosmos.Kernel/Cosmos.Kernel.csproj b/source/Cosmos/Cosmos.Kernel/Cosmos.Kernel.csproj
index 081ddd2bf..ade2b3d67 100644
--- a/source/Cosmos/Cosmos.Kernel/Cosmos.Kernel.csproj
+++ b/source/Cosmos/Cosmos.Kernel/Cosmos.Kernel.csproj
@@ -65,6 +65,8 @@
3.5
+
+
diff --git a/source/Cosmos/Cosmos.System/VFSManager.cs b/source/Cosmos/Cosmos.System/VFSManager.cs
index d4a9b5545..da5130628 100644
--- a/source/Cosmos/Cosmos.System/VFSManager.cs
+++ b/source/Cosmos/Cosmos.System/VFSManager.cs
@@ -31,17 +31,16 @@ namespace Cosmos.Sys {
}
mFilesystems = new List(4);
for (int i = 0; i < Device.Devices.Count; i++) {
+ Console.WriteLine("Check device: " + i);
var xDevice = Device.Devices[i];
if (xDevice.Type != Device.DeviceType.Storage) {
continue;
}
- var xStorageDevice = xDevice as BlockDevice;
- if (xStorageDevice == null) {
- continue;
- }
+ var xStorageDevice = (BlockDevice)xDevice;
if (xStorageDevice.Used) {
continue;
}
+ Console.WriteLine("Detect Filesystem");
DetectFilesystem(xStorageDevice);
}
Hardware.DebugUtil.SendNumber("VFS",
diff --git a/source/MatthijsTest/Program.cs b/source/MatthijsTest/Program.cs
index 30acd372c..92706022b 100644
--- a/source/MatthijsTest/Program.cs
+++ b/source/MatthijsTest/Program.cs
@@ -24,25 +24,41 @@ namespace MatthijsTest
}
#endregion
- private static NetworkDevice mNet;
+ public class TestBase
+ {
+ public virtual long GetValue(){
+ return 43;
+ }
+ }
+
+ public class TestDerived: TestBase
+ {
+ public override long GetValue()
+ {
+ return 86;
+ }
+ }
public static unsafe void Init()
{
- var xInit = false;
+ var xInit = true;
if (xInit)
{
var xBoot = new Cosmos.Sys.Boot();
- xBoot.Execute(true);
+ xBoot.Execute(false);
}
- int xValue = 43;
- Console.Write("Value = ");
- Console.WriteLine((object)xValue);
- Console.Write("Value2 = ");
- Console.WriteLine(xValue.ToString());
- Console.Write("Value2 = ");
- Console.WriteLine(xValue);
+ //int xCount = 0;
+ //for (int i = 0; i < Device.Devices.Count; i++)
+ //{
+ // if (Device.Devices[i] is BlockDevice)
+ // {
+ // xCount++;
+ // }
+ //}
+
+ //Console.WriteLine("Number of BlockDevices: " + xCount);
//ulong a = 1;
//ulong b = 2;
diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/AssemblerNasmTests.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/AssemblerNasmTests.cs
new file mode 100644
index 000000000..e2eafeb25
--- /dev/null
+++ b/source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/AssemblerNasmTests.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using NUnit.Framework;
+
+namespace Cosmos.IL2CPU.X86.Tests
+{
+ [TestFixture]
+ public class AssemblerNasmTests
+ {
+ [Test]
+ public void Test()
+ {
+ // public static int Test()
+ Assert.AreEqual(8, AssemblerNasm.GetResultCodeOffset(4, 0), "static int Test()");
+ // public static int Test(int)
+ Assert.AreEqual(8, AssemblerNasm.GetResultCodeOffset(4, 4), "static int Test(int)");
+ // public static long Test()
+ Assert.AreEqual(8, AssemblerNasm.GetResultCodeOffset(8, 0), "static long Test()");
+ // public static long Test(int)
+ Assert.AreEqual(8, AssemblerNasm.GetResultCodeOffset(8, 4), "static long Test(int)");
+ // public static int Test(long)
+ Assert.AreEqual(12, AssemblerNasm.GetResultCodeOffset(4, 8), "static int Test(long)");
+ // public static int Test(long,long)
+ Assert.AreEqual(20, AssemblerNasm.GetResultCodeOffset(4, 16), "static int Test(long,long)");
+ // public static long Test(long,long)
+ Assert.AreEqual(16, AssemblerNasm.GetResultCodeOffset(8, 16), "static long Test(long,long)");
+ }
+ }
+}
\ No newline at end of file
diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/Cosmos.IL2CPU.X86.Tests.csproj b/source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/Cosmos.IL2CPU.X86.Tests.csproj
new file mode 100644
index 000000000..1b2cd61e9
--- /dev/null
+++ b/source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/Cosmos.IL2CPU.X86.Tests.csproj
@@ -0,0 +1,77 @@
+
+
+
+ Debug
+ AnyCPU
+ 9.0.30729
+ 2.0
+ {52BF0A64-EBEF-420A-9F27-6C5226A4B77B}
+ Library
+ Properties
+ Cosmos.IL2CPU.X86.Tests
+ Cosmos.IL2CPU.X86.Tests
+ v3.5
+ 512
+ SAK
+ SAK
+ SAK
+ SAK
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+ False
+ ..\..\..\source\libraries\nunit\nunit.framework.dll
+
+
+
+ 3.5
+
+
+ 3.5
+
+
+ 3.5
+
+
+
+
+
+
+
+
+
+
+ {63F7BFB9-419E-4965-B580-304B9C9FA7D8}
+ Cosmos.IL2CPU.X86
+
+
+ {239E33A7-F0C3-4801-85CA-4D8F89A31DC0}
+ Cosmos.IL2CPU
+
+
+
+
+
\ No newline at end of file
diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/Cosmos.IL2CPU.X86.Tests.csproj.vspscc b/source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/Cosmos.IL2CPU.X86.Tests.csproj.vspscc
new file mode 100644
index 000000000..feffdecaa
--- /dev/null
+++ b/source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/Cosmos.IL2CPU.X86.Tests.csproj.vspscc
@@ -0,0 +1,10 @@
+""
+{
+"FILE_VERSION" = "9237"
+"ENLISTMENT_CHOICE" = "NEVER"
+"PROJECT_FILE_RELATIVE_PATH" = ""
+"NUMBER_OF_EXCLUDED_FILES" = "0"
+"ORIGINAL_PROJECT_FILE_PATH" = ""
+"NUMBER_OF_NESTED_PROJECTS" = "0"
+"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
+}
diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/Properties/AssemblyInfo.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/Properties/AssemblyInfo.cs
new file mode 100644
index 000000000..20459cb3d
--- /dev/null
+++ b/source2/IL2PCU/Cosmos.IL2CPU.X86.Tests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Cosmos.IL2CPU.X86.Tests")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("Cosmos.IL2CPU.X86.Tests")]
+[assembly: AssemblyCopyright("Copyright © 2010")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components. If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("9b85ad8d-1182-4542-ac51-a392a82bd562")]
+
+// Version information for an assembly consists of the following four values:
+//
+// Major Version
+// Minor Version
+// Build Number
+// Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/AssemblerNasm.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/AssemblerNasm.cs
index bc31a3b29..0c4ef93fd 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU.X86/AssemblerNasm.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/AssemblerNasm.cs
@@ -84,6 +84,10 @@ namespace Cosmos.IL2CPU.X86 {
}
protected override void MethodEnd(MethodInfo aMethod) {
+ if (Label.GetFullName(aMethod.MethodBase) == "System_String__System_Int64_ToString__")
+ {
+ Console.Write("");
+ }
base.MethodEnd(aMethod);
uint xReturnSize = 0;
var xMethInfo = aMethod.MethodBase as System.Reflection.MethodInfo;
@@ -95,7 +99,14 @@ namespace Cosmos.IL2CPU.X86 {
var xTotalArgsSize = (from item in aMethod.MethodBase.GetParameters()
select (int)ILOp.Align(ILOp.SizeOfType(item.ParameterType), 4)).Sum();
if (!aMethod.MethodBase.IsStatic) {
- xTotalArgsSize += (int)ILOp.Align(ILOp.SizeOfType(aMethod.MethodBase.DeclaringType), 4);
+ if (aMethod.MethodBase.DeclaringType.IsValueType)
+ {
+ xTotalArgsSize += 4; // only a reference is passed
+ }
+ else
+ {
+ xTotalArgsSize += (int)ILOp.Align(ILOp.SizeOfType(aMethod.MethodBase.DeclaringType), 4);
+ }
}
if (aMethod.PluggedMethod != null) {
@@ -107,7 +118,14 @@ namespace Cosmos.IL2CPU.X86 {
xTotalArgsSize = (from item in aMethod.PluggedMethod.MethodBase.GetParameters()
select (int)ILOp.Align(ILOp.SizeOfType(item.ParameterType), 4)).Sum();
if (!aMethod.PluggedMethod.MethodBase.IsStatic) {
- xTotalArgsSize += (int)ILOp.Align(ILOp.SizeOfType(aMethod.PluggedMethod.MethodBase.DeclaringType), 4);
+ if (aMethod.PluggedMethod.MethodBase.DeclaringType.IsValueType)
+ {
+ xTotalArgsSize += 4; // only a reference is passed
+ }
+ else
+ {
+ xTotalArgsSize += (int)ILOp.Align(ILOp.SizeOfType(aMethod.PluggedMethod.MethodBase.DeclaringType), 4);
+ }
}
}
@@ -123,20 +141,21 @@ namespace Cosmos.IL2CPU.X86 {
// xArgSize -= xReturnSize;
// xOffset = xArgSize;
//}
- int xOffset = 4;
- xOffset += xTotalArgsSize;
- if ((xTotalArgsSize - xReturnSize) < 0) {
- //xOffset += (int)(0 - (xTotalArgsSize - xReturnSize));
- xOffset = 8;
- }
+ var xOffset = GetResultCodeOffset(xReturnSize, (uint)xTotalArgsSize);
for (int i = 0; i < xReturnSize / 4; i++) {
new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX };
new CPUx86.Move {
DestinationReg = CPUx86.Registers.EBP,
DestinationIsIndirect = true,
- DestinationDisplacement = (int)(xOffset + ((i + 1) * 4) + 0 - xReturnSize),
+ DestinationDisplacement = (int)(xOffset + ((i + 0) * 4)),
SourceReg = Registers.EAX
};
+ // new CPUx86.Move {
+ // DestinationReg = CPUx86.Registers.EBP,
+ // DestinationIsIndirect = true,
+ // DestinationDisplacement = (int)(xOffset + ((i + 1) * 4) + 4 - xReturnSize),
+ // SourceReg = Registers.EAX
+ // };
}
// extra stack space is the space reserved for example when a "public static int TestMethod();" method is called, 4 bytes is pushed, to make room for result;
}
@@ -201,6 +220,17 @@ namespace Cosmos.IL2CPU.X86 {
new CPUx86.Return { DestinationValue = (uint)xRetSize };
}
+ public static uint GetResultCodeOffset(uint aResultSize, uint aTotalArgumentSize)
+ {
+ uint xOffset = 8;
+ if ((aTotalArgumentSize > 0) && (aTotalArgumentSize >= aResultSize))
+ {
+ xOffset += aTotalArgumentSize;
+ xOffset -= aResultSize;
+ }
+ return xOffset;
+ }
+
private static ISymbolReader GetSymbolReaderForAssembly(Assembly aAssembly)
{
try
diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/CosmosAssembler.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/CosmosAssembler.cs
index e9bf14978..6167d9bde 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU.X86/CosmosAssembler.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/CosmosAssembler.cs
@@ -297,7 +297,7 @@ namespace Cosmos.IL2CPU.X86
protected override void Ldflda(MethodInfo aMethod, string aFieldId)
{
- IL.Ldflda.DoExecute(this, aMethod, aMethod.MethodBase.DeclaringType, aFieldId);
+ IL.Ldflda.DoExecute(this, aMethod, aMethod.MethodBase.DeclaringType, aFieldId, false);
}
//// todo: remove when everything goes fine
diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Callvirt.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Callvirt.cs
index cd0bdd240..c226bff00 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Callvirt.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Callvirt.cs
@@ -23,6 +23,7 @@ namespace Cosmos.IL2CPU.X86.IL
public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
{
var xOpMethod = aOpCode as OpMethod;
+ string xCurrentMethodLabel = GetLabel(aMethod, aOpCode.Position);
DoExecute(Assembler, aMethod, xOpMethod.Value, xOpMethod.ValueUID, aOpCode.Position);
}
@@ -57,7 +58,7 @@ namespace Cosmos.IL2CPU.X86.IL
uint xThisOffset = 0;
var xParameters = aTargetMethod.GetParameters();
foreach (var xItem in xParameters) {
- xThisOffset += Align(SizeOfType(xItem.GetType()), 4);
+ xThisOffset += Align(SizeOfType(xItem.ParameterType), 4);
Assembler.Stack.Pop();
}
if (!aTargetMethod.IsStatic) {
@@ -71,8 +72,8 @@ namespace Cosmos.IL2CPU.X86.IL
// Can we add this method info somehow to the data passed in?
// mThisOffset = mTargetMethodInfo.Arguments[0].Offset;
- if (xExtraStackSize > 0) {
- xThisOffset -= xExtraStackSize;
+ if (xExtraStackSize > 0) {
+ //xThisOffset -= xExtraStackSize;
}
new Comment(Assembler, "ThisOffset = " + xThisOffset);
@@ -122,6 +123,10 @@ namespace Cosmos.IL2CPU.X86.IL
DestinationLabel = MethodInfoLabelGenerator.GenerateLabelName(VTablesImplRefs.GetMethodAddressForTypeRef)
};
+ if (xExtraStackSize > 0)
+ {
+ xThisOffset -= xExtraStackSize;
+ }
/*
* On the stack now:
* $esp Params
diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldarg.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldarg.cs
index 4c5e5a0e7..48324370a 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldarg.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldarg.cs
@@ -79,11 +79,19 @@ namespace Cosmos.IL2CPU.X86.IL
} else {
if (aParam == 0) {
xArgType = aMethod.MethodBase.DeclaringType;
+ if (xArgType.IsValueType)
+ {
+ xArgType = xArgType.MakeByRefType();
+ }
} else {
xArgType = aMethod.MethodBase.GetParameters()[aParam - 1].ParameterType;
}
}
+ new Comment("Ldarg");
+ new Comment("Arg idx = " + aParam);
xArgSize = Align(SizeOfType(xArgType), 4);
+ new Comment("Arg type = " + xArgType.ToString());
+ new Comment("Arg size = " + xArgSize);
for (int i = 0; i < (xArgSize / 4); i++) {
new Push {
DestinationReg = Registers.EBP,
diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldfld.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldfld.cs
index 23fe7671a..5d49852fd 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldfld.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldfld.cs
@@ -46,7 +46,7 @@ namespace Cosmos.IL2CPU.X86.IL
public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
{
var xOpCode = (ILOpCodes.OpField)aOpCode;
- DoExecute(Assembler, xOpCode.Value.DeclaringType, xOpCode.Value.GetFullName());
+ DoExecute(Assembler, xOpCode.Value.DeclaringType, xOpCode.Value.GetFullName(), true);
}
public static int GetFieldOffset(Type aDeclaringType, string aFieldId) {
int xExtraOffset = 0;
@@ -61,7 +61,7 @@ namespace Cosmos.IL2CPU.X86.IL
return (int)(xExtraOffset + xFieldInfo.Offset);
}
- public static void DoExecute(Assembler Assembler, Type aDeclaringType, string xFieldId) {
+ public static void DoExecute(Assembler Assembler, Type aDeclaringType, string xFieldId, bool aDerefExternalField) {
Assembler.Stack.Pop();
var xOffset = GetFieldOffset(aDeclaringType, xFieldId);
var xFields = GetFieldsInfo(aDeclaringType);
@@ -75,12 +75,11 @@ namespace Cosmos.IL2CPU.X86.IL
new CPUx86.Add { DestinationReg = CPUx86.Registers.ECX, SourceValue = (uint)(xOffset) };
- //if( aField.IsExternalField/* && aDerefExternalField */)
- //{
- // new CPUx86.Move { DestinationReg = CPUx86.Registers.ECX, SourceReg = CPUx86.Registers.ECX, SourceIsIndirect = true };
- //}
- //*******
-
+ if( xFieldInfo.IsExternalValue && aDerefExternalField)
+ {
+ new CPUx86.Move { DestinationReg = CPUx86.Registers.ECX, SourceReg = CPUx86.Registers.ECX, SourceIsIndirect = true };
+ }
+
for (int i = 1; i <= (xSize / 4); i++) {
new CPUx86.Move { DestinationReg = CPUx86.Registers.EAX, SourceReg = CPUx86.Registers.ECX, SourceIsIndirect = true, SourceDisplacement = (int)(xSize - (i * 4)) };
new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX };
diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldflda.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldflda.cs
index 82dd13d88..1b624fa84 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldflda.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldflda.cs
@@ -14,10 +14,10 @@ namespace Cosmos.IL2CPU.X86.IL
public override void Execute( MethodInfo aMethod, ILOpCode aOpCode )
{
var xOpCode = (ILOpCodes.OpField)aOpCode;
- DoExecute(Assembler, aMethod, xOpCode.Value.DeclaringType, xOpCode.Value.GetFullName());
+ DoExecute(Assembler, aMethod, xOpCode.Value.DeclaringType, xOpCode.Value.GetFullName(), true);
}
- public static void DoExecute(Assembler Assembler, MethodInfo aMethod, Type aDeclaringType, string aField) {
+ public static void DoExecute(Assembler Assembler, MethodInfo aMethod, Type aDeclaringType, string aField, bool aDerefValue) {
var xFields = GetFieldsInfo(aDeclaringType);
var xFieldInfo = (from item in xFields
@@ -41,12 +41,11 @@ namespace Cosmos.IL2CPU.X86.IL
new CPUx86.Add { DestinationReg = CPUx86.Registers.EAX, SourceValue = (uint)(xActualOffset) };
Assembler.Stack.Pop();
Assembler.Stack.Push(new StackContents.Item(4, xType));
-#warning TODO: Implement Plugs
- //if( aDerefExternalAddress && aField.IsExternalField )
- //{
- // new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX, DestinationIsIndirect = true };
- //}
- //else
+ if(aDerefValue && xFieldInfo.IsExternalValue )
+ {
+ new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX, DestinationIsIndirect = true };
+ }
+ else
{
new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX };
}
diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldloca.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldloca.cs
index 5f99d3c79..7be641be3 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldloca.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/IL/Ldloca.cs
@@ -12,9 +12,13 @@ namespace Cosmos.IL2CPU.X86.IL {
public override void Execute(MethodInfo aMethod, ILOpCode aOpCode) {
var xOpVar = (OpVar)aOpCode;
var xAddress = GetEBPOffsetForLocal(aMethod, xOpVar);
+ if (aMethod.MethodBase.Name == "Init" && aMethod.MethodBase.DeclaringType.Name == "Program")
+ {
+ Console.Write("");
+ }
+ xAddress += (GetStackCountForLocal(aMethod, aMethod.MethodBase.GetMethodBody().LocalVariables[xOpVar.Value]) - 1) * 4;
// xAddress contains full size of locals, excluding the actual local
- xAddress = xAddress;
new CPUx86.Move {
DestinationReg = CPUx86.Registers.EAX,
SourceReg = CPUx86.Registers.EBP
diff --git a/source2/IL2PCU/Cosmos.IL2CPU.X86/ILOp.cs b/source2/IL2PCU/Cosmos.IL2CPU.X86/ILOp.cs
index 7909d318c..5b9c721f5 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU.X86/ILOp.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU.X86/ILOp.cs
@@ -42,10 +42,11 @@ namespace Cosmos.IL2CPU.X86 {
var xBody = aMethod.MethodBase.GetMethodBody();
uint xOffset = 4;
for (int i = 0; i < xBody.LocalVariables.Count; i++) {
- if (i == aOp.Value) {
- break;
- }
- var xField = xBody.LocalVariables[i];
+ if (i == aOp.Value)
+ {
+ break;
+ }
+ var xField = xBody.LocalVariables[i];
xOffset += GetStackCountForLocal(aMethod, xField) * 4;
}
return xOffset;
diff --git a/source2/IL2PCU/Cosmos.IL2CPU/Assembler/Assembler.cs b/source2/IL2PCU/Cosmos.IL2CPU/Assembler/Assembler.cs
index 9eea0ea48..645a10d65 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU/Assembler/Assembler.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU/Assembler/Assembler.cs
@@ -702,10 +702,10 @@ namespace Cosmos.IL2CPU {
xParams = aFrom.MethodBase.GetParameters();
}
- if (aFrom.MethodBase.GetParameters().Length > 0 || !aFrom.MethodBase.IsStatic) {
- Ldarg(aFrom, 0);
- Pop();
- }
+ //if (aFrom.MethodBase.GetParameters().Length > 0 || !aFrom.MethodBase.IsStatic) {
+ // Ldarg(aFrom, 0);
+ // Pop();
+ //}
int xCurParamIdx = 0;
if (!aFrom.MethodBase.IsStatic) {
diff --git a/source2/IL2PCU/Cosmos.IL2CPU/CustomImplementation/System/Int64Impl.cs b/source2/IL2PCU/Cosmos.IL2CPU/CustomImplementation/System/Int64Impl.cs
index 2ea361e2f..8effbea84 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU/CustomImplementation/System/Int64Impl.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU/CustomImplementation/System/Int64Impl.cs
@@ -6,7 +6,7 @@ using Cosmos.IL2CPU.Plugs;
namespace Cosmos.IL2CPU.IL.CustomImplementations.System {
// Not supported yet, so commentd out.
- //[Plug(Target = typeof(Int64))]
+ [Plug(Target = typeof(Int64))]
public class Int64Impl {
public static string ToString(ref long aThis) {
return Int64Impl2.GetNumberString(aThis);
@@ -16,12 +16,13 @@ namespace Cosmos.IL2CPU.IL.CustomImplementations.System {
// See note in UInt32Impl2
public class Int64Impl2 {
public static string GetNumberString(long aValue) {
- bool xIsNegative = false;
- if (aValue < 0) {
- xIsNegative = true;
- aValue *= -1;
- }
- return UInt64Impl2.GetNumberString((ulong)aValue, xIsNegative);
+ bool xIsNegative = false;
+ if (aValue < 0)
+ {
+ xIsNegative = true;
+ aValue *= -1;
+ }
+ return UInt64Impl2.GetNumberString((ulong)aValue, xIsNegative);
}
}
}
diff --git a/source2/IL2PCU/Cosmos.IL2CPU/CustomImplementation/System/UInt64Impl.cs b/source2/IL2PCU/Cosmos.IL2CPU/CustomImplementation/System/UInt64Impl.cs
index 7b2300106..5086e4380 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU/CustomImplementation/System/UInt64Impl.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU/CustomImplementation/System/UInt64Impl.cs
@@ -6,7 +6,7 @@ using Cosmos.IL2CPU.Plugs;
namespace Cosmos.IL2CPU.IL.CustomImplementations.System {
// Not supported yet
- //[Plug(Target = typeof(UInt64))]
+ [Plug(Target = typeof(UInt64))]
public class UInt64Impl {
public static string ToString(ref ulong aThis) {
return UInt64Impl2.GetNumberString(aThis, false);
diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILOp.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILOp.cs
index f510e8f31..0af051cd4 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU/ILOp.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU/ILOp.cs
@@ -56,6 +56,10 @@ namespace Cosmos.IL2CPU {
} else if ((!aType.IsValueType && aType.IsClass) || aType.IsInterface) {
return 4;
}
+ if (aType.IsByRef)
+ {
+ return 4;
+ }
switch (aType.FullName) {
case "System.Char":
return 2;
diff --git a/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs b/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs
index a05524227..1f252a5bd 100644
--- a/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs
+++ b/source2/IL2PCU/Cosmos.IL2CPU/ILScanner.cs
@@ -375,6 +375,12 @@ namespace Cosmos.IL2CPU {
// mAsmblr.GenerateVMTCode(mTypes, mTypesSet, mKnownMethods);
+
+ // dump all methods to temp file.
+ File.WriteAllLines(@"e:\methods.txt", (from item in mItems
+ let xMethod = item as MethodBase
+ where xMethod != null
+ select Label.GetFullName(xMethod)).ToArray());
}
///