mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-26 21:42:11 +00:00
mem free works successfully now
This commit is contained in:
parent
84095fd299
commit
b4fca104df
8 changed files with 72 additions and 22 deletions
|
|
@ -17,5 +17,8 @@ namespace Cosmos.Hardware {
|
||||||
return GetEndOfKernel();
|
return GetEndOfKernel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void ZeroFill(uint aStartAddress, uint aLength) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
19
source/Cosmos/Cosmos.Kernel.Plugs/Assemblers/ZeroFill.cs
Normal file
19
source/Cosmos/Cosmos.Kernel.Plugs/Assemblers/ZeroFill.cs
Normal file
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,10 +7,16 @@ using HW = Cosmos.Hardware;
|
||||||
namespace Cosmos.Kernel.Plugs {
|
namespace Cosmos.Kernel.Plugs {
|
||||||
[Plug(Target = typeof(HW.CPU))]
|
[Plug(Target = typeof(HW.CPU))]
|
||||||
public static class CPU {
|
public static class CPU {
|
||||||
[PlugMethod(MethodAssembler=typeof(Assemblers.CreateGDT))]
|
[PlugMethod(MethodAssembler = typeof(Assemblers.CreateGDT))]
|
||||||
public static void CreateGDT() { }
|
public static void CreateGDT() {
|
||||||
|
}
|
||||||
|
|
||||||
[PlugMethod(MethodAssembler = typeof(Assemblers.CreateIDT))]
|
[PlugMethod(MethodAssembler = typeof(Assemblers.CreateIDT))]
|
||||||
public static void CreateIDT() { }
|
public static void CreateIDT() {
|
||||||
|
}
|
||||||
|
|
||||||
|
[PlugMethod(MethodAssembler = typeof(Assemblers.ZeroFill))]
|
||||||
|
public static void ZeroFill(uint aStartAddress, uint aLength) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,7 @@
|
||||||
<Compile Include="Assemblers\CreateIDT.cs" />
|
<Compile Include="Assemblers\CreateIDT.cs" />
|
||||||
<Compile Include="Assemblers\IOReadByte.cs" />
|
<Compile Include="Assemblers\IOReadByte.cs" />
|
||||||
<Compile Include="Assemblers\IOWriteByte.cs" />
|
<Compile Include="Assemblers\IOWriteByte.cs" />
|
||||||
|
<Compile Include="Assemblers\ZeroFill.cs" />
|
||||||
<Compile Include="Console.cs" />
|
<Compile Include="Console.cs" />
|
||||||
<Compile Include="CPU.cs" />
|
<Compile Include="CPU.cs" />
|
||||||
<Compile Include="Hardware.cs" />
|
<Compile Include="Hardware.cs" />
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,9 @@ namespace Cosmos.Kernel {
|
||||||
Console.Write("Value = ");
|
Console.Write("Value = ");
|
||||||
Hardware.Storage.ATA.WriteNumber(xPointer[1], 32);
|
Hardware.Storage.ATA.WriteNumber(xPointer[1], 32);
|
||||||
Console.WriteLine("");
|
Console.WriteLine("");
|
||||||
|
xPointer = (uint*)Heap.MemAlloc(64);
|
||||||
|
Hardware.Storage.ATA.WriteNumber((uint)xPointer, 32);
|
||||||
|
Console.WriteLine("");
|
||||||
//Console.Write("Initializing Keyboard...");
|
//Console.Write("Initializing Keyboard...");
|
||||||
//Keyboard.Initialize();
|
//Keyboard.Initialize();
|
||||||
//Console.WriteLine("Done");
|
//Console.WriteLine("Done");
|
||||||
|
|
|
||||||
|
|
@ -24,38 +24,36 @@ namespace Cosmos.Kernel {
|
||||||
//private const uint DefaultMaxMemory = 32 * 1024 * 1024;
|
//private const uint DefaultMaxMemory = 32 * 1024 * 1024;
|
||||||
|
|
||||||
private static void ClearMemory(uint aStartAddress, uint aLength) {
|
private static void ClearMemory(uint aStartAddress, uint aLength) {
|
||||||
|
DebugUtil.SendDoubleNumber("MM", "Clearing memory", aStartAddress, 32, aLength, 32);
|
||||||
Console.Write("[MM] Clearing ");
|
Console.Write("[MM] Clearing ");
|
||||||
Hardware.Storage.ATA.WriteNumber(aLength, 32);
|
Hardware.Storage.ATA.WriteNumber(aLength, 32);
|
||||||
Console.Write(" bytes at ");
|
Console.Write(" bytes at ");
|
||||||
Hardware.Storage.ATA.WriteNumber(aStartAddress, 32);
|
Hardware.Storage.ATA.WriteNumber(aStartAddress, 32);
|
||||||
Console.WriteLine("");
|
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) {
|
private static void Initialize(uint aStartAddress, uint aLength) {
|
||||||
mStartAddress = aStartAddress;
|
mStartAddress = aStartAddress;
|
||||||
// mCurrentAddress = aStartAddress;
|
|
||||||
mLength = aLength;
|
mLength = aLength;
|
||||||
Console.Write("Initializing memory...");
|
|
||||||
ClearMemory(aStartAddress, aLength);
|
ClearMemory(aStartAddress, aLength);
|
||||||
Console.WriteLine("Done");
|
|
||||||
mFirstBlock = (MemoryBlock*)aStartAddress;
|
mFirstBlock = (MemoryBlock*)aStartAddress;
|
||||||
mFirstBlock->State = MemoryBlockState.Free;
|
mFirstBlock->State = MemoryBlockState.Free;
|
||||||
mFirstBlock->Next = (MemoryBlock*)(aStartAddress + aLength);
|
mFirstBlock->Next = (MemoryBlock*)(aStartAddress + aLength);
|
||||||
mFirstBlock->Next->State = MemoryBlockState.EndOfMemory;
|
mFirstBlock->Next->State = MemoryBlockState.EndOfMemory;
|
||||||
//DebugUtil.SendMM_Init(aStartAddress, aLength);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void CheckInit() {
|
public static void CheckInit() {
|
||||||
|
|
@ -111,10 +109,12 @@ namespace Cosmos.Kernel {
|
||||||
|
|
||||||
[GlueMethod(Type = GlueMethodType.Heap_Free)]
|
[GlueMethod(Type = GlueMethodType.Heap_Free)]
|
||||||
public static void MemFree(uint aPointer) {
|
public static void MemFree(uint aPointer) {
|
||||||
|
DebugUtil.SendNumber("MM", "Free pointer", aPointer, 32);
|
||||||
MemoryBlock* xBlock = (MemoryBlock*)(aPointer - 5);
|
MemoryBlock* xBlock = (MemoryBlock*)(aPointer - 5);
|
||||||
xBlock->State = MemoryBlockState.Free;
|
xBlock->State = MemoryBlockState.Free;
|
||||||
uint aLength;
|
uint xLength = ((uint)xBlock->Next) - aPointer;
|
||||||
ClearMemory((uint)xBlock, (((uint)xBlock->Next) - ((uint)xBlock) - 5));
|
DebugUtil.SendNumber("MM", "Pointer length", xLength, 32);
|
||||||
|
ClearMemory(aPointer, xLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@
|
||||||
<Compile Include="Not.cs" />
|
<Compile Include="Not.cs" />
|
||||||
<Compile Include="Pushfd.cs" />
|
<Compile Include="Pushfd.cs" />
|
||||||
<Compile Include="Registers.cs" />
|
<Compile Include="Registers.cs" />
|
||||||
|
<Compile Include="RepeatStos.cs" />
|
||||||
<Compile Include="ShiftLeft.cs" />
|
<Compile Include="ShiftLeft.cs" />
|
||||||
<Compile Include="Divide.cs" />
|
<Compile Include="Divide.cs" />
|
||||||
<Compile Include="Instruction.cs" />
|
<Compile Include="Instruction.cs" />
|
||||||
|
|
|
||||||
17
source/Indy.IL2CPU.Assembler.X86/RepeatStos.cs
Normal file
17
source/Indy.IL2CPU.Assembler.X86/RepeatStos.cs
Normal file
|
|
@ -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;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue