Ejemplo n.º 1
0
        public void ByteFromVirtualAddressWithEmptyTlbCanBeRead()
        {
            uint testDataVirtualAddress = 65536;

            var(_, _, pdEntryForPt) = TlbHelper.CreatePageTableEntry(0, 4096);
            _mmu.CopyToPhysical(0, pdEntryForPt);

            var(_, ptIndex, ptEntry) = TlbHelper.CreatePageTableEntry(testDataVirtualAddress, 8192);
            uint ptEntryAddress = (uint)(4096 + ptIndex * 4);

            _mmu.CopyToPhysical(ptEntryAddress, ptEntry);

            var sampleData = new byte[] { 66, 33 };

            _mmu.CopyToPhysical(8192, sampleData);

            _mmu.GetVirtualByte(testDataVirtualAddress).Should().Be(66);
            _mmu.GetVirtualByte(testDataVirtualAddress + 1).Should().Be(33);
        }
Ejemplo n.º 2
0
        public void IdentityMaptTest()
        {
            var(location, data) = TlbHelper.PrepareIdentityMap(MemorySize);
            _mmu.CopyToPhysical(location, data);
            _mmu._pageDirectory = location;
            var storeRand = new Random(0);
            var getRand   = new Random(0);

            for (uint address = 0; address < location; address += 4)
            {
                var value = (uint)storeRand.Next();
                _mmu.StoreVirtualLong(address, value);
                var gotValue = _mmu.GetVirtualLong(address);
                gotValue.Should().Be(value, $"fail at first pass, address {address}");
            }

            for (uint address = 0; address < location; address += 4)
            {
                var expectedValue = (uint)getRand.Next();
                var value         = _mmu.GetVirtualLong(address);
                value.Should().Be(expectedValue, $"fail at second pass, address {address}");
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            const int memorySize = 32 * 1024 * 1024;
            var       mmu        = new Mmu(memorySize);
            var       decoder    = new InstructionDecoder();
            var       cpu        = new Cpu <PhysicalMemoryAccessor, Tracing>(mmu, decoder);

            if (false /*cpu is Cpu<VirtualMemoryAccessor>*/)
            {
                var(location, data) = TlbHelper.PrepareIdentityMap(memorySize);
                mmu.CopyToPhysical(location, data);
                mmu._pageDirectory = location;
            }
            else
            {
                mmu._pageDirectory = memorySize - 4;
            }

            var elf              = ELFReader.Load <uint>("D:\\fibo");
            var startAddress     = elf.EntryPoint;
            var loadableSegments = elf.Segments.Where(s => s.Type == SegmentType.Load);

            foreach (var segment in loadableSegments)
            {
                var content = segment.GetMemoryContents();
                var address = segment.PhysicalAddress;
                mmu.CopyToPhysical(address, content);
            }

            cpu.Execute((int)startAddress);
            var stoper = Stopwatch.StartNew();

            for (var i = 0; i < 10; ++i)
            {
                cpu.Execute((int)startAddress);
            }
            stoper.Stop();
            Console.WriteLine(stoper.ElapsedMilliseconds);
            Console.WriteLine(cpu.InstructionsExecuted);
            Console.WriteLine($"{(double)cpu.InstructionsExecuted / stoper.ElapsedMilliseconds / 1000} MIPS");
            cpu.Reset();


            stoper = Stopwatch.StartNew();
            for (var i = 0; i < 100; ++i)
            {
                cpu.Execute((int)startAddress);
            }
            stoper.Stop();
            Console.WriteLine(stoper.ElapsedMilliseconds);
            Console.WriteLine(cpu.InstructionsExecuted);
            Console.WriteLine($"{(double)cpu.InstructionsExecuted / stoper.ElapsedMilliseconds / 1000} MIPS");
            cpu.Reset();


            stoper = Stopwatch.StartNew();
            for (var i = 0; i < 100; ++i)
            {
                cpu.Execute((int)startAddress);
            }
            stoper.Stop();
            Console.WriteLine(stoper.ElapsedMilliseconds);
            Console.WriteLine(cpu.InstructionsExecuted);
            Console.WriteLine($"{(double)cpu.InstructionsExecuted / stoper.ElapsedMilliseconds / 1000} MIPS");
        }