mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-22 05:48:37 +00:00
structs should work now. will be testing using the old ext2+ata code...
This commit is contained in:
parent
2a2c747a83
commit
b22ee8ff20
8 changed files with 110 additions and 47 deletions
|
|
@ -26,9 +26,6 @@ namespace Indy.IL2CPU.IL.X86 {
|
|||
}
|
||||
|
||||
public override void DoAssemble() {
|
||||
foreach (var xField in mType.Fields) {
|
||||
new CPU.Comment(String.Format("{0} -- {1}", xField.Key, xField.Value.ToString()));
|
||||
}
|
||||
Ldfld(Assembler, mType, mField);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,21 +22,21 @@ namespace Indy.IL2CPU.IL.X86 {
|
|||
}
|
||||
public override void DoAssemble() {
|
||||
if (mSize >= 4) {
|
||||
for (int i = 0; i < (mSize / 4); i++) {
|
||||
for (int i = 1; i <= (mSize / 4); i++) {
|
||||
// Pop("eax");
|
||||
// Move(Assembler, "dword [" + mDataName + " + 0x" + (i * 4).ToString("X") + "]", "eax");
|
||||
new CPUx86.Pushd("[" + mDataName + " + 0x" + (i * 4).ToString("X") + "]");
|
||||
new CPUx86.Pushd("[" + mDataName + " + 0x" + (mSize - (i * 4)).ToString("X") + "]");
|
||||
}
|
||||
switch (mSize % 4) {
|
||||
case 1: {
|
||||
new CPUx86.Move(CPUx86.Registers.EAX, "0");
|
||||
new CPUx86.Move(CPUx86.Registers.AL, "[" + mDataName + " + 0x" + (mSize - 1).ToString("X") + "]");
|
||||
new CPUx86.Move(CPUx86.Registers.EAX, "0"); //mSize - 1
|
||||
new CPUx86.Move(CPUx86.Registers.AL, "[" + mDataName + " + 0x" + (0).ToString("X") + "]");
|
||||
new CPUx86.Push(CPUx86.Registers.EAX);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
new CPUx86.Move(CPUx86.Registers.EAX, "0");
|
||||
new CPUx86.Move(CPUx86.Registers.AX, "[" + mDataName + " + 0x" + (mSize - 2).ToString("X") + "]");
|
||||
new CPUx86.Move(CPUx86.Registers.AX, "[" + mDataName + " + 0x" + (0).ToString("X") + "]");
|
||||
new CPUx86.Push(CPUx86.Registers.EAX);
|
||||
break;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,20 +151,20 @@ namespace Indy.IL2CPU.IL.X86 {
|
|||
new CPUx86.Move("ecx", "[ecx]");
|
||||
}
|
||||
if (aField.Size >= 4) {
|
||||
for (int i = 0; i < (aField.Size / 4); i++) {
|
||||
new CPUx86.Move("eax", "[ecx + 0x" + (i * 4).ToString("X") + "]");
|
||||
for (int i = 1; i <= (aField.Size / 4); i++) {
|
||||
new CPUx86.Move("eax", "[ecx + 0x" + (aField.Size - (i * 4)).ToString("X") + "]");
|
||||
new CPUx86.Pushd("eax");
|
||||
}
|
||||
switch (aField.Size % 4) {
|
||||
case 1: {
|
||||
new CPUx86.Move("eax", "0");
|
||||
new CPUx86.Move("al", "[ecx + 0x" + (aField.Size - 1).ToString("X") + "]");
|
||||
new CPUx86.Move("al", "[ecx]");
|
||||
new CPUx86.Push("eax");
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
new CPUx86.Move("eax", "0");
|
||||
new CPUx86.Move("ax", "[ecx + 0x" + (aField.Size - 2).ToString("X") + "]");
|
||||
new CPUx86.Move("ax", "[ecx + 0x]");
|
||||
new CPUx86.Push("eax");
|
||||
break;
|
||||
}
|
||||
|
|
@ -213,25 +213,27 @@ namespace Indy.IL2CPU.IL.X86 {
|
|||
if (aType.NeedsGC && !aAssembler.InMetalMode) {
|
||||
aExtraOffset = 12;
|
||||
new CPUx86.Pushd("[esp + 4]");
|
||||
Ldfld(aAssembler, aType, aField, false);
|
||||
//Ldfld(aAssembler, aType, aField, false);
|
||||
new CPUx86.Pop("eax");
|
||||
new CPUx86.Pushd("[eax + " + (aField.Offset + aExtraOffset) + "]");
|
||||
Engine.QueueMethod(GCImplementationRefs.DecRefCountRef);
|
||||
new CPUx86.Call(Label.GenerateLabelName(GCImplementationRefs.DecRefCountRef));
|
||||
}
|
||||
new CPUx86.Move("ecx", "[esp + 0x" + xRoundedSize.ToString("X") + "]");
|
||||
new CPUx86.Add("ecx", "0x" + (aField.Offset + aExtraOffset).ToString("X"));
|
||||
for (int i = 1; i <= (aField.Size / 4); i++) {
|
||||
for (int i = 0; i < (aField.Size / 4); i++) {
|
||||
new CPUx86.Pop("eax");
|
||||
new Move("dword [ecx + 0x" + (aField.Size - (i * 4)).ToString("X") + "]", "eax");
|
||||
new Move("dword [ecx + 0x" + (i * 4).ToString("X") + "]", "eax");
|
||||
}
|
||||
switch (aField.Size % 4) {
|
||||
case 1: {
|
||||
new CPUx86.Pop("eax");
|
||||
new Move("byte [ecx]", "al");
|
||||
new Move("byte [ecx + " + ((aField.Size / 4) * 4) + "]", "al");
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
new CPUx86.Pop("eax");
|
||||
new Move("word [ecx]", "ax");
|
||||
new Move("word [ecx + " + ((aField.Size / 4) * 4) + "]", "ax");
|
||||
break;
|
||||
}
|
||||
case 0: {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using Indy.IL2CPU.Assembler;
|
||||
|
||||
|
||||
|
|
@ -35,7 +36,7 @@ namespace Indy.IL2CPU.IL.X86 {
|
|||
Engine.QueueMethod(GCImplementationRefs.DecRefCountRef);
|
||||
new CPUx86.Call(Label.GenerateLabelName(GCImplementationRefs.DecRefCountRef));
|
||||
}
|
||||
foreach (string s in mLocal.VirtualAddresses) {
|
||||
foreach (string s in mLocal.VirtualAddresses.Reverse()) {
|
||||
new CPUx86.Pop(CPUx86.Registers.EAX);
|
||||
new CPUx86.Move("[" + s + "]", "eax");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,19 +31,19 @@ namespace Indy.IL2CPU.IL.X86 {
|
|||
Engine.QueueMethod(GCImplementationRefs.DecRefCountRef);
|
||||
new CPUx86.Call(Label.GenerateLabelName(GCImplementationRefs.DecRefCountRef));
|
||||
}
|
||||
for (int i = 1; i <= (mSize / 4); i++) {
|
||||
for (int i = 0; i < (mSize / 4); i++) {
|
||||
new CPUx86.Pop(CPUx86.Registers.EAX);
|
||||
new CPUx86.Move("dword [" + mDataName + " + 0x" + (mSize - (i * 4)).ToString("X") + "]", "eax");
|
||||
new CPUx86.Move("dword [" + mDataName + " + 0x" + ((i * 4)).ToString("X") + "]", "eax");
|
||||
}
|
||||
switch (mSize % 4) {
|
||||
case 1: {
|
||||
new CPUx86.Pop(CPUx86.Registers.EAX);
|
||||
new CPUx86.Move("byte [" + mDataName + "]", "al");
|
||||
new CPUx86.Move("byte [" + mDataName + " + " + ((mSize/4)*4) + "]", "al");
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
new CPUx86.Pop(CPUx86.Registers.EAX);
|
||||
new CPUx86.Move("word [" + mDataName + "]", "ax");
|
||||
new CPUx86.Move("word [" + mDataName + " + " + ((mSize / 4) * 4) + "]", "ax");
|
||||
break;
|
||||
}
|
||||
case 0: {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,13 @@ namespace Indy.IL2CPU.IL.CustomImplementations.System {
|
|||
}
|
||||
|
||||
public static string GetNumberString(uint aValue, bool aIsNegative) {
|
||||
if (aValue == 0) {
|
||||
if (aIsNegative) {
|
||||
return "-0";
|
||||
} else {
|
||||
return "0";
|
||||
}
|
||||
}
|
||||
const string xDigits = "0123456789";
|
||||
char[] xResultChars = new char[11];
|
||||
int xCurrentPos = 10;
|
||||
|
|
|
|||
|
|
@ -767,11 +767,11 @@ namespace Indy.IL2CPU {
|
|||
// todo: add better detection of implementation state
|
||||
if (xBody != null) {
|
||||
// todo: add support for types which need different stack size
|
||||
foreach (LocalVariableInfo xLocal in xBody.LocalVariables) {
|
||||
if (xLocal.LocalType.IsValueType && !xLocal.LocalType.IsPrimitive && !xLocal.LocalType.IsEnum && !xLocal.LocalType.IsPointer) {
|
||||
throw new Exception("Structs as locals not yet supported!");
|
||||
}
|
||||
}
|
||||
//foreach (LocalVariableInfo xLocal in xBody.LocalVariables) {
|
||||
// if (xLocal.LocalType.IsValueType && !xLocal.LocalType.IsPrimitive && !xLocal.LocalType.IsEnum && !xLocal.LocalType.IsPointer) {
|
||||
// throw new Exception("Structs as locals not yet supported!");
|
||||
// }
|
||||
//}
|
||||
mInstructionsToSkip = 0;
|
||||
mAssembler.StackContents.Clear();
|
||||
ILReader xReader = new ILReader(xCurrentMethod);
|
||||
|
|
@ -1010,7 +1010,7 @@ namespace Indy.IL2CPU {
|
|||
TypeInformation xTypeInfo;
|
||||
int xObjectStorageSize;
|
||||
SortedList<string, TypeInformation.Field> xTypeFields = GetTypeFieldInfo(aType, out xObjectStorageSize);
|
||||
xTypeInfo = new TypeInformation(xObjectStorageSize, xTypeFields, aType, !aType.IsValueType);
|
||||
xTypeInfo = new TypeInformation(xObjectStorageSize, xTypeFields, aType, (!aType.IsValueType) && aType.IsClass);
|
||||
return xTypeInfo;
|
||||
}
|
||||
|
||||
|
|
@ -1138,7 +1138,7 @@ namespace Indy.IL2CPU {
|
|||
if (xFieldType == null) {
|
||||
xFieldType = xField.FieldType;
|
||||
}
|
||||
if ((!xFieldType.IsValueType && aGCObjects) || (xPlugFieldAttr != null && xPlugFieldAttr.IsExternalValue && aGCObjects)) {
|
||||
if ((!xFieldType.IsValueType && aGCObjects && xFieldType.IsClass) || (xPlugFieldAttr != null && xPlugFieldAttr.IsExternalValue && aGCObjects)) {
|
||||
continue;
|
||||
}
|
||||
if ((xFieldType.IsClass && !xFieldType.IsValueType) || (xPlugFieldAttr != null && xPlugFieldAttr.IsExternalValue)) {
|
||||
|
|
|
|||
|
|
@ -3,11 +3,9 @@ using System.Collections.Generic;
|
|||
using System.Text;
|
||||
using Cosmos.Build.Windows;
|
||||
|
||||
namespace MatthijsTest
|
||||
{
|
||||
class Program
|
||||
{
|
||||
#region Cosmos Builder logic
|
||||
namespace MatthijsTest {
|
||||
class Program {
|
||||
#region Cosmos Builder logic
|
||||
// Most users wont touch this. This will call the Cosmos Build tool
|
||||
[STAThread]
|
||||
static void Main(string[] args) {
|
||||
|
|
@ -16,20 +14,78 @@ namespace MatthijsTest
|
|||
}
|
||||
#endregion
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
Cosmos.Kernel.Boot.Default();
|
||||
Cosmos.Kernel.Staging.DefaultStageQueue stages = new Cosmos.Kernel.Staging.DefaultStageQueue();
|
||||
public static void Init() {
|
||||
DoTest();
|
||||
|
||||
// Put any further stages here.
|
||||
Console.WriteLine("Tests completed, Halting system now");
|
||||
while (true)
|
||||
;
|
||||
}
|
||||
|
||||
stages.Run();
|
||||
private static void DoTest() {
|
||||
TestStruct xTest = new TestStruct(true);
|
||||
xTest.Value1 = 1;
|
||||
xTest.Value2 = 2;
|
||||
Console.WriteLine("Value1 = " + xTest.Value1);
|
||||
Console.WriteLine("Value2 = " + xTest.Value2);
|
||||
Test1(xTest);
|
||||
Test2(xTest);
|
||||
mValue = xTest;
|
||||
Test3();
|
||||
Test4();
|
||||
var x = new MyTestObj();
|
||||
x.mTest = xTest;
|
||||
x.Test5();
|
||||
x.Test6();
|
||||
}
|
||||
|
||||
// Put your code here.
|
||||
private static TestStruct mValue;
|
||||
|
||||
stages.Teardown();
|
||||
while (true)
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
private static void Test1(TestStruct aTest) {
|
||||
var xTest = aTest;
|
||||
Console.WriteLine("Value3 = " + xTest.Value1);
|
||||
Console.WriteLine("Value4 = " + xTest.Value2);
|
||||
}
|
||||
|
||||
private static void Test2(TestStruct aTest2) {
|
||||
Console.WriteLine("Value5 = " + aTest2.Value1);
|
||||
Console.WriteLine("Value6 = " + aTest2.Value2);
|
||||
}
|
||||
|
||||
private static void Test3() {
|
||||
Console.WriteLine("Value7 = " + mValue.Value1);
|
||||
Console.WriteLine("Value8 = " + mValue.Value2);
|
||||
}
|
||||
|
||||
private static void Test4() {
|
||||
var xValue = mValue;
|
||||
Console.WriteLine("Value9 = " + xValue.Value1);
|
||||
Console.WriteLine("ValueA = " + xValue.Value2);
|
||||
}
|
||||
|
||||
public class MyTestObj {
|
||||
public TestStruct mTest;
|
||||
|
||||
public void Test5() {
|
||||
System.Diagnostics.Debugger.Break();
|
||||
Console.WriteLine("ValueB = " + mTest.Value1);
|
||||
Console.WriteLine("ValueC = " + mTest.Value2);
|
||||
}
|
||||
|
||||
public void Test6() {
|
||||
var xValue = mTest;
|
||||
Console.WriteLine("ValueD = " + xValue.Value1);
|
||||
Console.WriteLine("ValueE = " + xValue.Value2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct TestStruct {
|
||||
public uint Value1;
|
||||
public uint Value2;
|
||||
public TestStruct(bool aIsTest) {
|
||||
Value1 = 0;
|
||||
Value2 = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue