private MappedMemoryUnit BuildMappedMemUnit(uint[] data, uint startAddr)
        {
            DataMemory       dataMem   = new DataMemory(data);
            MappedMemoryUnit mappedMem = new MappedMemoryUnit(dataMem, startAddr);

            return(mappedMem);
        }
Example #2
0
        public void ParsesHexAndBinValues()
        {
            MappedMemoryUnit memUnit = target.Mips.Memory.MemUnits[4];

            Assert.IsInstanceOf(typeof(DataMemory), memUnit.MemUnit);
            Assert.AreEqual(0xDEADBEEF, memUnit.StartAddr);
            Assert.AreEqual(0b100, memUnit.Size / memUnit.WordSize);
        }
        public void Construct_Bitmask()
        {
            MappedMemoryUnit target = new MappedMemoryUnit(memUnit, " _1_0_xXxx_\r\n");

            Assert.AreEqual(0b100000, target.StartAddr);
            Assert.AreEqual(0b101111, target.EndAddr);
            Assert.AreEqual(memUnit, target.MemUnit);
        }
        public void Construct_WithStartAddress_ImplicitEndAddress()
        {
            MappedMemoryUnit target = new MappedMemoryUnit(memUnit, 12);

            Assert.AreEqual(12, target.StartAddr);
            Assert.AreEqual(27, target.EndAddr);
            Assert.AreEqual(memUnit, target.MemUnit);
        }
        public void Construct_WithStartAndEndAddresses()
        {
            MappedMemoryUnit target = new MappedMemoryUnit(memUnit, 12, 44);

            Assert.AreEqual(12, target.StartAddr);
            Assert.AreEqual(44, target.EndAddr);
            Assert.AreEqual(memUnit, target.MemUnit);
        }
        public void SetUp()
        {
            MappedMemoryUnit mappedMem  = BuildMappedMemUnit(new uint[] { 1, 2, 3, 4 }, 0);
            MappedMemoryUnit mappedMem2 = BuildMappedMemUnit(new uint[] { 5, 6, 7, 8 }, 16);
            MappedMemoryUnit mappedMem3 = BuildMappedMemUnit(new uint[] { 9, 10, 11, 12 }, 100);
            var memUnitList             = new List <MappedMemoryUnit> {
                mappedMem2, mappedMem3, mappedMem
            };

            target = new MemoryMapper(memUnitList);
        }
Example #7
0
        //[Ignore("TEST NOT YET NEEDED")]
        public void TestInitInstructionMemory()
        {
            uint[] instructions = new uint[] {
                0x201d0f3c, 0x3c08ffff, 0x3508ffff, 0x2009ffff, 0x1509001b, 0x00084600, 0x3508f000, 0x00084203, 0x00084102,
                0x340a0003, 0x01495022, 0x01484004, 0x010a582a, 0x010a582b, 0x20080005, 0x2d0b000a, 0x2d0b0004, 0x2008fffb,
                0x2d0b0005, 0x3c0b1010, 0x356b1010, 0x3c0c0101, 0x218c1010, 0x016c6824, 0x016c6825, 0x016c6826, 0x016c6827,
                0x8c040004, 0x20840002, 0x2484fffe, 0x0c000021, 0xac020000, 0x08000020, 0x23bdfff8, 0xafbf0004, 0xafa40000,
                0x28880002, 0x11000002, 0x00041020, 0x0800002e, 0x2084ffff, 0x0c000021, 0x8fa40000, 0x00441020, 0x00441020,
                0x2042ffff, 0x8fbf0004, 0x23bd0008, 0x03e00008
            };

            InstructionFactory instrFact = new InstructionFactory();

            Instruction[] instrs = new Instruction[instructions.Length];
            int           i      = 0;

            foreach (uint instr in instructions)
            {
                instrs[i] = instrFact.CreateInstruction(instr);
                i++;
            }

            target = new InstructionMemory(instrs);

            uint pc = 0;

            var dataMem  = new DataMemory(10000);
            var map      = new MappedMemoryUnit(dataMem, 0);
            var unitList = new List <MappedMemoryUnit> {
                map
            };
            var dataMemory = new MemoryMapper(unitList);
            var registers  = new Registers();

            int icount = 0;

            uint a = 99;

            dataMemory[4] = a;

            while (pc < instructions.Length * 4 && icount < 1000000)
            {
                //Console.WriteLine($"{pc:X8}: {target[pc]}");
                target.GetInstruction(pc).Execute(ref pc, dataMemory, registers);
                icount++;
            }

            Console.WriteLine(dataMemory[0]);

            Assert.AreEqual(a * a, dataMemory[0]);
        }
