From 2e4e0dd37037d31634b85e5ecf3ffd46c9e7758d Mon Sep 17 00:00:00 2001 From: Charles Betros Date: Fri, 24 Jul 2015 17:52:44 -0500 Subject: [PATCH] Added a test kernel for boxing. Moved Char Plug to Cosmos.System.Plugs Added FAT writing. (Doesn't work yet.) --- Tests/BoxingTests/AssemblyInfo.cs | 36 +++ Tests/BoxingTests/BoxingTests.csproj | 67 +++++ Tests/BoxingTests/BoxingTestsBoot.Cosmos | 83 ++++++ Tests/BoxingTests/Kernel.cs | 51 ++++ .../Cosmos.TestRunner.Core.csproj | 4 + .../DefaultEngineConfiguration.cs | 2 +- .../OutputHandlerXml.cs | 48 +++- .../Cosmos.TestRunner.csproj | 4 + Tests/Cosmos.TestRunner/Program.cs | 1 + Users/Sentinel/SentinelKernel/Kernel.cs | 45 +-- .../SentinelKernel/SentinelKernelBoot.Cosmos | 4 +- .../SentinelKernel/bin/Debug/bochsrc.bxrc | 50 ---- .../FileSystem/FAT/FatFileSystem.cs | 6 + .../FileSystem/FAT/FatStream.cs | 78 +++++- .../SentinelSystem/FileSystem/VFS/VFSBase.cs | 2 +- .../FileSystem/VFS/VFSManager.cs | 4 +- .../SentinelSystem/System/IO/FileImpl.cs | 18 +- .../System/IO/FileStreamImpl.cs | 29 +- .../Cosmos.Common/Extensions/ByteConverter.cs | 11 + source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj | 1 - .../CustomImplementation/System/CharImpl.cs | 30 -- .../Cosmos.System.Plugs.csproj | 1 + source/Cosmos.System.Plugs/System/CharImpl.cs | 36 +++ source/Cosmos.sln | 38 +++ source/XSharp.Compiler/Docs/Old.html | 256 ++++++++++-------- 25 files changed, 653 insertions(+), 252 deletions(-) create mode 100644 Tests/BoxingTests/AssemblyInfo.cs create mode 100644 Tests/BoxingTests/BoxingTests.csproj create mode 100644 Tests/BoxingTests/BoxingTestsBoot.Cosmos create mode 100644 Tests/BoxingTests/Kernel.cs delete mode 100644 Users/Sentinel/SentinelKernel/bin/Debug/bochsrc.bxrc delete mode 100644 source/Cosmos.IL2CPU/CustomImplementation/System/CharImpl.cs create mode 100644 source/Cosmos.System.Plugs/System/CharImpl.cs diff --git a/Tests/BoxingTests/AssemblyInfo.cs b/Tests/BoxingTests/AssemblyInfo.cs new file mode 100644 index 000000000..6848b03ad --- /dev/null +++ b/Tests/BoxingTests/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System; +using System.Reflection; +using System.Resources; +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("Package Name")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Company")] +[assembly: AssemblyProduct("Package Name")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +[assembly: ComVisible(false)] +[assembly: CLSCompliant(false)] +[assembly: NeutralResourcesLanguage("en-US")] + +// 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 Revision and Build Numbers +// by using the '*' as shown below: + +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] + + + diff --git a/Tests/BoxingTests/BoxingTests.csproj b/Tests/BoxingTests/BoxingTests.csproj new file mode 100644 index 000000000..d3018ce3d --- /dev/null +++ b/Tests/BoxingTests/BoxingTests.csproj @@ -0,0 +1,67 @@ + + + + Debug + AnyCPU + 9.0.30729 + 2.0 + {F8889473-5866-4913-86AC-8072A1A2558C} + Library + Properties + BoxingTests + BoxingTests + 512 + v4.5 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + x86 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + False + ..\..\..\..\Users\Charles\AppData\Roaming\Cosmos User Kit\Kernel\Cosmos.Debug.Kernel.dll + + + False + ..\..\..\..\Users\Charles\AppData\Roaming\Cosmos User Kit\Kernel\Cosmos.HAL.dll + + + + + + + + + + + + + + {E6D3B644-C487-472D-A978-C1A82D0C099B} + Cosmos.TestRunner.TestController + + + + + \ No newline at end of file diff --git a/Tests/BoxingTests/BoxingTestsBoot.Cosmos b/Tests/BoxingTests/BoxingTestsBoot.Cosmos new file mode 100644 index 000000000..d521b9491 --- /dev/null +++ b/Tests/BoxingTests/BoxingTestsBoot.Cosmos @@ -0,0 +1,83 @@ + + + + Debug + 2.0 + {444098bc-8f72-4030-a8c0-118d2dd93eb8} + false + BoxingTestsBoot + elf + v4.5 + + + Bochs + + true + Source + User + False + false + Player + bin\Debug\ + BoxingTestsBoot + Use Bochs emulator to deploy and debug. + ISO + Bochs + Pipe: Cosmos\Serial + BoxingTestsBoot + Use VMware Player or Workstation to deploy and debug. + ISO + VMware + true + Source + Pipe: Cosmos\Serial + Player + bin\Debug\ + False + false + BoxingTestsBoot + Use Bochs emulator to deploy and debug. + ISO + Bochs + true + Source + Pipe: Cosmos\Serial + Player + bin\Debug\ + False + false + BoxingTestsBoot + Connect to Intel Edison device to deploy and debug. + BinaryImage + IntelEdison + true + Source + Pipe: Cosmos\Serial + Player + bin\Debug\ + False + false + True + True + + + + + + + + + BoxingTests + {f8889473-5866-4913-86ac-8072a1a2558c} + True + + + + + \ No newline at end of file diff --git a/Tests/BoxingTests/Kernel.cs b/Tests/BoxingTests/Kernel.cs new file mode 100644 index 000000000..523f29fce --- /dev/null +++ b/Tests/BoxingTests/Kernel.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Cosmos.TestRunner; +using Sys = Cosmos.System; + +namespace BoxingTests +{ + public class Kernel : Sys.Kernel + { + protected override void BeforeRun() + { + Console.WriteLine("Cosmos booted successfully."); + } + + protected override void Run() + { + Assert.IsTrue(TestBoxingCharToString(), "Boxing char to string test failed."); + Assert.IsTrue(TestBoxingCharArrayToString(), "Boxing char[] to string test failed."); + TestController.Completed(); + } + + private bool TestBoxingCharToString() + { + try + { + char xC = 'c'; + string xS = xC.ToString(); + return (xS[0] == xC); + } + catch (Exception) + { + return false; + } + } + + private bool TestBoxingCharArrayToString() + { + try + { + char[] xC = {'c'}; + string xS = xC.ToString(); + return (xS[0] == xC[0]); + } + catch (Exception) + { + return false; + } + } + } +} diff --git a/Tests/Cosmos.TestRunner.Core/Cosmos.TestRunner.Core.csproj b/Tests/Cosmos.TestRunner.Core/Cosmos.TestRunner.Core.csproj index 475108cb9..3d8b091db 100644 --- a/Tests/Cosmos.TestRunner.Core/Cosmos.TestRunner.Core.csproj +++ b/Tests/Cosmos.TestRunner.Core/Cosmos.TestRunner.Core.csproj @@ -117,6 +117,10 @@ {6128DEEB-D30F-4859-B60F-C36D5452F3E9} IL2CPU + + {f8889473-5866-4913-86ac-8072a1a2558c} + BoxingTests + {bdc011be-6041-4a58-a6e7-0f592e78cb27} Cosmos.Compiler.Tests.Interfaces.Kernel diff --git a/Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs b/Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs index e644ddda9..967b30d3e 100644 --- a/Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs +++ b/Tests/Cosmos.TestRunner.Core/DefaultEngineConfiguration.cs @@ -24,7 +24,7 @@ namespace Cosmos.TestRunner.Core engine.AddKernel(typeof(Cosmos.Compiler.Tests.SimpleWriteLine.Kernel.Kernel).Assembly.Location); engine.AddKernel(typeof(SimpleStructsAndArraysTest.Kernel).Assembly.Location); engine.AddKernel(typeof(VGACompilerCrash.Kernel).Assembly.Location); - + engine.AddKernel(typeof(BoxingTests.Kernel).Assembly.Location); // known bugs, therefor disabled for now: // end of known bugs diff --git a/Tests/Cosmos.TestRunner.Core/OutputHandlerXml.cs b/Tests/Cosmos.TestRunner.Core/OutputHandlerXml.cs index 4840b0da6..32eb0b8c0 100644 --- a/Tests/Cosmos.TestRunner.Core/OutputHandlerXml.cs +++ b/Tests/Cosmos.TestRunner.Core/OutputHandlerXml.cs @@ -21,7 +21,11 @@ namespace Cosmos.TestRunner.Core protected override void OnExecuteKernelStart(string assemblyName) { - var xParent = mCurrentNode.Peek(); + XmlElement xParent = mDocument.DocumentElement; + if (mCurrentNode.Count > 0) + { + xParent = mCurrentNode.Peek(); + } var xItem = mDocument.CreateElement("Kernel"); xItem.Attributes.Append(NewXmlAttribute("AssemblyName", assemblyName)); xParent.AppendChild(xItem); @@ -42,7 +46,11 @@ namespace Cosmos.TestRunner.Core protected override void OnLogDebugMessage(string message) { - var xParent = mCurrentNode.Peek(); + XmlElement xParent = mDocument.DocumentElement; + if (mCurrentNode.Count > 0) + { + xParent = mCurrentNode.Peek(); + } var xNode = xParent.SelectSingleNode("./DebugMessages"); if (xNode == null) { @@ -56,7 +64,17 @@ namespace Cosmos.TestRunner.Core protected override void OnLogMessage(string message) { - var xParent = mCurrentNode.Peek(); + XmlElement xParent = mDocument.DocumentElement; + if (mCurrentNode.Count > 0) + { + xParent = mCurrentNode.Peek(); + } + var xNode = xParent.SelectSingleNode("./Messages"); + if (xNode == null) + { + xNode = mDocument.CreateElement("Messages"); + xParent.PrependChild(xNode); + } var xItem = mDocument.CreateElement("Message"); xItem.InnerText = message; xParent.AppendChild(xItem); @@ -64,7 +82,11 @@ namespace Cosmos.TestRunner.Core protected override void OnLogError(string message) { - var xParent = mCurrentNode.Peek(); + XmlElement xParent = mDocument.DocumentElement; + if (mCurrentNode.Count > 0) + { + xParent = mCurrentNode.Peek(); + } var xItem = mDocument.CreateElement("Error"); xItem.AppendChild(mDocument.CreateCDataSection(message)); xParent.AppendChild(xItem); @@ -102,7 +124,11 @@ namespace Cosmos.TestRunner.Core protected override void OnUnhandledException(Exception exception) { - var xParent = mCurrentNode.Peek(); + XmlElement xParent = mDocument.DocumentElement; + if (mCurrentNode.Count > 0) + { + xParent = mCurrentNode.Peek(); + } var xItem = mDocument.CreateElement("Exception"); xItem.AppendChild(mDocument.CreateCDataSection(exception.ToString())); xParent.AppendChild(xItem); @@ -110,7 +136,11 @@ namespace Cosmos.TestRunner.Core protected override void OnTaskStart(string taskName) { - var xParent = mCurrentNode.Peek(); + XmlElement xParent = mDocument.DocumentElement; + if (mCurrentNode.Count > 0) + { + xParent = mCurrentNode.Peek(); + } var xItem = mDocument.CreateElement("Task"); xItem.Attributes.Append(NewXmlAttribute("TaskName", taskName)); xParent.AppendChild(xItem); @@ -148,7 +178,11 @@ namespace Cosmos.TestRunner.Core protected override void OnRunConfigurationStart(RunConfiguration configuration) { - var xParent = mCurrentNode.Peek(); + XmlElement xParent = mDocument.DocumentElement; + if (mCurrentNode.Count > 0) + { + xParent = mCurrentNode.Peek(); + } var xItem = mDocument.CreateElement("Configuration"); xItem.Attributes.Append(NewXmlAttribute("IsELF", configuration.IsELF.ToString())); xItem.Attributes.Append(NewXmlAttribute("RunTarget", configuration.RunTarget.ToString())); diff --git a/Tests/Cosmos.TestRunner/Cosmos.TestRunner.csproj b/Tests/Cosmos.TestRunner/Cosmos.TestRunner.csproj index d8dcf998d..b1d63f43c 100644 --- a/Tests/Cosmos.TestRunner/Cosmos.TestRunner.csproj +++ b/Tests/Cosmos.TestRunner/Cosmos.TestRunner.csproj @@ -53,6 +53,10 @@ {3DEF0461-08AB-471A-8F03-A9C556652A0F} Cosmos.System + + {f8889473-5866-4913-86ac-8072a1a2558c} + BoxingTests + {BDC011BE-6041-4A58-A6E7-0F592E78CB27} Cosmos.Compiler.Tests.Interfaces.Kernel diff --git a/Tests/Cosmos.TestRunner/Program.cs b/Tests/Cosmos.TestRunner/Program.cs index 6e6a901f8..a48958e8f 100644 --- a/Tests/Cosmos.TestRunner/Program.cs +++ b/Tests/Cosmos.TestRunner/Program.cs @@ -23,6 +23,7 @@ namespace Cosmos.TestRunner.Console xOutputXml, new OutputHandlerConsole()); + xEngine.RunTargets.Add(RunTargetEnum.Bochs); xEngine.Execute(); global::System.Console.WriteLine("Do you want to save test run details?"); diff --git a/Users/Sentinel/SentinelKernel/Kernel.cs b/Users/Sentinel/SentinelKernel/Kernel.cs index 1cc66bd20..1aade265c 100644 --- a/Users/Sentinel/SentinelKernel/Kernel.cs +++ b/Users/Sentinel/SentinelKernel/Kernel.cs @@ -33,14 +33,14 @@ namespace SentinelKernel return; } - Console.WriteLine("Folder exists!"); - xTest = Directory.Exists("0:\\test\\DirInTest"); - if (!xTest) - { - Console.WriteLine("Subfolder doesn't exist!"); - return; - } - Console.WriteLine("Subfolder exists as well!"); + //Console.WriteLine("Folder exists!"); + //xTest = Directory.Exists("0:\\test\\DirInTest"); + //if (!xTest) + //{ + // Console.WriteLine("Subfolder doesn't exist!"); + // return; + //} + //Console.WriteLine("Subfolder exists as well!"); xTest = File.Exists(@"0:\KudzU.txt"); if (!xTest) @@ -48,23 +48,23 @@ namespace SentinelKernel Console.WriteLine(@"\Kudzu.txt not found!"); return; } - Console.WriteLine("Kudzu.txt found!"); - - xTest = File.Exists(@"0:\Test\DirInTest\Readme.txt"); - if (!xTest) - { - Console.WriteLine(@"\Test\DirInTest\Readme.txt not found!"); - return; - } - - Console.WriteLine(@"Test\DirInTest\Readme.txt found!"); - Console.Write("File contents of Kudzu.txt: "); Console.WriteLine(File.ReadAllText(@"0:\Kudzu.txt")); + File.WriteAllText(@"0:\Kudzu.txt", "Test FAT write."); + Console.WriteLine(File.ReadAllText(@"0:\Kudzu.txt")); - Console.WriteLine(@"File contents of Test\DirInTest\Readme.txt: "); - Console.WriteLine(File.ReadAllText(@"0:\Test\DirInTest\Readme.txt")); + //xTest = File.Exists(@"0:\Test\DirInTest\Readme.txt"); + //if (!xTest) + //{ + // Console.WriteLine(@"\Test\DirInTest\Readme.txt not found!"); + // return; + //} + + //Console.WriteLine(@"Test\DirInTest\Readme.txt found!"); + + //Console.WriteLine(@"File contents of Test\DirInTest\Readme.txt: "); + //Console.WriteLine(File.ReadAllText(@"0:\Test\DirInTest\Readme.txt")); } catch (Exception e) { @@ -74,7 +74,8 @@ namespace SentinelKernel finally { while (true) - ; + { + } } } } diff --git a/Users/Sentinel/SentinelKernel/SentinelKernelBoot.Cosmos b/Users/Sentinel/SentinelKernel/SentinelKernelBoot.Cosmos index 7e347bc56..933d78cb1 100644 --- a/Users/Sentinel/SentinelKernel/SentinelKernelBoot.Cosmos +++ b/Users/Sentinel/SentinelKernel/SentinelKernelBoot.Cosmos @@ -48,7 +48,7 @@ Use Bochs emulator to deploy and debug. ISO Bochs - True + False True Source Pipe: Cosmos\Serial @@ -56,7 +56,7 @@ bin\Debug\ False false - True + False True All All diff --git a/Users/Sentinel/SentinelKernel/bin/Debug/bochsrc.bxrc b/Users/Sentinel/SentinelKernel/bin/Debug/bochsrc.bxrc deleted file mode 100644 index e24698722..000000000 --- a/Users/Sentinel/SentinelKernel/bin/Debug/bochsrc.bxrc +++ /dev/null @@ -1,50 +0,0 @@ -# configuration file generated by Bochs -plugin_ctrl: unmapped=1, biosdev=1, speaker=1, extfpuirq=1, parallel=1, serial=1, gameport=1, iodebug=1 -config_interface: win32config -display_library: win32 -memory: host=256, guest=256 -romimage: file="C:\Program Files (x86)\Bochs-2.6.8/BIOS-bochs-latest" -vgaromimage: file="C:\Program Files (x86)\Bochs-2.6.8/VGABIOS-lgpl-latest" -boot: cdrom -floppy_bootsig_check: disabled=0 -# no floppya -# no floppyb -ata0: enabled=1, ioaddr1=0x1f0, ioaddr2=0x3f0, irq=14 -ata0-master: type=cdrom, path="SentinelKernelBoot.iso", status=inserted, model="Generic 1234", biosdetect=auto -ata0-slave: type=none -ata1: enabled=1, ioaddr1=0x170, ioaddr2=0x370, irq=15 -ata1-master: type=disk, path="C:\Data\Sources\OpenSource\Cosmos\Build\VMWare\Workstation\Filesystem.vmdk", mode=vmware4, cylinders=0, heads=0, spt=0, model="Generic 1234", biosdetect=auto, translation=auto -ata1-slave: type=none -ata2: enabled=0 -ata3: enabled=0 -pci: enabled=1, chipset=i440fx -vga: extension=vbe, update_freq=5, realtime=1 -cpu: count=1, ips=4000000, model=bx_generic, reset_on_triple_fault=1, cpuid_limit_winnt=0, ignore_bad_msrs=1, mwait_is_nop=0 -cpuid: level=6, stepping=3, model=3, family=6, vendor_string="GenuineIntel", brand_string=" Intel(R) Pentium(R) 4 CPU " -cpuid: mmx=1, apic=xapic, simd=sse2, sse4a=0, misaligned_sse=0, sep=1, movbe=0, adx=0 -cpuid: aes=0, sha=0, xsave=0, xsaveopt=0, x86_64=1, 1g_pages=0, pcid=0, fsgsbase=0 -cpuid: smep=0, smap=0, mwait=1, vmx=1 -print_timestamps: enabled=0 -debugger_log: - -magic_break: enabled=0 -port_e9_hack: enabled=0 -private_colormap: enabled=0 -clock: sync=none, time0=local, rtc_sync=0 -# no cmosimage -# no loader -log: - -logprefix: %t%e%d -debug: action=ignore, cpu0=report -info: action=report -error: action=report -panic: action=ask -keyboard: type=mf, serial_delay=250, paste_delay=100000, user_shortcut=none -mouse: type=ps2, enabled=0, toggle=ctrl+mbutton -sound: waveoutdrv=win, waveout=none, waveindrv=win, wavein=none, midioutdrv=win, midiout=none -speaker: enabled=1, mode=sound -parport1: enabled=1, file=none -parport2: enabled=0 -com1: enabled=1, mode=null -com2: enabled=0 -com3: enabled=0 -com4: enabled=0 diff --git a/Users/Sentinel/SentinelSystem/FileSystem/FAT/FatFileSystem.cs b/Users/Sentinel/SentinelSystem/FileSystem/FAT/FatFileSystem.cs index 561c3bc8e..eb4f6c900 100644 --- a/Users/Sentinel/SentinelSystem/FileSystem/FAT/FatFileSystem.cs +++ b/Users/Sentinel/SentinelSystem/FileSystem/FAT/FatFileSystem.cs @@ -179,6 +179,12 @@ namespace SentinelKernel.System.FileSystem.FAT mDevice.ReadBlock(xSector, SectorsPerCluster, aData); } + public void WriteCluster(UInt64 aCluster, byte[] aData) + { + UInt64 xSector = DataSector + ((aCluster - 2) * SectorsPerCluster); + mDevice.WriteBlock(xSector, SectorsPerCluster, aData); + } + public void GetFatTableSector(UInt64 aClusterNum, out UInt32 oSector, out UInt32 oOffset) { UInt64 xOffset = 0; diff --git a/Users/Sentinel/SentinelSystem/FileSystem/FAT/FatStream.cs b/Users/Sentinel/SentinelSystem/FileSystem/FAT/FatStream.cs index 80822e3de..6b92f1e78 100644 --- a/Users/Sentinel/SentinelSystem/FileSystem/FAT/FatStream.cs +++ b/Users/Sentinel/SentinelSystem/FileSystem/FAT/FatStream.cs @@ -44,7 +44,7 @@ namespace SentinelKernel.System.FileSystem.FAT public override bool CanWrite { - get { return false; } + get { return true; } } public override long Length @@ -71,10 +71,10 @@ namespace SentinelKernel.System.FileSystem.FAT public override int Read(byte[] aBuffer, int aOffset, int aCount) { - return Read(aBuffer, (Int64)aOffset, (Int64)aCount); + return Read(aBuffer, aOffset, aCount); } - public int Read(byte[] aBuffer, Int64 aOffset, Int64 aCount) + protected int Read(byte[] aBuffer, Int64 aOffset, Int64 aCount) { if (aCount < 0) { @@ -131,7 +131,6 @@ namespace SentinelKernel.System.FileSystem.FAT aOffset += xReadSize; xCount -= (ulong)xReadSize; - xCount = 0; } mPosition += (ulong)aOffset; @@ -150,17 +149,80 @@ namespace SentinelKernel.System.FileSystem.FAT public override void SetLength(long value) { - throw new NotImplementedException(); + var xOldClusterTotal = Length/mFS.BytesPerCluster; + if (Length%mFS.BytesPerCluster != 0) + { + xOldClusterTotal++; + } + + var xNewClusterTotal = value/mFS.BytesPerCluster; + if (value%mFS.BytesPerCluster != 0) + { + xNewClusterTotal++; + } + + if (xNewClusterTotal != xOldClusterTotal) + { + throw new NotImplementedException("Setting the stream length to a size that requires alllcating new clusters is not currently implemented."); + } + + //mFile.Size = value; } public override void Write(byte[] aBuffer, int aOffset, int aCount) { - Write(aBuffer, (long)aOffset, (long)aCount); + Write(aBuffer, aOffset, aCount); } - public void Write(byte[] buffer, long offset, long count) + protected void Write(byte[] aBuffer, long aOffset, long aCount) { - throw new NotImplementedException(); + if (aCount < 0) + { + throw new ArgumentOutOfRangeException("aCount"); + } + if (aOffset < 0) + { + throw new ArgumentOutOfRangeException("aOffset"); + } + if (aBuffer == null || aBuffer.Length - aOffset < aCount) + { + throw new ArgumentException("Invalid offset length!"); + } + + ulong xCount = (ulong)aCount; + var xCluster = mFS.NewClusterArray(); + UInt32 xClusterSize = mFS.BytesPerCluster; + + long xTotalLength = (long) (mPosition + xCount); + if (xTotalLength > Length) + { + SetLength(xTotalLength); + } + + while (xCount > 0) + { + long xWriteSize; + UInt64 xClusterIdx = mPosition / xClusterSize; + UInt64 xPosInCluster = mPosition % xClusterSize; + if (xPosInCluster + xCount > xClusterSize) + { + xWriteSize = (long)(xClusterSize - xPosInCluster - 1); + } + else + { + xWriteSize = (long)xCount; + } + + Array.Copy(aBuffer, (long)xPosInCluster, xCluster, aOffset, xWriteSize); + + mFS.WriteCluster((ulong)mFatTable[(int)xClusterIdx], xCluster); + + aOffset += xWriteSize; + xCount -= (ulong)xWriteSize; + } + + mPosition += (ulong)aOffset; + } } } \ No newline at end of file diff --git a/Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSBase.cs b/Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSBase.cs index 236ca2532..b54b96d58 100644 --- a/Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSBase.cs +++ b/Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSBase.cs @@ -20,7 +20,7 @@ namespace SentinelKernel.System.FileSystem.VFS public abstract List GetVolumes(); - public static char DirectorySeparatorChar { get { return '\\'; } } + public static char DirectorySeparatorChar => '\\'; public static char AltDirectorySeparatorChar { get { return '/'; } } diff --git a/Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSManager.cs b/Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSManager.cs index f08cb5c0d..88e7e1fb8 100644 --- a/Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSManager.cs +++ b/Users/Sentinel/SentinelSystem/FileSystem/VFS/VFSManager.cs @@ -134,7 +134,7 @@ namespace SentinelKernel.System.FileSystem.VFS #endregion - public static Listing.File TryGetFile(string aPath) + public static Listing.File TryGetFile(string aPath) { if (string.IsNullOrEmpty(aPath)) { @@ -291,7 +291,7 @@ namespace SentinelKernel.System.FileSystem.VFS try { FatHelpers.Debug("DirectoryExists. Path = '" + aPath + "'"); - string xDir = aPath + VFSBase.DirectorySeparatorChar; + string xDir = string.Concat(aPath + VFSBase.DirectorySeparatorChar); //xDir = Path.GetDirectoryName(xDir); return (VFSManager.GetDirectory(xDir) != null); } diff --git a/Users/Sentinel/SentinelSystem/System/IO/FileImpl.cs b/Users/Sentinel/SentinelSystem/System/IO/FileImpl.cs index 10fd2535e..aac040851 100644 --- a/Users/Sentinel/SentinelSystem/System/IO/FileImpl.cs +++ b/Users/Sentinel/SentinelSystem/System/IO/FileImpl.cs @@ -14,11 +14,9 @@ namespace SentinelKernel.System.Plugs.System.IO { public static bool Exists(string aFile) { - return FileSystem.VFS.VFSManager.FileExists(aFile); + return VFSManager.FileExists(aFile); } - - public static string ReadAllText(string aFile) { using (var xFS = new FileStream(aFile, FileMode.Open)) @@ -34,11 +32,13 @@ namespace SentinelKernel.System.Plugs.System.IO } } - // if (!File.Exists(aFile)) - // return "Could not find file " + aFile; - // //throw new FileNotFoundException("Could not find file " + aFile); - - // return VFSManager.ReadFileAsString(aFile); - //} + public static void WriteAllText(string aFile, string aText) + { + using (var xFS = new FileStream(aFile, FileMode.Create)) + { + var xBuff = aText.GetUtf8Bytes(0, (uint) aText.Length); + xFS.Write(xBuff, 0, xBuff.Length); + } + } } } diff --git a/Users/Sentinel/SentinelSystem/System/IO/FileStreamImpl.cs b/Users/Sentinel/SentinelSystem/System/IO/FileStreamImpl.cs index a9c11e87c..c0a1d6fc4 100644 --- a/Users/Sentinel/SentinelSystem/System/IO/FileStreamImpl.cs +++ b/Users/Sentinel/SentinelSystem/System/IO/FileStreamImpl.cs @@ -8,18 +8,16 @@ using SentinelKernel.System.FileSystem.VFS; namespace SentinelKernel.System.Plugs.System.IO { - [Plug(Target = typeof(IO::FileStream))] - [PlugField(FieldId = "$$InnerStream$$", FieldType = typeof(IO::Stream))] + [Plug(Target = typeof (IO::FileStream))] + [PlugField(FieldId = "$$InnerStream$$", FieldType = typeof (IO::Stream))] public class FileStreamImpl { // This plug basically forwards all calls to the $$InnerStream$$ stream, which is supplied by the file system. + // public static unsafe void Ctor(String aThis, [FieldAccess(Name = "$$Storage$$")]ref Char[] aStorage, Char[] aChars, int aStartIndex, int aLength, - - - // public static unsafe void Ctor(String aThis, [FieldAccess(Name = "$$Storage$$")]ref Char[] aStorage, Char[] aChars, int aStartIndex, int aLength, - - public static void Ctor(IO::FileStream aThis, string aPathname, IO::FileMode aMode, [FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream) + public static void Ctor(IO::FileStream aThis, string aPathname, IO::FileMode aMode, + [FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream) { innerStream = VFSManager.GetFileStream(aPathname); } @@ -29,19 +27,28 @@ namespace SentinelKernel.System.Plugs.System.IO // plug cctor as it (indirectly) uses Thread.MemoryBarrier() } - public static int Read(IO::FileStream aThis, byte[] aBuffer, int aOffset, int aCount, [FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream) + public static int Read(IO::FileStream aThis, byte[] aBuffer, int aOffset, int aCount, + [FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream) { return innerStream.Read(aBuffer, aOffset, aCount); } - public static long get_Length(IO::FileStream aThis, [FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream) + public static void Write(IO::FileStream aThis, byte[] aBuffer, int aOffset, int aCount, + [FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream) + { + innerStream.Write(aBuffer, aOffset, aCount); + } + + public static long get_Length(IO::FileStream aThis, + [FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream) { return innerStream.Length; } - public static void SetLength(IO::FileStream aThis, long value) + public static void SetLength(IO::FileStream aThis, long aLength, + [FieldAccess(Name = "$$InnerStream$$")] ref IO::Stream innerStream) { - throw new NotImplementedException(); + innerStream.SetLength(aLength); } public static void Dispose(IO::FileStream aThis, bool disposing) diff --git a/source/Cosmos.Common/Extensions/ByteConverter.cs b/source/Cosmos.Common/Extensions/ByteConverter.cs index 2df70e49e..f0e0ce357 100644 --- a/source/Cosmos.Common/Extensions/ByteConverter.cs +++ b/source/Cosmos.Common/Extensions/ByteConverter.cs @@ -50,6 +50,17 @@ namespace Cosmos.Common.Extensions { return new string(xChars); } + static public byte[] GetUtf8Bytes(this string n, UInt32 aStart, UInt32 aCharCount) + { + // TODO: This method handles ASCII only currently, no unicode. + var xBytes = new byte[aCharCount]; + for (int i = 0; i < aCharCount; i++) + { + xBytes[i] = (byte)n[(int) ((aStart) + i)]; + } + return xBytes; + } + static public string GetUtf16String(this byte[] n, UInt32 aStart, UInt32 aCharCount) { //TODO: This routine only handles ASCII. It does not handle unicode yet. var xChars = new char[aCharCount]; diff --git a/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj b/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj index 49b438e6e..924970f80 100644 --- a/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj +++ b/source/Cosmos.IL2CPU/Cosmos.IL2CPU.csproj @@ -110,7 +110,6 @@ - diff --git a/source/Cosmos.IL2CPU/CustomImplementation/System/CharImpl.cs b/source/Cosmos.IL2CPU/CustomImplementation/System/CharImpl.cs deleted file mode 100644 index 84e60c854..000000000 --- a/source/Cosmos.IL2CPU/CustomImplementation/System/CharImpl.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Cosmos.IL2CPU.Plugs; - -namespace Cosmos.IL2CPU.IL.CustomImplementations.System { - [Plug(Target = typeof(char))] - public static class CharImpl { - public static void Cctor() { - // - } - - //[PlugMethod(Signature = "System_String___System_Char_ToString____")] - public static string ToString(ref char aThis) { - char[] xResult = new char[1]; - xResult[0] = aThis; - return new String(xResult); - } // System_String__System_Char_ToString__ - - public static char ToUpper(char aThis) { - // todo: properly implement Char.ToUpper() - return aThis; - } - - public static bool IsWhiteSpace(char aChar) { - return aChar == ' ' || aChar == '\t'; - } - } -} diff --git a/source/Cosmos.System.Plugs/Cosmos.System.Plugs.csproj b/source/Cosmos.System.Plugs/Cosmos.System.Plugs.csproj index 273b4a860..3cc4e2326 100644 --- a/source/Cosmos.System.Plugs/Cosmos.System.Plugs.csproj +++ b/source/Cosmos.System.Plugs/Cosmos.System.Plugs.csproj @@ -71,6 +71,7 @@ + diff --git a/source/Cosmos.System.Plugs/System/CharImpl.cs b/source/Cosmos.System.Plugs/System/CharImpl.cs new file mode 100644 index 000000000..4a63c6dc5 --- /dev/null +++ b/source/Cosmos.System.Plugs/System/CharImpl.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Cosmos.IL2CPU.Plugs; + +namespace Cosmos.System.Plugs.System +{ + [Plug(Target = typeof(char))] + public static class CharImpl + { + public static void Cctor() + { + // + } + + public static string ToString(ref char aThis) + { + char[] xResult = new char[1]; + xResult[0] = aThis; + return new string(xResult); + } + + public static char ToUpper(char aThis) + { + // todo: properly implement Char.ToUpper() + return aThis; + } + + public static bool IsWhiteSpace(char aChar) + { + return aChar == ' ' || aChar == '\t'; + } + } +} \ No newline at end of file diff --git a/source/Cosmos.sln b/source/Cosmos.sln index 2951000d8..9347c32f2 100644 --- a/source/Cosmos.sln +++ b/source/Cosmos.sln @@ -235,6 +235,10 @@ Project("{471EC4BB-E47E-4229-A789-D1F5F83B52D4}") = "VGACompilerCrashBoot", "..\ EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Cosmos.TestRunner.UI", "..\Tests\Cosmos.TestRunner.UI\Cosmos.TestRunner.UI.csproj", "{0B20C26F-CA92-4D88-8211-EC7B0A261337}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BoxingTests", "..\Tests\BoxingTests\BoxingTests.csproj", "{F8889473-5866-4913-86AC-8072A1A2558C}" +EndProject +Project("{471EC4BB-E47E-4229-A789-D1F5F83B52D4}") = "BoxingTestsBoot", "..\Tests\BoxingTests\BoxingTestsBoot.Cosmos", "{444098BC-8F72-4030-A8C0-118D2DD93EB8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1192,6 +1196,38 @@ Global {0B20C26F-CA92-4D88-8211-EC7B0A261337}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {0B20C26F-CA92-4D88-8211-EC7B0A261337}.Release|Mixed Platforms.Build.0 = Release|Any CPU {0B20C26F-CA92-4D88-8211-EC7B0A261337}.Release|x86.ActiveCfg = Release|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Debug|Itanium.ActiveCfg = Debug|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Debug|Itanium.Build.0 = Debug|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Debug|x86.ActiveCfg = Debug|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Debug|x86.Build.0 = Debug|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Release|Any CPU.Build.0 = Release|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Release|Itanium.ActiveCfg = Release|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Release|Itanium.Build.0 = Release|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Release|x86.ActiveCfg = Release|Any CPU + {F8889473-5866-4913-86AC-8072A1A2558C}.Release|x86.Build.0 = Release|Any CPU + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Debug|Any CPU.ActiveCfg = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Debug|Any CPU.Build.0 = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Debug|Itanium.ActiveCfg = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Debug|Itanium.Build.0 = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Debug|x86.ActiveCfg = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Debug|x86.Build.0 = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Release|Any CPU.ActiveCfg = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Release|Any CPU.Build.0 = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Release|Itanium.ActiveCfg = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Release|Itanium.Build.0 = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Release|Mixed Platforms.ActiveCfg = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Release|Mixed Platforms.Build.0 = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Release|x86.ActiveCfg = Debug|x86 + {444098BC-8F72-4030-A8C0-118D2DD93EB8}.Release|x86.Build.0 = Debug|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1284,5 +1320,7 @@ Global {21915A7E-CC84-4836-8B87-857B6149D496} = {F104F6BC-EF8E-4408-A786-D570D7565231} {78AC2B12-8185-4033-80F0-DA5BF874BE5E} = {F104F6BC-EF8E-4408-A786-D570D7565231} {0B20C26F-CA92-4D88-8211-EC7B0A261337} = {79173AE7-4596-4D33-866F-6F94A2314BE8} + {F8889473-5866-4913-86AC-8072A1A2558C} = {F104F6BC-EF8E-4408-A786-D570D7565231} + {444098BC-8F72-4030-A8C0-118D2DD93EB8} = {F104F6BC-EF8E-4408-A786-D570D7565231} EndGlobalSection EndGlobal diff --git a/source/XSharp.Compiler/Docs/Old.html b/source/XSharp.Compiler/Docs/Old.html index 403e55b03..5231365ac 100644 --- a/source/XSharp.Compiler/Docs/Old.html +++ b/source/XSharp.Compiler/Docs/Old.html @@ -1,121 +1,161 @@ <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.html.cs" Inherits="XSharp_index" %> - + +

X#

- X# compiles C# code into assembly, but does it as it runs. This allows the use - of intellisense, and modification of the output using C#.

-
  • One of the goals of Cosmos is the need to write very little assembly, so only - debug stub, compiler users, etc need assembly. Too much work on X# may not be - worth the resources required.
  • -

    - Consts

    -

    - ref with #. else user would need to use @, and if not woudl get [value] instead. - ie consts have direct ref as default while fields have indirect as default. Also - treat consts diff since they can only be read from and not assigned, and at - parse time we dont know if a label is const, var or other.

    -

    - all consts are group based. Need provision for globals in future. Consts cannot - be local.

    -

    - Method

    -

    - name()

    -
  • + X# compiles C# code into assembly, but does it as it runs. This allows the use + of intellisense, and modification of the output using C#. +

    +
  • + One of the goals of Cosmos is the need to write very little assembly, so only + debug stub, compiler users, etc need assembly. Too much work on X# may not be + worth the resources required. +
  • - Usage

    -

    - look in tokenpatterns.cs for more

    -

    - Labels

    -

    - ..Global

    -

    - .Group

    -

    - Local

    -

    - Think of it like a directory path, .. and . are up.

    -

    - Checkpoint 'text'

    -

    -  

    -

    - if reg = x goto label

    -

    - =
    - !=
    - >
    - >=
    - <
    - <=

    -

    - Register Arithmetic

    -

    - EBP = EBP + 32;
    - This is not possible because C# operator overloading does not look at return - type but only the operand types. That is C# sees Register + int. If we supported - the previous example, then X# could not support:
    - EAX = Memory[EBP + 4];
    - In short, C# sees these two as the same and so X# can only support one. Because - the memory addressing is used more frequently than adding a constant to a - register, X# supports it.
    - To add a constant to a register use:
    - EBP.Add(32);

    -

    - Register-- / Register++

    -

    - Valid and usable. Correspond to Inc and Dec.

    -

    - Register Shifting

    -

    - Example:
    - EAX << 2

    -

    - Rotate

    + Consts +

    -  ~ "infinite" shift because it loops

    -

    - Register Methods

    -
      -
    • Add
    • -
    • Sub
    • -
    • Compare
    • -
    • Test
    • -
    -

    - Register = int

    -

    - Example:
    - EAX = $40
    - EAX = 64

    -

    - Register = Register

    -

    - Example:
    - EAX = EBP

    -

    - Register = Memory[Address];
    - Register = Memory[Address + int];

    -

    - Address can be a string label. i.e. EAX = Memory["Data1"]

    -

    - Register = Port[x]
    - Register = Port[EAX]

    -

    - public static implicit operator RegisterEAX(Cosmos.Assembler.ElementReference aReference) { - Instance.Move(aReference); return Instance; } -

    -

    - Register = Label

    -

    - Example:
    - EAX = AddressOf("Labelname");

    + ref with #. else user would need to use @, and if not woudl get [value] instead. + ie consts have direct ref as default while fields have indirect as default. Also + treat consts diff since they can only be read from and not assigned, and at + parse time we dont know if a label is const, var or other. +

    +

    + all consts are group based. Need provision for globals in future. Consts cannot + be local. +

    +

    + Method +

    +

    + name() +

    +
  • +

    + Usage +

    +

    + look in tokenpatterns.cs for more +

    +

    + Labels +

    +

    + ..Global +

    +

    + .Group +

    +

    + Local +

    +

    + Think of it like a directory path, .. and . are up. +

    +

    + Checkpoint 'text' +

    +

    +   +

    +

    + if reg = x goto label +

    +

    + =
    + !=
    + >
    + >=
    + <
    + <= +

    +

    + Register Arithmetic +

    +

    + EBP = EBP + 32;
    + This is not possible because C# operator overloading does not look at return + type but only the operand types. That is C# sees Register + int. If we supported + the previous example, then X# could not support:
    + EAX = Memory[EBP + 4];
    + In short, C# sees these two as the same and so X# can only support one. Because + the memory addressing is used more frequently than adding a constant to a + register, X# supports it.
    + To add a constant to a register use:
    + EBP.Add(32); +

    +

    + Register-- / Register++ +

    +

    + Valid and usable. Correspond to Inc and Dec. +

    +

    + Register Shifting +

    +

    + Example:
    + EAX << 2 +

    +

    + Rotate +

    +

    +  ~ "infinite" shift because it loops +

    +

    + Register Methods +

    +
      +
    • Add
    • +
    • Sub
    • +
    • Compare
    • +
    • Test
    • +
    +

    + Register = int +

    +

    + Example:
    + EAX = $40
    + EAX = 64 +

    +

    + Register = Register +

    +

    + Example:
    + EAX = EBP +

    +

    + Register = Memory[Address];
    + Register = Memory[Address + int]; +

    +

    + Address can be a string label. i.e. EAX = Memory["Data1"] +

    +

    + Register = Port[x]
    + Register = Port[EAX] +

    +

    + public static implicit operator RegisterEAX(Cosmos.Assembler.ElementReference aReference) { + Instance.Move(aReference); return Instance; } +

    +

    + Register = Label +

    +

    + Example:
    + EAX = AddressOf("Labelname"); +

    +
  • +