protected TranslationCPU(string cpuType, Machine machine, EndiannessEnum endianness) { if(cpuType == null) { throw new RecoverableException(new ArgumentNullException("cpuType")); } Endianness = endianness; PerformanceInMips = 100; currentCountThreshold = 5000; this.cpuType = cpuType; ClockSource = new BaseClockSource(); ClockSource.NumberOfEntriesChanged += (oldValue, newValue) => { if(oldValue > newValue) { Misc.Swap(ref oldValue, ref newValue); } if(oldValue == 0 && newValue != 0) { ClearTranslationCache(); } }; this.translationCacheSize = DefaultTranslationCacheSize; this.machine = machine; started = false; isHalted = false; translationCacheSync = new object(); pumpingModeSync = new object(); InitializeRegisters(); InitInterruptEvents(); Init(); InitDisas(); }
public void ShouldTickWithOneHandler() { var clocksource = new BaseClockSource(); var counter = 0; clocksource.AddClockEntry(new ClockEntry(2, 1, () => counter++) { Value = 0 }); clocksource.Advance(1); Assert.AreEqual(0, counter); clocksource.Advance(1); Assert.AreEqual(1, counter); clocksource.Advance(1); Assert.AreEqual(1, counter); clocksource.Advance(2); Assert.AreEqual(2, counter); }
public void ShouldTickWithTwoHandlers() { var clocksource = new BaseClockSource(); var counterA = 0; var counterB = 0; clocksource.AddClockEntry(new ClockEntry(2, 1, () => counterA++) { Value = 0 }); clocksource.AddClockEntry(new ClockEntry(5, 1, () => counterB++) { Value = 0 }); clocksource.Advance(2); Assert.AreEqual(1, counterA); Assert.AreEqual(0, counterB); clocksource.Advance(2); Assert.AreEqual(2, counterA); Assert.AreEqual(0, counterB); clocksource.Advance(1); Assert.AreEqual(2, counterA); Assert.AreEqual(1, counterB); }
public void ShouldHaveHandlersInSync() { // we test here whether handler executed by the slower clock entry // always "sees" value of the faster one as ten times its own value var clockSource = new BaseClockSource(); Action firstHandler = () => { }; var values = new List<long>(); // clock entry with ratio -10 is 10 times slower than the one with 1 clockSource.AddClockEntry(new ClockEntry(10000, 1, firstHandler)); clockSource.AddClockEntry(new ClockEntry(1, -10, () => values.Add(clockSource.GetClockEntry(firstHandler).Value))); clockSource.Advance(9, true); clockSource.Advance(8, true); clockSource.Advance(20, true); CollectionAssert.AreEqual(new [] { 10, 20, 30 }, values); }
protected TranslationCPU(string cpuType, Machine machine, Endianess endianness) { if(cpuType == null) { throw new RecoverableException(new ArgumentNullException("cpuType")); } oldMaximumBlockSize = -1; Endianness = endianness; PerformanceInMips = 100; currentCountThreshold = 5000; this.cpuType = cpuType; DisableInterruptsWhileStepping = true; ClockSource = new BaseClockSource(); ClockSource.NumberOfEntriesChanged += (oldValue, newValue) => { if(oldValue > newValue) { Misc.Swap(ref oldValue, ref newValue); } if(oldValue == 0 && newValue != 0) { ClearTranslationCache(); } }; this.translationCacheSize = DefaultTranslationCacheSize; this.machine = machine; started = false; isHalted = false; translationCacheSync = new object(); pagesAccessedByIo = new HashSet<long>(); pauseGuard = new CpuThreadPauseGuard(this); InitializeRegisters(); InitInterruptEvents(); Init(); InitDisas(); }