Example #8
0
        private static ObservableCollection <MemoryLocationInfo> GetMemoryContents(MappedMemoryUnit selectedUnit)
        {
            ObservableCollection <MemoryLocationInfo> memoryItems = new ObservableCollection <MemoryLocationInfo>();

            for (uint index = 0; index < selectedUnit.Size; index += selectedUnit.WordSize)
            {
                uint?mappedAddress   = (index + selectedUnit.StartAddr <= selectedUnit.EndAddr) ? index + selectedUnit.StartAddr : (uint?)null;
                uint relativeAddress = index;
                uint value           = selectedUnit[index];
                memoryItems.Add(new MemoryLocationInfo(mappedAddress, relativeAddress, value));
            }

            return(memoryItems);
        }
Example #9
0
        public void RefreshDisplay()
        {
            MappedMemoryUnit selectedUnit = memUnits[MemoryTabs.SelectedIndex];

            for (uint index = selectedUnit.StartAddr; index < selectedUnit.StartAddr + selectedUnit.Size; index += selectedUnit.WordSize)
            {
                uint relativeAddress = index - selectedUnit.StartAddr;
                if (selectedMemoryContents[(int)(relativeAddress / selectedUnit.WordSize)].Value != selectedUnit[relativeAddress])
                {
                    uint?mappedAddress = (index < selectedUnit.EndAddr) ? index : (uint?)null;
                    selectedMemoryContents[(int)(relativeAddress / selectedUnit.WordSize)] = new MemoryLocationInfo(mappedAddress, relativeAddress, mapper[index]);
                }
            }
        }
Example #10
0
        public void SetUp()
        {
            uint[] instructions = new uint[] {
                0x201d0f3c, 0x3c08ffff, 0x3508ffff, 0x2009ffff, 0x1509001b, 0x00084600, 0x3508f000, 0x00084203, 0x00084102,
                0x340a0003, 0x01495022, 0x01484004, 0x010a582a, 0x010a582b, 0x20080005, 0x2d0b000a, 0x2d0b0004, 0x2008fffb,
                0x2d0b0005, 0x3c0b1010, 0x356b1010, 0x3c0c0101, 0x218c1010, 0x016c6824, 0x016c6825, 0x016c6826, 0x016c6827,
                0x8c040004, 0x20840002, 0x2484fffe, 0x0c000021, 0xac020000, 0x08F00020, 0x23bdfff8, 0xafbf0004, 0xafa40000,
                0x28880002, 0x11000002, 0x00041020, 0x0800002e, 0x2084ffff, 0x0c000021, 0x8fa40000, 0x00441020, 0x00441020,
                0x2042ffff, 0x8fbf0004, 0x23bd0008, 0x03e00008
            };
            InstructionFactory instrFact = new InstructionFactory();

            Instruction[] instrs = new Instruction[instructions.Length];
            for (int i = 0; i < instructions.Length; i++)
            {
                instrs[i] = instrFact.CreateInstruction(instructions[i]);
            }

            InstructionMemory instrMem = new InstructionMemory(instrs);
            var dataMem = new DataMemory(10000);

            dataMem[4] = 99;
            var map      = new MappedMemoryUnit(dataMem, 0);
            var unitList = new List <MappedMemoryUnit> {
                map
            };
            var mem = new MemoryMapper(unitList);

            memDict = new Dictionary <Type, List <MemoryUnit> >();
            memDict.Add(instrMem.GetType(), new List <MemoryUnit> {
                instrMem
            });
            memDict.Add(mem.GetType(), new List <MemoryUnit> {
                mem
            });

            target = new Mips(0x0, memDict);
        }