コード例 #1
0
        public void Test3()
        {
            // Arrange
            var instruction = new Byte2(-985);

            // Act

            var decodedInstruction = InstructionDecoder.Decode(instruction);

            // Assert
            decodedInstruction.ComputationInstruction.Should().BeTrue();
            decodedInstruction.SourceMemory.Should().BeTrue();
            decodedInstruction.Operation.zx.Should().BeTrue();
            decodedInstruction.Operation.nx.Should().BeTrue();
            decodedInstruction.Operation.zy.Should().BeFalse();
            decodedInstruction.Operation.ny.Should().BeFalse();
            decodedInstruction.Operation.Function.Should().BeFalse();
            decodedInstruction.Operation.NegateOutput.Should().BeFalse();
            decodedInstruction.Destination.A.Should().BeTrue();
            decodedInstruction.Destination.D.Should().BeFalse();
            decodedInstruction.Destination.Ram.Should().BeFalse();
            decodedInstruction.Condition.GreaterThanZero.Should().BeTrue();
            decodedInstruction.Condition.EqualToZero.Should().BeTrue();
            decodedInstruction.Condition.LessThanZero.Should().BeTrue();
            decodedInstruction.w.ToInt16().Should().Be(0);
        }
コード例 #2
0
ファイル: Z80CPU.cs プロジェクト: wchill/Z80Sharp
        private void HandleINT()
        {
            // TODO: Check if INT is supposed to be able to fire during this push and other memory operations
            var opcode = AcknowledgeInterrupt();

            if (Registers.InterruptMode == Z80InterruptMode.External)
            {
                var instr = InstructionDecoder.DecodeNextInstruction(this, opcode);
                instr.Execute(this, instr.InstructionBytes);
            }
            else if (Registers.InterruptMode == Z80InterruptMode.FixedAddress)
            {
                PushWord(Registers.PC);
                Registers.PC = 0x38;
            }
            else if (Registers.InterruptMode == Z80InterruptMode.Vectorized)
            {
                var upper = Registers.I;
                var lower = opcode;
                var addr  = Utilities.LETo16Bit(lower, upper);
                PushWord(Registers.PC);
                var jumpAddr = ReadWord(addr);
                Registers.PC = jumpAddr;
            }
        }
コード例 #3
0
        public ControlUnitOutput Do(Byte2 data, bool clock)
        {
            var decodedInstruction = InstructionDecoder.Decode(data);

            var selectedSourceMemory =
                Select16.Do(decodedInstruction.SourceMemory,
                            _memoryOutput.Ram,
                            _memoryOutput.A);

            _aluOutput =
                ArithmeticLogicUnit.Do(decodedInstruction.Operation,
                                       _memoryOutput.D,
                                       selectedSourceMemory);

            _selectedBasedOnComputationInstruction =
                Select16.Do(decodedInstruction.ComputationInstruction,
                            _aluOutput,
                            decodedInstruction.w);

            _memoryOutput = _memory.Do(decodedInstruction.Destination,
                                       _selectedBasedOnComputationInstruction,
                                       clock);

            var isCondition =
                ArithmeticLogicUnit.Evaluate(decodedInstruction.Condition,
                                             _aluOutput);

            return(new ControlUnitOutput(isCondition, _memoryOutput.A));
        }
コード例 #4
0
 public InferenceDisassembler(VMConstants constants, KoiStream koiStream)
 {
     Constants   = constants ?? throw new ArgumentNullException(nameof(constants));
     KoiStream   = koiStream ?? throw new ArgumentNullException(nameof(koiStream));
     _decoder    = new InstructionDecoder(constants, KoiStream.Contents.CreateReader());
     _processor  = new InstructionProcessor(this);
     _cfgBuilder = new ControlFlowGraphBuilder();
 }
コード例 #5
0
ファイル: Machine.cs プロジェクト: OdeToCode/Blazork
 public Machine(ILogger logger, IInputStream inputStream)
 {
     Memory      = new MachineMemory(Stream.Null);
     StackFrames = new FrameCollection(logger);
     ObjectTable = new GameObjectTable(this);
     Decoder     = new InstructionDecoder(this);
     Output      = new CompositeOutputStream(new DebugOutputStream(logger));
     Logger      = logger.ForContext <Machine>();
     Input       = inputStream;
 }
