diff --git a/source/Cosmos/Cosmos.Hardware/CPU.cs b/source/Cosmos/Cosmos.Hardware/CPU.cs index 5d92d0ab8..7377e7d10 100644 --- a/source/Cosmos/Cosmos.Hardware/CPU.cs +++ b/source/Cosmos/Cosmos.Hardware/CPU.cs @@ -17,5 +17,8 @@ namespace Cosmos.Hardware { return GetEndOfKernel(); } } + + public static void ZeroFill(uint aStartAddress, uint aLength) { + } } } \ No newline at end of file diff --git a/source/Cosmos/Cosmos.Kernel.Plugs/Assemblers/ZeroFill.cs b/source/Cosmos/Cosmos.Kernel.Plugs/Assemblers/ZeroFill.cs new file mode 100644 index 000000000..c5a75e984 --- /dev/null +++ b/source/Cosmos/Cosmos.Kernel.Plugs/Assemblers/ZeroFill.cs @@ -0,0 +1,19 @@ +using System; +using Indy.IL2CPU.Assembler.X86; +using Indy.IL2CPU.Plugs; +using Assembler = Indy.IL2CPU.Assembler.Assembler; +using CPUx86 = Indy.IL2CPU.Assembler.X86; +using CPUNative = Indy.IL2CPU.Assembler.X86.Native; + +namespace Cosmos.Kernel.Plugs.Assemblers { + public class ZeroFill: AssemblerMethod { + + // public static void ZeroFill(uint aStartAddress, uint aLength) {} + public override void Assemble(Assembler aAssembler) { + new CPUx86.Move("edi", "[ebp + 0xC]"); // address + new CPUx86.Move("ecx", "[ebp + 8]"); + new CPUx86.Move("eax", "0"); + new CPUx86.RepeatStos(); + } + } +} diff --git a/source/Cosmos/Cosmos.Kernel.Plugs/CPU.cs b/source/Cosmos/Cosmos.Kernel.Plugs/CPU.cs index 86c8c40ce..862c86893 100644 --- a/source/Cosmos/Cosmos.Kernel.Plugs/CPU.cs +++ b/source/Cosmos/Cosmos.Kernel.Plugs/CPU.cs @@ -7,10 +7,16 @@ using HW = Cosmos.Hardware; namespace Cosmos.Kernel.Plugs { [Plug(Target = typeof(HW.CPU))] public static class CPU { - [PlugMethod(MethodAssembler=typeof(Assemblers.CreateGDT))] - public static void CreateGDT() { } + [PlugMethod(MethodAssembler = typeof(Assemblers.CreateGDT))] + public static void CreateGDT() { + } - [PlugMethod(MethodAssembler = typeof(Assemblers.CreateIDT))] - public static void CreateIDT() { } + [PlugMethod(MethodAssembler = typeof(Assemblers.CreateIDT))] + public static void CreateIDT() { + } + + [PlugMethod(MethodAssembler = typeof(Assemblers.ZeroFill))] + public static void ZeroFill(uint aStartAddress, uint aLength) { + } } } diff --git a/source/Cosmos/Cosmos.Kernel.Plugs/Cosmos.Kernel.Plugs.csproj b/source/Cosmos/Cosmos.Kernel.Plugs/Cosmos.Kernel.Plugs.csproj index 795ab4b87..a47149b59 100644 --- a/source/Cosmos/Cosmos.Kernel.Plugs/Cosmos.Kernel.Plugs.csproj +++ b/source/Cosmos/Cosmos.Kernel.Plugs/Cosmos.Kernel.Plugs.csproj @@ -57,6 +57,7 @@ + diff --git a/source/Cosmos/Cosmos.Kernel/CPU.cs b/source/Cosmos/Cosmos.Kernel/CPU.cs index 6a214b656..e146abd32 100644 --- a/source/Cosmos/Cosmos.Kernel/CPU.cs +++ b/source/Cosmos/Cosmos.Kernel/CPU.cs @@ -43,6 +43,9 @@ namespace Cosmos.Kernel { Console.Write("Value = "); Hardware.Storage.ATA.WriteNumber(xPointer[1], 32); Console.WriteLine(""); + xPointer = (uint*)Heap.MemAlloc(64); + Hardware.Storage.ATA.WriteNumber((uint)xPointer, 32); + Console.WriteLine(""); //Console.Write("Initializing Keyboard..."); //Keyboard.Initialize(); //Console.WriteLine("Done"); diff --git a/source/Cosmos/Cosmos.Kernel/Heap.cs b/source/Cosmos/Cosmos.Kernel/Heap.cs index 445b86f3b..bfbc7049c 100644 --- a/source/Cosmos/Cosmos.Kernel/Heap.cs +++ b/source/Cosmos/Cosmos.Kernel/Heap.cs @@ -24,38 +24,36 @@ namespace Cosmos.Kernel { //private const uint DefaultMaxMemory = 32 * 1024 * 1024; private static void ClearMemory(uint aStartAddress, uint aLength) { + DebugUtil.SendDoubleNumber("MM", "Clearing memory", aStartAddress, 32, aLength, 32); Console.Write("[MM] Clearing "); Hardware.Storage.ATA.WriteNumber(aLength, 32); Console.Write(" bytes at "); Hardware.Storage.ATA.WriteNumber(aStartAddress, 32); Console.WriteLine(""); + Hardware.CPU.ZeroFill(aStartAddress, aLength); + //uint* xPtrLong = (uint*)aStartAddress; + //{ + // for (int i = 0; i < (aLength / 4); i++) { + // xPtrLong[i] = 0; + // } + //} + //byte* xPtr = (byte*)(aStartAddress + aLength - (aLength % 4)); + //{ + // for (int i = 0; i < aLength%4; i++) { + // xPtr[i] = 0; + // } + //} - uint* xPtrLong = (uint*)aStartAddress; - { - for (int i = 0; i < (aLength / 4); i++) { - xPtrLong[i] = 0; - } - } - byte* xPtr = (byte*)(aStartAddress + aLength - (aLength % 4)); - { - for (int i = 0; i < aLength%4; i++) { - xPtr[i] = 0; - } - } } private static void Initialize(uint aStartAddress, uint aLength) { mStartAddress = aStartAddress; - // mCurrentAddress = aStartAddress; mLength = aLength; - Console.Write("Initializing memory..."); ClearMemory(aStartAddress, aLength); - Console.WriteLine("Done"); mFirstBlock = (MemoryBlock*)aStartAddress; mFirstBlock->State = MemoryBlockState.Free; mFirstBlock->Next = (MemoryBlock*)(aStartAddress + aLength); mFirstBlock->Next->State = MemoryBlockState.EndOfMemory; - //DebugUtil.SendMM_Init(aStartAddress, aLength); } public static void CheckInit() { @@ -111,10 +109,12 @@ namespace Cosmos.Kernel { [GlueMethod(Type = GlueMethodType.Heap_Free)] public static void MemFree(uint aPointer) { + DebugUtil.SendNumber("MM", "Free pointer", aPointer, 32); MemoryBlock* xBlock = (MemoryBlock*)(aPointer - 5); xBlock->State = MemoryBlockState.Free; - uint aLength; - ClearMemory((uint)xBlock, (((uint)xBlock->Next) - ((uint)xBlock) - 5)); + uint xLength = ((uint)xBlock->Next) - aPointer; + DebugUtil.SendNumber("MM", "Pointer length", xLength, 32); + ClearMemory(aPointer, xLength); } } } diff --git a/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj b/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj index 72f9671e8..33f7a37cd 100644 --- a/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj +++ b/source/Indy.IL2CPU.Assembler.X86/Indy.IL2CPU.Assembler.X86.csproj @@ -60,6 +60,7 @@ + diff --git a/source/Indy.IL2CPU.Assembler.X86/RepeatStos.cs b/source/Indy.IL2CPU.Assembler.X86/RepeatStos.cs new file mode 100644 index 000000000..769e3f279 --- /dev/null +++ b/source/Indy.IL2CPU.Assembler.X86/RepeatStos.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Indy.IL2CPU.Assembler.X86 { + [OpCode(0xFFFFFFFF, "rep stosb")] + public class RepeatStos: Instruction { + //public readonly string Destination; + public RepeatStos() { + // Destination = aDestination; + } + //public override string ToString() { + // return "rep stos " + Destinati; + //} + } +}