From 36f4dfd119c76b42922a67eb54ed023ddbd4eabf Mon Sep 17 00:00:00 2001 From: mterwoord_cp <7cd3fd84a0151ea055c2f79e4d2eef9576fe9afesxUZAwxD> Date: Sun, 4 Nov 2007 16:48:10 +0000 Subject: [PATCH] fixed string support in metal-mode --- source/Cosmos.Kernel.Boot/BootDrv.cs | 2 +- .../System/ConsoleImpl.cs | 2 ++ .../System/StringImpl.cs | 25 ++++++++++++++----- .../System/StringImplRefs.cs | 1 + source/Indy.IL2CPU.IL.X86/LdStr.cs | 6 ++--- source/Indy.IL2CPU.IL.X86/X86OpCodeMap.cs | 9 ++++--- .../CustomImplementation/System/StringImpl.cs | 14 +++++------ 7 files changed, 38 insertions(+), 21 deletions(-) diff --git a/source/Cosmos.Kernel.Boot/BootDrv.cs b/source/Cosmos.Kernel.Boot/BootDrv.cs index 499646c13..1cac38dcb 100644 --- a/source/Cosmos.Kernel.Boot/BootDrv.cs +++ b/source/Cosmos.Kernel.Boot/BootDrv.cs @@ -79,7 +79,7 @@ namespace Cosmos.Kernel.Boot { } public static void Main() { - Console.WriteLine("This is CosmOS Booting..."); + Console.WriteLine("This is CosmOS Booting..."); // 25 chars if (!BootInfoSet) { Console.WriteLine("No boot info available, terminating!"); return; diff --git a/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ConsoleImpl.cs b/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ConsoleImpl.cs index 0c205ca5f..0459ac521 100644 --- a/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ConsoleImpl.cs +++ b/source/Indy.IL2CPU.IL.X86.Native/CustomImplementations/System/ConsoleImpl.cs @@ -840,6 +840,8 @@ namespace Indy.IL2CPU.IL.X86.Native.CustomImplementations.System { } private static void OutputString(string aText) { + int theLength = aText.Length; + global::System.Diagnostics.Debugger.Break(); for (int i = 0; i < aText.Length; i++) { Write_char_(aText[i]); } diff --git a/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/StringImpl.cs b/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/StringImpl.cs index f00399565..b0aa26d5d 100644 --- a/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/StringImpl.cs +++ b/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/StringImpl.cs @@ -7,7 +7,7 @@ namespace Indy.IL2CPU.IL.X86.CustomImplementations.System { public static class StringImpl { public static unsafe int get_Length(int* aThis) { int* xThis = aThis; - xThis += 3; + xThis += 2; xThis = (int*)*xThis; xThis += 2; return *xThis; @@ -17,11 +17,24 @@ namespace Indy.IL2CPU.IL.X86.CustomImplementations.System { return 0; } - public static unsafe byte get_Chars_Metal(byte* aThis, int aIndex) { - byte* xThis = aThis; - xThis += 4; - xThis += aIndex; - return *xThis; + public static unsafe byte get_Chars_Metal(uint* aThis, int aIndex) { + uint* xThis = aThis; + xThis += 3; + xThis = (uint*)*xThis; + xThis += 3; + byte* aBytes = (byte*)xThis; + aBytes += aIndex; + return *aBytes; + } + + public static unsafe ushort get_Chars_Normal(uint* aThis, int aIndex) { + uint* xThis = aThis; + xThis += 3; + xThis = (uint*)*xThis; + xThis += 3; + ushort* aBytes = (ushort*)xThis; + aBytes += aIndex; + return *aBytes; } } } diff --git a/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/StringImplRefs.cs b/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/StringImplRefs.cs index f69884731..0ace4bb97 100644 --- a/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/StringImplRefs.cs +++ b/source/Indy.IL2CPU.IL.X86/CustomImplementations/System/StringImplRefs.cs @@ -10,6 +10,7 @@ namespace Indy.IL2CPU.IL.X86.CustomImplementations.System { public static readonly AssemblyDefinition RuntimeAssemblyDef; public static readonly MethodDefinition get_LengthRef; public static readonly MethodDefinition get_Chars_MetalRef; + public static readonly MethodDefinition get_Chars_NormalRef; static StringImplRefs() { RuntimeAssemblyDef = AssemblyFactory.GetAssembly(typeof(StringImpl).Assembly.Location); diff --git a/source/Indy.IL2CPU.IL.X86/LdStr.cs b/source/Indy.IL2CPU.IL.X86/LdStr.cs index 5064e5293..b0f48a93a 100644 --- a/source/Indy.IL2CPU.IL.X86/LdStr.cs +++ b/source/Indy.IL2CPU.IL.X86/LdStr.cs @@ -34,8 +34,8 @@ namespace Indy.IL2CPU.IL.X86 { if (String.IsNullOrEmpty(xDataName)) { xDataName = Assembler.GetIdentifier("StringLiteral"); StringBuilder xRefByteArray = new StringBuilder(); - xRefByteArray.Append(BitConverter.GetBytes(Engine.RegisterType(Engine.GetTypeDefinition("mscorlib", "System.String"))).Aggregate("", (r, b) => r + b + ",")); - xRefByteArray.Append(BitConverter.GetBytes((int)InstanceTypeEnum.NormalObject).Aggregate("", (r, b) => r + b + ",")); + xRefByteArray.Append("0x" + ((uint)Engine.RegisterType(Engine.GetTypeDefinition("mscorlib", "System.String"))).ToString("X")); + xRefByteArray.Append(",0x" + ((int)InstanceTypeEnum.NormalObject).ToString("X") + ",0,"); xRefByteArray.Append(xDataName + "__Contents,"); xRefByteArray.Append("0,0,0"); Assembler.DataMembers.Add(new DataMember(xDataName, "dd", xRefByteArray.ToString())); @@ -43,7 +43,7 @@ namespace Indy.IL2CPU.IL.X86 { } else { xDataName = xDataName.Substring(0, xDataName.Length - "__Contents".Length); } - Move(Assembler, "eax", "[" + xDataName + "]"); + Move(Assembler, "eax", xDataName); Pushd(4, "eax"); } else { var xDataByteArray = new StringBuilder(); diff --git a/source/Indy.IL2CPU.IL.X86/X86OpCodeMap.cs b/source/Indy.IL2CPU.IL.X86/X86OpCodeMap.cs index a87814222..424670df6 100644 --- a/source/Indy.IL2CPU.IL.X86/X86OpCodeMap.cs +++ b/source/Indy.IL2CPU.IL.X86/X86OpCodeMap.cs @@ -44,17 +44,18 @@ namespace Indy.IL2CPU.IL.X86 { } case "System_UInt32____Indy_IL2CPU_CustomImplementation_System_StringImpl_GetStorage___System_String___": { //if (aInMetalMode) { - //return CustomImplementation.System.StringImplRefs.GetStorageMetalRef; + //return CustomImplementation.System.StringImplRefs.GetStorageMetalRef; //} else { - //return CustomImplementation.System.StringImplRefs.GetStorageNormalRef; + //return CustomImplementation.System.StringImplRefs.GetStorageNormalRef; //} - return CustomImplementation.System.StringImplRefs.GetStorage_ImplRef; + return CustomImplementation.System.StringImplRefs.GetStorage_ImplRef; } case "System_Char___System_String_get_Chars___System_Int32___": { if (aInMetalMode) { return CustomImplementations.System.StringImplRefs.get_Chars_MetalRef; + } else { + return CustomImplementations.System.StringImplRefs.get_Chars_NormalRef; } - goto default; } case "System_Void___System_EventHandler__ctor___System_Object__System_IntPtr___": { return CustomImplementations.System.EventHandlerImplRefs.CtorRef; diff --git a/source/Indy.IL2CPU/CustomImplementation/System/StringImpl.cs b/source/Indy.IL2CPU/CustomImplementation/System/StringImpl.cs index 6d8bdd985..55a2348b7 100644 --- a/source/Indy.IL2CPU/CustomImplementation/System/StringImpl.cs +++ b/source/Indy.IL2CPU/CustomImplementation/System/StringImpl.cs @@ -44,12 +44,12 @@ namespace Indy.IL2CPU.CustomImplementation.System { return (uint)xThis; } - public static unsafe uint* GetStorageNormal(uint* aStringPtr) { - uint* xResult = aStringPtr; - xResult = xResult + 3; - xResult = (uint*)(*xResult); - xResult += 3; - return xResult; - } +// public static unsafe uint* GetStorageNormal(uint* aStringPtr) { +// uint* xResult = aStringPtr; +// xResult = xResult + 3; +// xResult = (uint*)(*xResult); +// xResult += 3; +// return xResult; +// } } }