This commit is contained in:
mterwoord_cp 2010-02-25 07:44:06 +00:00
parent 80c23dd95d
commit 0ef92f6d22
25 changed files with 312 additions and 73 deletions

View file

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

View file

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

View file

@ -1,4 +1,4 @@
//#define WRITE_TO_DEBUG
#define WRITE_TO_DEBUG
using System;
using System.Collections.Generic;
using System.Text;

View file

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

View file

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

View file

@ -65,6 +65,8 @@
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Debugger.cs" />

View file

@ -31,17 +31,16 @@ namespace Cosmos.Sys {
}
mFilesystems = new List<Filesystem>(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",

View file

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

View file

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

View file

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{52BF0A64-EBEF-420A-9F27-6C5226A4B77B}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Cosmos.IL2CPU.X86.Tests</RootNamespace>
<AssemblyName>Cosmos.IL2CPU.X86.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=2.4.1.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\source\libraries\nunit\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblerNasmTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Cosmos.IL2CPU.X86\Cosmos.IL2CPU.X86.csproj">
<Project>{63F7BFB9-419E-4965-B580-304B9C9FA7D8}</Project>
<Name>Cosmos.IL2CPU.X86</Name>
</ProjectReference>
<ProjectReference Include="..\Cosmos.IL2CPU\Cosmos.IL2CPU.csproj">
<Project>{239E33A7-F0C3-4801-85CA-4D8F89A31DC0}</Project>
<Name>Cosmos.IL2CPU</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View file

@ -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"
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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