コード例 #6
0
        public void DefinedCpuInstructions_AreCorrectlyDecoded()
        {
            var instructionDecoder = new InstructionDecoder();

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x00E0)), Is.InstanceOf <Instruction_00E0>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x00EE)), Is.InstanceOf <Instruction_00EE>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x1248)), Is.InstanceOf <Instruction_1nnn>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x2468)), Is.InstanceOf <Instruction_2nnn>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x3468)), Is.InstanceOf <Instruction_3xkk>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x4468)), Is.InstanceOf <Instruction_4xkk>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x5460)), Is.InstanceOf <Instruction_5xy0>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x6123)), Is.InstanceOf <Instruction_6xkk>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x7123)), Is.InstanceOf <Instruction_7xkk>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x8AB0)), Is.InstanceOf <Instruction_8xy0>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x8AB1)), Is.InstanceOf <Instruction_8xy1>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x8AB2)), Is.InstanceOf <Instruction_8xy2>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x8AB3)), Is.InstanceOf <Instruction_8xy3>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x8AB4)), Is.InstanceOf <Instruction_8xy4>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x8AB5)), Is.InstanceOf <Instruction_8xy5>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x8AB6)), Is.InstanceOf <Instruction_8xy6>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x8AB7)), Is.InstanceOf <Instruction_8xy7>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x8ABE)), Is.InstanceOf <Instruction_8xyE>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x9460)), Is.InstanceOf <Instruction_9xy0>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xA123)), Is.InstanceOf <Instruction_Annn>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xB123)), Is.InstanceOf <Instruction_Bnnn>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xC123)), Is.InstanceOf <Instruction_Cxkk>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xD123)), Is.InstanceOf <Instruction_Dxyn>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xE19E)), Is.InstanceOf <Instruction_Ex9E>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xE1A1)), Is.InstanceOf <Instruction_ExA1>());

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xFA07)), Is.InstanceOf <Instruction_Fx07>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xF10A)), Is.InstanceOf <Instruction_Fx0A>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xFA15)), Is.InstanceOf <Instruction_Fx15>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xFA18)), Is.InstanceOf <Instruction_Fx18>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xFA1E)), Is.InstanceOf <Instruction_Fx1E>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xFA29)), Is.InstanceOf <Instruction_Fx29>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xFA33)), Is.InstanceOf <Instruction_Fx33>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xF155)), Is.InstanceOf <Instruction_Fx55>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xF165)), Is.InstanceOf <Instruction_Fx65>());
        }
コード例 #7
0
        static void Decode()
        {
            int address = TEXT_SECTION_START;

            while (_memory.Read(address).Any(x => x != 0))
            {
                byte[] bytes = _memory.Read(address);
                InstructionDecoder.PrintInstruction(bytes);
                address += 4;
            }
        }
コード例 #8
0
        public void EightBitOpcodeRegisterBInBits0To3(int register)
        {
            var decoder = new InstructionDecoder();

            ForEachOpcode(EightBitOpcodes, opcode =>
            {
                var encodedInstruction = (ushort)(opcode | (register << 0));
                var decodedInstruction = decoder.Decode(encodedInstruction);
                decodedInstruction.RegisterB.Should().Be(register);
            });
        }
コード例 #9
0
        private static TInstruction AssertBytesDecodedAs <TInstruction>(byte[] bytes) where TInstruction : IInstruction
        {
            var(instruction, bytesRead) = InstructionDecoder.Decode(bytes);

            Assert.IsType <TInstruction>(instruction);
            var loadInstruction = (TInstruction)instruction;

            //Whole message was read
            Assert.Equal(bytes.Length, bytesRead);
            return(loadInstruction);
        }
コード例 #10
0
            public Decode()
            {
                var instructions = new Instruction[]
                {
                    new Add(),
                    new Multiply(),
                    new Halt()
                };

                Decoder = new InstructionDecoder(instructions);
            }
コード例 #11
0
        public void FourBitOpcodeRegisterAInBits7To11(int register)
        {
            var decoder = new InstructionDecoder();

            ForEachOpcode(FourBitOpcodes, opcode =>
            {
                var encodedInstruction = (ushort)(opcode | (register << 8));
                var decodedInstruction = decoder.Decode(encodedInstruction);
                decodedInstruction.RegisterA.Should().Be(register);
            });
        }
