Exemplo n.º 1
0
        Mmu CreateMmu()
        {
            var mmu = new Mmu(MemorySize);

            mmu.CopyToPhysical(DestinationOffset, SampleData.Span);
            return(mmu);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        public Benchmark()
        {
            const int memorySize = 32 * 1024 * 1024;
            var       mmu        = new Mmu(memorySize);
            var       decoder    = new InstructionDecoder();

            cpu1 = new Cpu <PhysicalMemoryAccessor, NoTracing>(mmu, decoder);
            cpu2 = new Cpu <PhysicalMemoryAccessor, NoTracing>(mmu, decoder);
            mmu._pageDirectory = memorySize - 4;

            var elf = ELFReader.Load <uint>("D:\\fibo");

            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);
            }
        }
Exemplo n.º 4
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");
        }