Exemplo n.º 1
0
 public static void SetHookAfterRead(this SystemBus sysbus, IBusPeripheral peripheral, string pythonScript, Range? subrange = null)
 {
     var runner = new BusHooksPythonEngine(sysbus, peripheral, pythonScript);
     sysbus.SetHookAfterRead<uint>(peripheral, runner.ReadHook, subrange);
     sysbus.SetHookAfterRead<ushort>(peripheral, (readValue, offset) => (ushort)runner.ReadHook(readValue, offset), subrange);
     sysbus.SetHookAfterRead<byte>(peripheral, (readValue, offset) => (byte)runner.ReadHook(readValue, offset), subrange);
 }
Exemplo n.º 2
0
 public static void SetHookBeforeWrite(this SystemBus sysbus, IBusPeripheral peripheral, string pythonScript, Range? subrange = null)
 {
     var runner = new BusHooksPythonEngine(sysbus, peripheral, null, pythonScript);
     sysbus.SetHookBeforeWrite<uint>(peripheral, runner.WriteHook, subrange);
     sysbus.SetHookBeforeWrite<ushort>(peripheral, (valueToWrite, offset) => (ushort)runner.WriteHook(valueToWrite, offset), subrange);
     sysbus.SetHookBeforeWrite<byte>(peripheral, (valueToWrite, offset) => (byte)runner.WriteHook(valueToWrite, offset), subrange);
 }
Exemplo n.º 3
0
 public void ShouldShiftRange()
 {
     var range = new Range(0x2200, 0x200);
     var expectedResult = new Range(0x2500, 0x200);
     var result = range.ShiftBy(0x300);
     Assert.AreEqual(expectedResult, result);
 }
Exemplo n.º 4
0
 public void ShouldIntersectRangesWithOneCommonAddress()
 {
     var range1 = new Range(0x1000, 0x200);
     var range2 = new Range(0x11ff, 0x300);
     var expectedResult = new Range(0x11ff, 0x1);
     var intersection = range1.Intersect(range2);
     Assert.AreEqual(expectedResult, intersection);
 }
Exemplo n.º 5
0
        public RelativeRangeToken(string value) : base(value)
        {
            var trimmed = value.TrimStart('<').TrimEnd('>');
            var split = trimmed.Split(new []{ ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
            var resultValues = ParseNumbers(split);

            Value = new Range(resultValues[0], resultValues[1]);
        }
Exemplo n.º 6
0
 public Range Intersect(Range range)
 {
     var startAddress = Math.Max(StartAddress, range.StartAddress);
     var endAddress = Math.Min(EndAddress, range.EndAddress);
     if(startAddress >= endAddress)
     {
         return Range.Empty;
     }
     return new Range(startAddress, endAddress - startAddress);
 }
Exemplo n.º 7
0
 public void ShouldIntersectRange()
 {
     var range1 = new Range(0x1000, 0x200);
     var range2 = new Range(0x1100, 0x300);
     var expectedResult = new Range(0x1100, 0x100);
     var intersection1 = range1.Intersect(range2);
     var intersection2 = range2.Intersect(range1);
     Assert.AreEqual(expectedResult, intersection1);
     Assert.AreEqual(expectedResult, intersection2);
 }
Exemplo n.º 8
0
 public static bool TryCreate(long startAddress, long size, out Range range)
 {
     range = default(Range);
     if(size < 0)
     {
         return false;
     }
     range.StartAddress = startAddress;
     range.EndAddress = startAddress + size;
     return true;
 }
Exemplo n.º 9
0
        public void UnmapMemory(Range range)
        {
            using(machine.ObtainPausedState())
            {
                var startAddress = checked((uint)range.StartAddress);
                var endAddress = checked((uint)(range.EndAddress - 1));
                ValidateMemoryRangeAndThrow(startAddress, (uint)range.Size);

                // when unmapping memory, two things has to be done
                // first is to flag address range as no-memory (that is, I/O)
                TlibUnmapRange(startAddress, endAddress);

                // and second is to remove mappings that are not used anymore
                currentMappings = currentMappings.
                    Where(x => TlibIsRangeMapped((uint)x.Segment.StartingOffset, (uint)(x.Segment.StartingOffset + x.Segment.Size)) == 1).ToList();
            }
        }
Exemplo n.º 10
0
		public static void Register(this SystemBus sysbus, IBusPeripheral peripheral, Range range)
		{
			sysbus.Register(peripheral, new BusRangeRegistration(range));
		}
Exemplo n.º 11
0
 public virtual void UnmapMemory(Range range)
 {
 }
Exemplo n.º 12
0
 protected HookWrapper(IBusPeripheral peripheral, Type type, Range? subrange)
 {
     Peripheral = peripheral;
     Name = type.Name;
     Subrange = subrange;
 }
Exemplo n.º 13
0
 public void ShouldContainItself()
 {
     var range = new Range(0x1000, 0x1200);
     Assert.IsTrue(range.Contains(range));
 }
Exemplo n.º 14
0
 public void ShouldNotContainNearbyAddresses()
 {
     var range = new Range(0x600, 0x100);
     Assert.IsFalse(range.Contains(0x5FF));
     Assert.IsFalse(range.Contains(0x700));
 }
Exemplo n.º 15
0
 public static void Register(this SystemBus sysbus, IBusPeripheral peripheral, Range range)
 {
     sysbus.Register(peripheral, new BusRangeRegistration(range));
 }
Exemplo n.º 16
0
        public void RelativeRangeTest()
        {
            var result = tokenizer.Tokenize("<-5,+5>");
            var expectedValue = new Range(-5, 11);
            AssertTokenizationTypes(result, typeof(AbsoluteRangeToken));
            AssertTokenizationValues(result, expectedValue);

            result = tokenizer.Tokenize("<0x6 0x2>");
            expectedValue = new Range(0x6, 0x2);
            AssertTokenizationTypes(result, typeof(RelativeRangeToken));
            AssertTokenizationValues(result, expectedValue);
        }
Exemplo n.º 17
0
        public void RangeTest()
        {
            var result = tokenizer.Tokenize("<-5,+5>");
            var expectedValue = new Range(-5, 11);
            AssertTokenizationTypes(result, typeof(AbsoluteRangeToken));
            AssertTokenizationValues(result, expectedValue);

            result = tokenizer.Tokenize("<    \t0x123abDE  \t, \t\t  0xabcdef0 \t\t   >");
            expectedValue = new Range(0x123abde, 0xabcdef0 - 0x123abde + 1);
            AssertTokenizationTypes(result, typeof(AbsoluteRangeToken));
            AssertTokenizationValues(result, expectedValue);

            result = tokenizer.Tokenize("<0xdefg, 0xefgh>");
            AssertTokenizationResult(result, 16);

            result = tokenizer.Tokenize("<5,-6>");
            AssertTokenizationResult(result, 6, typeof(RecoverableException));
        }
Exemplo n.º 18
0
 public bool Contains(Range range)
 {
     return range.StartAddress >= StartAddress && range.EndAddress <= EndAddress;
 }
Exemplo n.º 19
0
 public void ShouldContainLastAddress()
 {
     var range = new Range(0x1600, 0xA00);
     Assert.IsTrue(range.Contains(0x1fff));
 }
Exemplo n.º 20
0
 public bool Intersects(Range range)
 {
     return Intersect(range) != Range.Empty;
 }
Exemplo n.º 21
0
 public BusRangeRegistration(Range range, long offset = 0)
 {
     Range = range;
     Offset = offset;
 }