コード例 #12
0
        void TestOpcodeParameter(IEnumerable <Opcode> opcodes, ushort rawValue, int expectedDecodedValue)
        {
            var decoder = new InstructionDecoder();

            ForEachOpcode(opcodes, opcode =>
            {
                var encodedInstruction = (ushort)(opcode | rawValue);
                var decodedInstruction = decoder.Decode(encodedInstruction);
                decodedInstruction.Value.Should().Be(expectedDecodedValue);
            });
        }
コード例 #13
0
        public void UndefinedCpuInstructions_AreDecodedAsUndefinedInstructions()
        {
            var instructionDecoder = new InstructionDecoder();

            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x0000)), Is.InstanceOf <UndefinedInstruction>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x5468)), Is.InstanceOf <UndefinedInstruction>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x8468)), Is.InstanceOf <UndefinedInstruction>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0x9468)), Is.InstanceOf <UndefinedInstruction>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xE101)), Is.InstanceOf <UndefinedInstruction>());
            Assert.That(instructionDecoder.GetCpuInstruction(new DecodedInstruction(0xF1FF)), Is.InstanceOf <UndefinedInstruction>());
        }
コード例 #14
0
        public void Init(ulong programCounter)
        {
            // Set the instruction decoder and type decoder
            instructionDecoder = new InstructionDecoder(EndianType.Little);
            typeDecoder        = new TypeDecoder();
            rvcDecoder         = new RvcDecoder(architecture);

            InitDetails(programCounter);
            environment.ApplyOutputParameter(configuration.Debug, configuration.VerboseMode);

            isInitialized = true;
        }
コード例 #15
0
        public void For_data_instruction_W_returns_input()
        {
            // Arrange
            var instruction = new Byte2(17);

            // Act

            var decodedInstruction = InstructionDecoder.Decode(instruction);

            // Assert
            decodedInstruction.w.ToInt16().Should().Be(17);
        }
コード例 #16
0
ファイル: Debugger.cs プロジェクト: claassen/RIVM
        private void updateMemoryDisplay()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn("address", typeof(string)));
            dt.Columns.Add(new DataColumn("value", typeof(string)));
            dt.Columns.Add(new DataColumn("instruction", typeof(String)));

            int start = _memoryDisplayStartAddress;
            int end   = start + 1000;

            for (int address = start; address < end;)
            {
                if (_memoryDisplaySize == 4)
                {
                    int machineCode = _vm.cpu.Memory.Get(address, false, 4);

                    object[] firstRowData = new object[3];
                    firstRowData[0] = address;
                    firstRowData[1] = machineCode;

                    address += 4;

                    Instruction instruction = InstructionDecoder.Decode(machineCode);

                    if (instruction.HasImmediate)
                    {
                        instruction.Immediate = _vm.cpu.Memory.Get(address, false, 4);
                        address += 4;
                    }

                    firstRowData[2] = instruction.ToString();
                    dt.Rows.Add(firstRowData);

                    if (instruction.HasImmediate)
                    {
                        dt.Rows.Add(address - 4, instruction.Immediate, "[immediate value]");
                    }
                }
                else
                {
                    int value = BitHelper.ExtractBytes(_vm.cpu.Memory.Get(address, false, 1), 1);
                    dt.Rows.Add(address, value, "");
                    address++;
                }
            }

            memoryGridView.Invoke((MethodInvoker)(() =>
            {
                memoryGridView.DataSource = dt;
            }));
        }
コード例 #17
0
        public void Decode_Works()
        {
            var instructionDecoder = new InstructionDecoder();
            var decodedInstruction = instructionDecoder.Decode(0x12, 0x34);

            Assert.That(decodedInstruction.InstructionCode, Is.EqualTo(0x1234));
            Assert.That(decodedInstruction.nnn, Is.EqualTo(0x234));
            Assert.That(decodedInstruction.n, Is.EqualTo(0x4));
            Assert.That(decodedInstruction.x, Is.EqualTo(0x2));
            Assert.That(decodedInstruction.y, Is.EqualTo(0x3));
            Assert.That(decodedInstruction.kk, Is.EqualTo(0x34));
            Assert.That(decodedInstruction.OpCode, Is.EqualTo(0x1));
        }
