public void Create() { var ram = new Ram(1024, 256); Assert.That(ram.Size, Is.EqualTo(1024)); Assert.That(ram.FrameSize, Is.EqualTo(256)); Assert.That(ram.FrameCount, Is.EqualTo(4)); }
public PageStream(Ram ram, PageInfo pageSet) { if (ram == null) throw new ArgumentNullException(nameof(ram)); if (pageSet == null) throw new ArgumentNullException(nameof(pageSet)); _ram = ram; _pageSet = pageSet; _page = pageSet.Pages.FirstOrDefault(); }
public void ReadFromStream() { var buffer = new byte[] {1, 2, 3, 4, 5, 6}; const uint frameSize = 3; var ram = new Ram(buffer, frameSize); var s = ram.GetStream(0); Assert.That(s.Length, Is.EqualTo(frameSize)); Assert.That(s.ToArray(), Is.EquivalentTo(new[] {1, 2, 3})); var s2 = ram.GetStream(1); Assert.That(s2.Length, Is.EqualTo(frameSize)); Assert.That(s2.ToArray(), Is.EquivalentTo(new[] { 4, 5, 6 })); }
public Cpu(Ram ram) { Ram = ram; ReadyQueue = new ReadyQueue(PriorityCount); DeviceReadQueue = new DeviceQueue(); DeviceWriteQueue = new DeviceQueue(); Locks = Enumerable.Range(1, LockCount).Select(x => (DeviceId)(x + Devices.Locks)).Select(x => new Lock(x)).ToArray(); Events = Enumerable.Range(1, EventCount).Select(x => (DeviceId)(x + Devices.Events)).Select(x => new Event(x)).ToArray(); SleepTimer = new CpuSleepTimer(); _processes = new Dictionary<uint, ProcessContextBlock>(); _operations = OpCodeMetaInformationBuilder.GetMetaInformation().ToDictionary(x => x.OpCode, OpCodeMetaInformationBuilder.BuildOperation); IdleProcess = new ProcessContextBlock { Id = 1, }; InputDevice = new TerminalInputDevice(); }
public void Free() { var ram = new Ram(2, 1); var pcb = new ProcessContextBlock { Id = 1 }; var frame = ram.Allocate(pcb); Assert.That(frame, Is.Not.Null); frame = ram.Allocate(pcb); Assert.That(frame, Is.Not.Null); ram.Free(frame); frame = ram.Allocate(pcb); Assert.That(frame, Is.Not.Null); }
public void CreateShared() { var ram = new Ram(1024, 256); var offset = ram.AllocateShared(512); Assert.That(offset, Is.EqualTo(0)); var pcb = new ProcessContextBlock {Id = 10}; var p1 = ram.Allocate(pcb); var p2 = ram.Allocate(pcb); var p1Offset = ram.ToPhysicalAddress(10, p1.VirtualAddress); var p2Offset = ram.ToPhysicalAddress(10, p2.VirtualAddress); Assert.That(p1Offset, Is.GreaterThan(offset)); Assert.That(p2Offset, Is.GreaterThan(offset)); Assert.That(p2Offset, Is.GreaterThan(p1Offset)); }
public void Allocate() { var ram = new Ram(2, 1); var pcb = new ProcessContextBlock { Id = 1 }; var page = ram.Allocate(pcb); Assert.That(page, Is.Not.Null); Assert.That(page.PageNumber, Is.Not.EqualTo(0)); page = ram.Allocate(pcb); Assert.That(page, Is.Not.Null); Assert.That(page.PageNumber, Is.Not.EqualTo(0)); page = ram.Allocate(pcb); Assert.That(page, Is.Null); }
public void Write() { var buffer = new byte[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; const uint frameSize = 4; var ram = new Ram(buffer, frameSize); var pageSet = new PageInfo(); var pcb = new ProcessContextBlock {Id = 1}; ram.Allocate(pcb); pageSet.Append(ram.Allocate(pcb)); pageSet.Append(ram.Allocate(pcb)); var pageStream = new PageStream(ram, pageSet); Assert.That(pageStream.Length, Is.EqualTo(8)); var b = new byte[] { 91, 92, 93, 94, }; pageStream.Position = 2; pageStream.Write(b, 0, 4); Assert.That(buffer, Is.EquivalentTo(new[] { 1, 2, 3, 4, 5, 6, 91, 92, 93, 94, 11, 12, })); }
public void Read() { var buffer = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }; const uint frameSize = 4; var ram = new Ram(buffer, frameSize); var pageSet = new PageInfo(); var pcb = new ProcessContextBlock {Id = 1}; ram.Allocate(pcb); pageSet.Append(ram.Allocate(pcb)); pageSet.Append(ram.Allocate(pcb)); var pageStream = new PageStream(ram, pageSet); Assert.That(pageStream.Length, Is.EqualTo(8)); var b = new byte[6]; pageStream.Read(b, 0, 6); Assert.That(pageStream.Position, Is.EqualTo(6)); Assert.That(b, Is.EquivalentTo(new[] { 5, 6, 7, 8, 9, 10 })); }
public void SetUp() { const uint pId = 10; var ram = new Ram(_ram, 16); _sharedOffset = (int) ram.AllocateShared(256); _cpu = new Cpu(ram); _cpu.InputDevice = new InputDevice(); var p = CreateProcess(pId); _cpu.CurrentProcess = p; _cpu.CurrentProcess.Registers[Register.H] = p.GlobalData.Offset; var heap = _cpu.Ram.Allocate(_cpu.IdleProcess); _heapOffset = (int) _cpu.Ram.ToPhysicalAddress(_cpu.IdleProcess.Id, heap.VirtualAddress); _cpu.Ram.Free(heap); }
public void WriteToStream() { var buffer = new byte[] {1, 2, 3, 4, 5, 6}; const uint frameSize = 3; var ram = new Ram(buffer, frameSize); var s = ram.GetStream(0); s.WriteByte(99); Assert.That(s.ToArray(), Is.EquivalentTo(new[] {99, 2, 3})); }