From f3bb974712cfeebb46d4c6ee619e604df9c1521b Mon Sep 17 00:00:00 2001 From: Charles Betros Date: Fri, 24 Jun 2016 21:38:55 -0500 Subject: [PATCH] Progress on memory. Fix ldelem_ref. --- source/Cosmos.HAL/BlockDevice/AtaPio.cs | 4 +- source/Cosmos.HAL/BlockDevice/BlockDevice.cs | 21 +--------- source/Cosmos.HAL/BlockDevice/Partition.cs | 6 ++- source/Cosmos.HAL/Global.cs | 9 +++-- source/Cosmos.IL2CPU/AppAssembler.cs | 2 +- source/Cosmos.IL2CPU/IL/Ldelem_Ref.cs | 42 ++++++++++---------- 6 files changed, 35 insertions(+), 49 deletions(-) diff --git a/source/Cosmos.HAL/BlockDevice/AtaPio.cs b/source/Cosmos.HAL/BlockDevice/AtaPio.cs index 233532ee7..76ca59eeb 100644 --- a/source/Cosmos.HAL/BlockDevice/AtaPio.cs +++ b/source/Cosmos.HAL/BlockDevice/AtaPio.cs @@ -344,8 +344,8 @@ namespace Cosmos.HAL.BlockDevice public override void WriteBlock(UInt64 aBlockNo, UInt64 aBlockCount, byte[] aData) { - CheckDataSize(aData, aBlockCount); - SelectSector(aBlockNo, aBlockCount); + CheckDataSize(aData, aBlockCount); + SelectSector(aBlockNo, aBlockCount); SendCmd(LBA48Bit ? Cmd.WritePioExt : Cmd.WritePio); UInt16 xValue; diff --git a/source/Cosmos.HAL/BlockDevice/BlockDevice.cs b/source/Cosmos.HAL/BlockDevice/BlockDevice.cs index 8a1e15af7..f07332d9e 100644 --- a/source/Cosmos.HAL/BlockDevice/BlockDevice.cs +++ b/source/Cosmos.HAL/BlockDevice/BlockDevice.cs @@ -42,32 +42,13 @@ namespace Cosmos.HAL.BlockDevice protected void CheckDataSize(byte[] aData, UInt64 aBlockCount) { - aData = new byte[1024]; var xActualLength = aData.Length; var xExpectedDataSize = aBlockCount * mBlockSize; Debugger.DoSend("Expected data size:"); Debugger.DoSendNumber(xExpectedDataSize); Debugger.DoSend("Actual data size:"); Debugger.DoSendNumber(xActualLength); - Debugger.DoSend("Actual data size:"); - Debugger.DoSendNumber(xActualLength); - Debugger.DoSend("Actual data size:"); - Debugger.DoSendNumber(xActualLength); - Debugger.DoSend("Actual data size:"); - Debugger.DoSendNumber(aData.Length); - Debugger.DoSend("Expected data size:"); - Debugger.DoSendNumber(xExpectedDataSize); - for (int i = 0; i < 10000; i++) - { - ; - ; - ; - } - while (true) - ; - //var xBlockSize = mBlockSize; - //var xDataLength = aData.Length; - //var xDataSize = aBlockCount * mBlockSize; + if ((ulong)aData.Length != aBlockCount * mBlockSize) { throw new Exception("Invalid data size."); diff --git a/source/Cosmos.HAL/BlockDevice/Partition.cs b/source/Cosmos.HAL/BlockDevice/Partition.cs index 46f08cbca..305c3c641 100644 --- a/source/Cosmos.HAL/BlockDevice/Partition.cs +++ b/source/Cosmos.HAL/BlockDevice/Partition.cs @@ -20,14 +20,16 @@ namespace Cosmos.HAL.BlockDevice public override void ReadBlock(UInt64 aBlockNo, UInt64 aBlockCount, byte[] aData) { - UInt64 xHostBlockNo = mStartingSector + aBlockNo; + CheckDataSize(aData, aBlockCount); + UInt64 xHostBlockNo = mStartingSector + aBlockNo; CheckBlockNo(xHostBlockNo, aBlockCount); mHost.ReadBlock(xHostBlockNo, aBlockCount, aData); } public override void WriteBlock(UInt64 aBlockNo, UInt64 aBlockCount, byte[] aData) { - UInt64 xHostBlockNo = mStartingSector + aBlockNo; + CheckDataSize(aData, aBlockCount); + UInt64 xHostBlockNo = mStartingSector + aBlockNo; CheckBlockNo(xHostBlockNo, aBlockCount); mHost.WriteBlock(xHostBlockNo, aBlockCount, aData); } diff --git a/source/Cosmos.HAL/Global.cs b/source/Cosmos.HAL/Global.cs index 139f2db94..f183479e0 100644 --- a/source/Cosmos.HAL/Global.cs +++ b/source/Cosmos.HAL/Global.cs @@ -85,19 +85,22 @@ namespace Cosmos.HAL } // TODO Change this to foreach when foreach is supported - Ata.AtaDebugger.Send("Number of MBR partitions found: " + xMBR.Partitions.Count); + Ata.AtaDebugger.Send("Number of MBR partitions found:"); + Ata.AtaDebugger.SendNumber(xMBR.Partitions.Count); for (int i = 0; i < xMBR.Partitions.Count; i++) { var xPart = xMBR.Partitions[i]; if (xPart == null) { - Console.WriteLine("Null partition found at idx " + i); + Console.WriteLine("Null partition found at idx:"); + Console.WriteLine(i); } else { var xPartDevice = new Partition(xATA, xPart.StartSector, xPart.SectorCount); BlockDevice.BlockDevice.Devices.Add(xPartDevice); - Console.WriteLine("Found partition at idx " + i); + Console.WriteLine("Found partition at idx"); + Console.WriteLine(i); } } } diff --git a/source/Cosmos.IL2CPU/AppAssembler.cs b/source/Cosmos.IL2CPU/AppAssembler.cs index 10e65b0b1..ff5d69792 100644 --- a/source/Cosmos.IL2CPU/AppAssembler.cs +++ b/source/Cosmos.IL2CPU/AppAssembler.cs @@ -917,7 +917,7 @@ namespace Cosmos.IL2CPU XS.DataMemberBytes(xTheName + "_Contents", xData); XS.DataMember(xTheName, 1, "dd", xTheName + "_Contents"); #if VMT_DEBUG - using (var xVmtDebugOutput = XmlWriter.Create(@"c:\data\vmt_debug.xml")) + using (var xVmtDebugOutput = XmlWriter.Create(@"vmt_debug.xml")) { xVmtDebugOutput.WriteStartDocument(); xVmtDebugOutput.WriteStartElement("VMT"); diff --git a/source/Cosmos.IL2CPU/IL/Ldelem_Ref.cs b/source/Cosmos.IL2CPU/IL/Ldelem_Ref.cs index 03fff84d5..5c33e23d1 100644 --- a/source/Cosmos.IL2CPU/IL/Ldelem_Ref.cs +++ b/source/Cosmos.IL2CPU/IL/Ldelem_Ref.cs @@ -1,42 +1,42 @@ using System; +using System.Linq; using CPUx86 = Cosmos.Assembler.x86; using Cosmos.Assembler; +using Cosmos.IL2CPU.ILOpCodes; using Cosmos.IL2CPU.Plugs.System; using XSharp.Compiler; +using static XSharp.Compiler.XSRegisters; namespace Cosmos.IL2CPU.X86.IL { - [Cosmos.IL2CPU.OpCode(ILOpCode.Code.Ldelem_Ref)] + [OpCode(ILOpCode.Code.Ldelem_Ref)] public class Ldelem_Ref : ILOp { - public Ldelem_Ref(Cosmos.Assembler.Assembler aAsmblr) + public Ldelem_Ref(Assembler.Assembler aAsmblr) : base(aAsmblr) { } - public static void Assemble(Cosmos.Assembler.Assembler aAssembler, uint aElementSize, bool isSigned, bool debugEnabled) + public static void Assemble(Assembler.Assembler aAssembler, uint aElementSize, bool isSigned, bool debugEnabled) { - // stack - 1: array - // stack - 0: index DoNullReferenceCheck(aAssembler, debugEnabled, 8); - - XS.Pop(XSRegisters.EAX); // index - XS.Set(XSRegisters.EDX, aElementSize); - XS.Add(XSRegisters.ESP, 4); - XS.Multiply(XSRegisters.EDX); - - XS.Add(XSRegisters.EAX, (ObjectImpl.FieldDataOffset + 4)); + // calculate element offset into array memory (including header) + XS.Pop(EAX); + XS.Set(EDX, aElementSize); + XS.Multiply(EDX); + XS.Add(EAX, ObjectImpl.FieldDataOffset + 4); if (aElementSize > 4) { // we start copying the last bytes - XS.Add(XSRegisters.EAX, aElementSize - 4); + XS.Add(EAX, aElementSize - 4); } - // pop the array - XS.Pop(XSRegisters.EDX); - - XS.Add(XSRegisters.EDX, XSRegisters.EAX); + // pop the array now + XS.Add(ESP, 4); + XS.Pop(EDX); + + XS.Add(EDX, EAX); var xSizeLeft = aElementSize; while (xSizeLeft > 0) @@ -58,7 +58,7 @@ namespace Cosmos.IL2CPU.X86.IL { new CPUx86.MoveZeroExtend { DestinationReg = CPUx86.RegistersEnum.ECX, Size = 8, SourceReg = CPUx86.RegistersEnum.EDX, SourceIsIndirect = true }; } - XS.Push(XSRegisters.ECX); + XS.Push(ECX); break; case 2: if (isSigned) @@ -69,12 +69,12 @@ namespace Cosmos.IL2CPU.X86.IL { new CPUx86.MoveZeroExtend { DestinationReg = CPUx86.RegistersEnum.ECX, Size = 16, SourceReg = CPUx86.RegistersEnum.EDX, SourceIsIndirect = true }; } - XS.Push(XSRegisters.ECX); + XS.Push(ECX); break; case 4: // copy a full dword - XS.Push(XSRegisters.EDX, isIndirect: true); - XS.Sub(XSRegisters.EDX, 4); // move to previous 4 bytes + XS.Push(EDX, isIndirect: true); + XS.Sub(EDX, 4); // move to previous 4 bytes break; //case 8: // new CPUx86.Push {DestinationReg = CPUx86.Registers.EDX, DestinationDisplacement = 4, DestinationIsIndirect = true};