コード例 #18
0
        public void Step()
        {
            try
            {
                int machineCode = Fetch();
                _currentInstruction = InstructionDecoder.Decode(machineCode);

                if (_currentInstruction is Break)
                {
                    _debugging = true;
                    _debuggingNotification();
                }

                if (_currentInstruction.HasImmediate)
                {
                    _currentInstruction.Immediate = Fetch();
                }

                _currentInstruction.Execute(this);

                if (Interrupts.Count > 0)
                {
                    lock (Interrupts)
                    {
                        throw new InterruptException(Interrupts.Dequeue());
                    }
                }
            }
            catch (InterruptException ex)
            {
                //Index into Interrupt Descriptor Table
                int interrupt = ex.InterruptNumber;

                KernelMode = true;

                //TODO: Need to switch to kernel stack? Should this be handled by IR common stub?

                //Similar to a call, stored the address where code should resume executing on the stack
                Memory[Registers[Register.SP]] = Registers[Register.IP];
                Registers[Register.SP]        += 4;

                //Set IP to fixed interrupt handler address
                Registers[Register.IP] = Memory[IDTPointer + interrupt * 4];
            }

            if (_stepNotification != null && _debugging)
            {
                _stepNotification();
            }
        }
コード例 #19
0
        public void SetRegisterValues(int currentInstruction, int[] registers)
        {
            int readRegister1 = InstructionDecoder.source_reg1(currentInstruction);
            int readRegister2 = InstructionDecoder.source_reg2(currentInstruction);
            int writeRegister = InstructionDecoder.dest_reg(currentInstruction);


            ReadReg1Value  = registers[readRegister1];
            ReadReg2Value  = registers[readRegister2];
            WriteReg_20_16 = readRegister2;
            WriteReg_15_11 = writeRegister;
            SEOffset       = InstructionDecoder.offset(currentInstruction);
            Function       = InstructionDecoder.func_code(SEOffset);
        }
コード例 #20
0
        public List <DisassembledInstruction> Disassemble(ushort address)
        {
            Registers.PC = address;
            var instructions = new List <DisassembledInstruction>();
            DisassembledInstruction instruction;

            do
            {
                instruction = InstructionDecoder.DecodeNextInstruction(this);
                instructions.Add(instruction);
            } while (!instruction.ControlInstruction);

            return(instructions);
        }
コード例 #21
0
        public void DecodesOpeningZorkInstruction()
        {
            using var file = File.OpenRead(@"Data\ZORK1.DAT");
            var logger  = NullLoggerFactory.GetLogger();
            var machine = new Machine(logger, new SolveZorkInputStream());

            machine.Load(file);

            var decoder     = new InstructionDecoder(machine);
            var memory      = machine.Memory.SpanAt(machine.PC);
            var instruction = decoder.Decode(memory);

            instruction.Prepare(memory);
            instruction.Execute(memory);

            Assert.NotNull(instruction as VarInstruction);
            Assert.Equal("Call", instruction.Operation.Name);
            Assert.Equal(0, instruction.OpCode);
            Assert.Equal(0, instruction.StoreResult);
            Assert.Equal(3, instruction.Operands.Count);
            Assert.Equal(0x5479, machine.PC);

            memory      = machine.Memory.SpanAt(machine.PC);
            instruction = decoder.Decode(memory);
            instruction.Prepare(memory);
            instruction.Execute(memory);

            Assert.NotNull(instruction as VarInstruction);
            Assert.Equal("Call", instruction.Operation.Name);
            Assert.Equal(2, instruction.Operands.Count);
            Assert.Equal(3, instruction.StoreResult);
            Assert.Equal(OperandType.Variable, instruction.Operands[1].Type);
            Assert.Equal(1, instruction.Operands[1].RawValue);

            memory      = machine.Memory.SpanAt(machine.PC);
            instruction = decoder.Decode(memory);
            instruction.Prepare(memory);
            instruction.Execute(memory);

            Assert.NotNull(instruction as Op2Instruction);
            Assert.Equal("Add", instruction.Operation.Name);
            Assert.Equal(4, instruction.Size);
            Assert.Equal(2, instruction.Operands.Count);
            Assert.Equal(OperandType.Variable, instruction.Operands[0].Type);
            Assert.Equal(0x94, instruction.Operands[0].RawValue);
            Assert.Equal(OperandType.Small, instruction.Operands[1].Type);
            Assert.Equal(0xB4, instruction.Operands[1].RawValue);
            Assert.Equal(0x03, instruction.StoreResult);
        }
