Example #1
0
        public uint Allocate(uint size)
        {
            var page = new PageInfo();

            while (size > Ram.FrameSize)
            {
                size -= Ram.FrameSize;
                page.Append(Ram.Allocate(CurrentProcess));
            }

            page.Append(Ram.Allocate(CurrentProcess));
            CurrentProcess.PageTable.Add(page);

            return(page.Offset);
        }
Example #2
0
        public Stream AllocateCodeBlock(ProcessContextBlock pcb, uint length)
        {
            var page = new PageInfo();

            while (length > Ram.FrameSize)
            {
                length -= Ram.FrameSize;
                page.Append(Ram.Allocate(pcb));
            }

            page.Append(Ram.Allocate(pcb));
            pcb.Code = page;

            return(GetMemoryStream(page));
        }
Example #3
0
        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, }));
        }
Example #4
0
        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 }));
        }
Example #5
0
        public Stream AllocateCodeBlock(ProcessContextBlock pcb, uint length)
        {
            var page = new PageInfo();

            while ( length > Ram.FrameSize )
            {
                length -= Ram.FrameSize;
                page.Append(Ram.Allocate(pcb));
            }

            page.Append(Ram.Allocate(pcb));
            pcb.Code = page;

            return GetMemoryStream(page);
        }
Example #6
0
        public uint Allocate(uint size)
        {
            var page = new PageInfo();

            while (size > Ram.FrameSize)
            {
                size -= Ram.FrameSize;
                page.Append(Ram.Allocate(CurrentProcess));
            }

            page.Append(Ram.Allocate(CurrentProcess));
            CurrentProcess.PageTable.Add(page);

            return page.Offset;
        }