コード例 #22
0
        public void DecodeStream_StreamWithMultipleOpcode_DecodesInstructions()
        {
            var bytesStream = InstructionByteBuilder.Create()
                              .Opcode(Opcode.Load, LoadKind.Integer, 42)
                              .Opcode(Opcode.Load, LoadKind.Integer, 69)
                              .Opcode(Opcode.Add)
                              .Opcode(Opcode.Return)
                              .AsStream();

            var instructions = InstructionDecoder.DecodeStream(bytesStream).ToList();

            Assert.Equal(4, instructions.Count);
            Assert.Equal("add", instructions.ElementAt(2).ToString());
            Assert.Equal("ret", instructions.ElementAt(3).ToString());
        }
コード例 #23
0
        public override void Execute(Dictionary <string, object> data)
        {
            var decoder = new InstructionDecoder(new Instruction[]
            {
                new Add(),
                new Multiply(),
                new Halt()
            });

            var computer = new Computer(decoder);

            computer.State.Memory = (int[])data[_programKey];

            computer.Run();
        }
コード例 #24
0
        public M6502Core(uint frequency)
        {
            Pins      = new PinsState();
            Bus       = new Bus(this);
            Registers = new RegistersState();

            _instructionDecoder = new InstructionDecoder(this);
            _interruptsLogic    = new InterruptsLogic(this);
            _frequency          = frequency;

            if (frequency != 0)
            {
                _ticksPerCycle = TimeSpan.TicksPerSecond / (ulong)_frequency;
            }
        }
コード例 #25
0
        public void SetExecutionPath(int currentinstruction)
        {
            if ((InstructionDecoder.is_r_format(currentinstruction)) &&
                ((InstructionDecoder.rfunct(currentinstruction) == InstructionType.Subtract) ||
                 InstructionDecoder.rfunct(currentinstruction) == InstructionType.Add))
            {
                _regDestination = 1;
                _ALUOp          = 10;
                _ALUSrc         = 0;
                _MemRead        = 0;
                _MemWrite       = 0;
                _RegWrite       = 1;
                _MemToReg       = 0;
            }

            else if (InstructionDecoder.getOPcode(currentinstruction) == InstructionType.LoadByte)
            {
                _regDestination = 0;
                _ALUOp          = 0;
                _ALUSrc         = 1;
                _MemRead        = 1;
                _MemWrite       = 0;
                _RegWrite       = 1;
                _MemToReg       = 1;
            }

            else if (InstructionDecoder.getOPcode(currentinstruction) == InstructionType.StoreByte)
            {
                _regDestination = 0;
                _ALUOp          = 0;
                _ALUSrc         = 1;
                _MemRead        = 0;
                _MemWrite       = 1;
                _RegWrite       = 0;
                _MemToReg       = 0;
            }

            else
            {
                _regDestination = 0;
                _ALUOp          = 0;
                _ALUSrc         = 0;
                _MemRead        = 0;
                _MemWrite       = 0;
                _RegWrite       = 0;
                _MemToReg       = 0;
            }
        }
コード例 #26
0
ファイル: Debugger.cs プロジェクト: claassen/RIVM
        private Instruction getNextInstruction()
        {
            int address = _vm.cpu.Registers[Register.IP];

            int machineCode = _vm.cpu.Memory.Get(address, false, 4);

            address += 4;

            Instruction instruction = InstructionDecoder.Decode(machineCode);

            if (instruction.HasImmediate)
            {
                instruction.Immediate = _vm.cpu.Memory.Get(address, false, 4);
            }

            return(instruction);
        }
コード例 #27
0
ファイル: Program.cs プロジェクト: szpght/moha
        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);
            }
        }
コード例 #28
0
 public void InitTestFixture()
 {
     _instructionDecoder = new InstructionDecoder();
 }
コード例 #29
0
 public ModRmOpcodeDecoder(
     InstructionDecoder defaultDecoder,
     params (byte, InstructionDecoder) [] decoders)
コード例 #30
0
ファイル: Program.cs プロジェクト: szpght/moha
        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");
        }